abstract generic_category() to build on boost-1.42 and older. fix some include issues in tests

This commit is contained in:
Arvid Norberg 2013-09-09 07:06:12 +00:00
parent 42ae69979f
commit a780b8469d
6 changed files with 24 additions and 25 deletions

View File

@ -543,6 +543,9 @@ namespace libtorrent
#endif // BOOST_VERSION < 103600
#endif // BOOST_VERSION < 103500
inline boost::system::error_category const& generic_category()
{ return get_posix_category(); }
#ifndef BOOST_NO_EXCEPTIONS
struct TORRENT_EXPORT libtorrent_exception: std::exception
{

View File

@ -180,7 +180,7 @@ namespace libtorrent
if (_stati64(f.c_str(), &ret) < 0)
#endif
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
#else
@ -192,7 +192,7 @@ namespace libtorrent
retval = ::stat(f.c_str(), &ret);
if (retval < 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
#endif // TORRENT_WINDOWS
@ -231,7 +231,7 @@ namespace libtorrent
if (::rename(f1.c_str(), f2.c_str()) < 0)
#endif
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
}
@ -271,7 +271,7 @@ namespace libtorrent
#else
int ret = mkdir(n.c_str(), 0777);
if (ret < 0 && errno != EEXIST)
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
#endif
}
@ -327,13 +327,13 @@ namespace libtorrent
// this only works on 10.5
copyfile_state_t state = copyfile_state_alloc();
if (copyfile(f1.c_str(), f2.c_str(), state, COPYFILE_ALL) < 0)
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
copyfile_state_free(state);
#else
int infd = ::open(inf.c_str(), O_RDONLY);
if (infd < 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
@ -347,7 +347,7 @@ namespace libtorrent
if (outfd < 0)
{
close(infd);
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
char buffer[4096];
@ -357,13 +357,13 @@ namespace libtorrent
if (num_read == 0) break;
if (num_read < 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
break;
}
int num_written = write(outfd, buffer, num_read);
if (num_written < num_read)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
break;
}
if (num_read < int(sizeof(buffer))) break;
@ -691,7 +691,7 @@ namespace libtorrent
std::string f = convert_to_native(inf);
if (::remove(f.c_str()) < 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
return;
}
#endif // TORRENT_WINDOWS
@ -784,7 +784,7 @@ namespace libtorrent
m_handle = opendir(p.c_str());
if (m_handle == 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
m_done = true;
return;
}
@ -836,7 +836,7 @@ namespace libtorrent
dirent* dummy;
if (readdir_r(m_handle, &m_dirent, &dummy) != 0)
{
ec.assign(errno, boost::system::get_generic_category());
ec.assign(errno, generic_category());
m_done = true;
}
if (dummy == 0) m_done = true;

View File

@ -1134,15 +1134,7 @@ namespace libtorrent
if (has_picker() && j.piece >= 0) picker().write_failed(block_finished);
}
if (j.error ==
#if BOOST_VERSION == 103500
error_code(boost::system::posix_error::not_enough_memory, get_posix_category())
#elif BOOST_VERSION > 103500
error_code(boost::system::errc::not_enough_memory, boost::system::generic_category())
#else
asio::error::no_memory
#endif
)
if (j.error == error_code(boost::system::errc::not_enough_memory, generic_category()))
{
if (alerts().should_post<file_error_alert>())
alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.error));
@ -7630,7 +7622,7 @@ namespace libtorrent
m_announcing = true;
#ifndef TORRENT_DISABLE_DHT
if (m_policy.num_peers() == 0 && m_ses.m_dht)
if (m_policy.num_peers() < 50 && m_ses.m_dht)
{
// we don't have any peers, prioritize
// announcing this torrent with the DHT

View File

@ -137,7 +137,7 @@ void udp_socket::send_hostname(char const* hostname, int port
// if the sockets are closed, the udp_socket is closing too
if (!is_open())
{
ec = error_code(boost::system::errc::bad_file_descriptor, boost::system::generic_category());
ec = error_code(boost::system::errc::bad_file_descriptor, generic_category());
return;
}
@ -180,7 +180,7 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len
// if the sockets are closed, the udp_socket is closing too
if (!is_open())
{
ec = error_code(boost::system::errc::bad_file_descriptor, boost::system::generic_category());
ec = error_code(boost::system::errc::bad_file_descriptor, generic_category());
return;
}

View File

@ -43,6 +43,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM
#include <iostream>
#endif
using namespace libtorrent;
struct dht_server

View File

@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "test.hpp"
#include "setup_transfer.hpp"
#include "libtorrent/create_torrent.hpp"
#include <sys/stat.h> // for chmod
#include <fstream>
static const int file_sizes[] =