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 < 103600
#endif // BOOST_VERSION < 103500 #endif // BOOST_VERSION < 103500
inline boost::system::error_category const& generic_category()
{ return get_posix_category(); }
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
struct TORRENT_EXPORT libtorrent_exception: std::exception struct TORRENT_EXPORT libtorrent_exception: std::exception
{ {

View File

@ -180,7 +180,7 @@ namespace libtorrent
if (_stati64(f.c_str(), &ret) < 0) if (_stati64(f.c_str(), &ret) < 0)
#endif #endif
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
#else #else
@ -192,7 +192,7 @@ namespace libtorrent
retval = ::stat(f.c_str(), &ret); retval = ::stat(f.c_str(), &ret);
if (retval < 0) if (retval < 0)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
#endif // TORRENT_WINDOWS #endif // TORRENT_WINDOWS
@ -231,7 +231,7 @@ namespace libtorrent
if (::rename(f1.c_str(), f2.c_str()) < 0) if (::rename(f1.c_str(), f2.c_str()) < 0)
#endif #endif
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
} }
@ -271,7 +271,7 @@ namespace libtorrent
#else #else
int ret = mkdir(n.c_str(), 0777); int ret = mkdir(n.c_str(), 0777);
if (ret < 0 && errno != EEXIST) if (ret < 0 && errno != EEXIST)
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
#endif #endif
} }
@ -327,13 +327,13 @@ namespace libtorrent
// this only works on 10.5 // this only works on 10.5
copyfile_state_t state = copyfile_state_alloc(); copyfile_state_t state = copyfile_state_alloc();
if (copyfile(f1.c_str(), f2.c_str(), state, COPYFILE_ALL) < 0) 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); copyfile_state_free(state);
#else #else
int infd = ::open(inf.c_str(), O_RDONLY); int infd = ::open(inf.c_str(), O_RDONLY);
if (infd < 0) if (infd < 0)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
@ -347,7 +347,7 @@ namespace libtorrent
if (outfd < 0) if (outfd < 0)
{ {
close(infd); close(infd);
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
char buffer[4096]; char buffer[4096];
@ -357,13 +357,13 @@ namespace libtorrent
if (num_read == 0) break; if (num_read == 0) break;
if (num_read < 0) if (num_read < 0)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
break; break;
} }
int num_written = write(outfd, buffer, num_read); int num_written = write(outfd, buffer, num_read);
if (num_written < num_read) if (num_written < num_read)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
break; break;
} }
if (num_read < int(sizeof(buffer))) break; if (num_read < int(sizeof(buffer))) break;
@ -691,7 +691,7 @@ namespace libtorrent
std::string f = convert_to_native(inf); std::string f = convert_to_native(inf);
if (::remove(f.c_str()) < 0) if (::remove(f.c_str()) < 0)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
return; return;
} }
#endif // TORRENT_WINDOWS #endif // TORRENT_WINDOWS
@ -784,7 +784,7 @@ namespace libtorrent
m_handle = opendir(p.c_str()); m_handle = opendir(p.c_str());
if (m_handle == 0) if (m_handle == 0)
{ {
ec.assign(errno, boost::system::get_generic_category()); ec.assign(errno, generic_category());
m_done = true; m_done = true;
return; return;
} }
@ -836,7 +836,7 @@ namespace libtorrent
dirent* dummy; dirent* dummy;
if (readdir_r(m_handle, &m_dirent, &dummy) != 0) 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; m_done = true;
} }
if (dummy == 0) 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 (has_picker() && j.piece >= 0) picker().write_failed(block_finished);
} }
if (j.error == if (j.error == error_code(boost::system::errc::not_enough_memory, generic_category()))
#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 (alerts().should_post<file_error_alert>()) if (alerts().should_post<file_error_alert>())
alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.error)); alerts().post_alert(file_error_alert(j.error_file, get_handle(), j.error));
@ -7630,7 +7622,7 @@ namespace libtorrent
m_announcing = true; m_announcing = true;
#ifndef TORRENT_DISABLE_DHT #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 // we don't have any peers, prioritize
// announcing this torrent with the DHT // 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 the sockets are closed, the udp_socket is closing too
if (!is_open()) 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; 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 the sockets are closed, the udp_socket is closing too
if (!is_open()) 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; return;
} }

View File

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

View File

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