diff --git a/libtorrent/include/libtorrent/asio/detail/epoll_reactor.hpp b/libtorrent/include/libtorrent/asio/detail/epoll_reactor.hpp index 9c406c3fa..e260c5194 100644 --- a/libtorrent/include/libtorrent/asio/detail/epoll_reactor.hpp +++ b/libtorrent/include/libtorrent/asio/detail/epoll_reactor.hpp @@ -157,7 +157,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -190,7 +191,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -219,7 +221,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -250,7 +253,8 @@ public: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); except_op_queue_.dispatch_all_operations(descriptor, ec); } @@ -427,7 +431,8 @@ private: int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); if (result != 0) { - ec = asio::error_code(errno, asio::native_ecat); + ec = asio::error_code(errno, + asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); write_op_queue_.dispatch_all_operations(descriptor, ec); except_op_queue_.dispatch_all_operations(descriptor, ec); @@ -485,8 +490,10 @@ private: int fd = epoll_create(epoll_size); if (fd == -1) { - boost::throw_exception(asio::system_error( - asio::error_code(errno, asio::native_ecat), + boost::throw_exception( + asio::system_error( + asio::error_code(errno, + asio::error::system_category), "epoll")); } return fd; diff --git a/libtorrent/include/libtorrent/asio/detail/kqueue_reactor.hpp b/libtorrent/include/libtorrent/asio/detail/kqueue_reactor.hpp index 18a842b46..5fffc6788 100644 --- a/libtorrent/include/libtorrent/asio/detail/kqueue_reactor.hpp +++ b/libtorrent/include/libtorrent/asio/detail/kqueue_reactor.hpp @@ -150,7 +150,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); read_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -176,7 +177,8 @@ public: EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -201,7 +203,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -224,7 +227,8 @@ public: EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, ec); } } @@ -238,7 +242,8 @@ public: EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code ec(errno, asio::native_ecat); + asio::error_code ec(errno, + asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, ec); write_op_queue_.dispatch_all_operations(descriptor, ec); } @@ -392,7 +397,7 @@ private: if (events[i].flags & EV_ERROR) { asio::error_code error( - events[i].data, asio::native_ecat); + events[i].data, asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, error); read_op_queue_.dispatch_all_operations(descriptor, error); } @@ -422,7 +427,8 @@ private: EV_SET(&event, descriptor, EVFILT_READ, EV_DELETE, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code error(errno, asio::native_ecat); + asio::error_code error(errno, + asio::error::system_category); except_op_queue_.dispatch_all_operations(descriptor, error); read_op_queue_.dispatch_all_operations(descriptor, error); } @@ -434,7 +440,7 @@ private: if (events[i].flags & EV_ERROR) { asio::error_code error( - events[i].data, asio::native_ecat); + events[i].data, asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, error); } else @@ -451,7 +457,8 @@ private: EV_SET(&event, descriptor, EVFILT_WRITE, EV_DELETE, 0, 0, 0); if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) { - asio::error_code error(errno, asio::native_ecat); + asio::error_code error(errno, + asio::error::system_category); write_op_queue_.dispatch_all_operations(descriptor, error); } } @@ -505,8 +512,10 @@ private: int fd = kqueue(); if (fd == -1) { - boost::throw_exception(asio::system_error( - asio::error_code(errno, asio::native_ecat), + boost::throw_exception( + asio::system_error( + asio::error_code(errno, + asio::error::system_category), "kqueue")); } return fd; diff --git a/libtorrent/include/libtorrent/asio/detail/posix_event.hpp b/libtorrent/include/libtorrent/asio/detail/posix_event.hpp index 1197ac3f1..b48586f15 100644 --- a/libtorrent/include/libtorrent/asio/detail/posix_event.hpp +++ b/libtorrent/include/libtorrent/asio/detail/posix_event.hpp @@ -29,6 +29,7 @@ #include #include "asio/detail/pop_options.hpp" +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" @@ -47,7 +48,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "event"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/posix_mutex.hpp b/libtorrent/include/libtorrent/asio/detail/posix_mutex.hpp index 224722bb4..6067880fb 100644 --- a/libtorrent/include/libtorrent/asio/detail/posix_mutex.hpp +++ b/libtorrent/include/libtorrent/asio/detail/posix_mutex.hpp @@ -28,6 +28,7 @@ #include #include "asio/detail/pop_options.hpp" +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/scoped_lock.hpp" @@ -50,7 +51,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -69,7 +70,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -82,7 +83,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "mutex"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/posix_thread.hpp b/libtorrent/include/libtorrent/asio/detail/posix_thread.hpp index f01b40428..6e5815426 100644 --- a/libtorrent/include/libtorrent/asio/detail/posix_thread.hpp +++ b/libtorrent/include/libtorrent/asio/detail/posix_thread.hpp @@ -29,6 +29,7 @@ #include #include "asio/detail/pop_options.hpp" +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" @@ -52,7 +53,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "thread"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/posix_tss_ptr.hpp b/libtorrent/include/libtorrent/asio/detail/posix_tss_ptr.hpp index 93fce3479..dda329c40 100644 --- a/libtorrent/include/libtorrent/asio/detail/posix_tss_ptr.hpp +++ b/libtorrent/include/libtorrent/asio/detail/posix_tss_ptr.hpp @@ -28,6 +28,7 @@ #include #include "asio/detail/pop_options.hpp" +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" @@ -46,7 +47,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "tss"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/reactive_socket_service.hpp b/libtorrent/include/libtorrent/asio/detail/reactive_socket_service.hpp index e4b4dfa7c..9c0075821 100644 --- a/libtorrent/include/libtorrent/asio/detail/reactive_socket_service.hpp +++ b/libtorrent/include/libtorrent/asio/detail/reactive_socket_service.hpp @@ -157,7 +157,7 @@ public: if (int err = reactor_.register_descriptor(sock.get())) { - ec = asio::error_code(err, asio::native_ecat); + ec = asio::error_code(err, asio::error::system_category); return ec; } @@ -181,7 +181,7 @@ public: if (int err = reactor_.register_descriptor(native_socket)) { - ec = asio::error_code(err, asio::native_ecat); + ec = asio::error_code(err, asio::error::system_category); return ec; } @@ -1124,7 +1124,7 @@ public: bool operator()(const asio::error_code& result) { // Check whether the operation was successful. - if (result != 0) + if (result) { io_service_.post(bind_handler(handler_, result, 0)); return true; @@ -1489,7 +1489,7 @@ public: if (connect_error) { ec = asio::error_code(connect_error, - asio::native_ecat); + asio::error::system_category); io_service_.post(bind_handler(handler_, ec)); return true; } diff --git a/libtorrent/include/libtorrent/asio/detail/socket_ops.hpp b/libtorrent/include/libtorrent/asio/detail/socket_ops.hpp index 7f4e15edf..98f3b0f64 100644 --- a/libtorrent/include/libtorrent/asio/detail/socket_ops.hpp +++ b/libtorrent/include/libtorrent/asio/detail/socket_ops.hpp @@ -52,9 +52,10 @@ inline ReturnType error_wrapper(ReturnType return_value, asio::error_code& ec) { #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) - ec = asio::error_code(WSAGetLastError(), asio::native_ecat); + ec = asio::error_code(WSAGetLastError(), + asio::error::system_category); #else - ec = asio::error_code(errno, asio::native_ecat); + ec = asio::error_code(errno, asio::error::system_category); #endif return return_value; } @@ -923,6 +924,13 @@ inline void gai_free(void* p) ::operator delete(p); } +inline void gai_strcpy(char* target, const char* source, std::size_t max_size) +{ + using namespace std; + *target = 0; + strncat(target, source, max_size); +} + enum { gai_clone_flag = 1 << 30 }; inline int gai_aistruct(addrinfo_type*** next, const addrinfo_type* hints, @@ -1292,14 +1300,15 @@ inline int getaddrinfo_emulation(const char* host, const char* service, if (host != 0 && host[0] != '\0' && hptr->h_name && hptr->h_name[0] && (hints.ai_flags & AI_CANONNAME) && canon == 0) { - canon = gai_alloc(strlen(hptr->h_name) + 1); + std::size_t canon_len = strlen(hptr->h_name) + 1; + canon = gai_alloc(canon_len); if (canon == 0) { freeaddrinfo_emulation(aihead); socket_ops::freehostent(hptr); return EAI_MEMORY; } - strcpy(canon, hptr->h_name); + gai_strcpy(canon, hptr->h_name, canon_len); } // Create an addrinfo structure for each returned address. @@ -1335,13 +1344,14 @@ inline int getaddrinfo_emulation(const char* host, const char* service, } else { - aihead->ai_canonname = gai_alloc(strlen(search[0].host) + 1); + std::size_t canonname_len = strlen(search[0].host) + 1; + aihead->ai_canonname = gai_alloc(canonname_len); if (aihead->ai_canonname == 0) { freeaddrinfo_emulation(aihead); return EAI_MEMORY; } - strcpy(aihead->ai_canonname, search[0].host); + gai_strcpy(aihead->ai_canonname, search[0].host, canonname_len); } } gai_free(canon); @@ -1424,8 +1434,7 @@ inline asio::error_code getnameinfo_emulation( *dot = 0; } } - *host = '\0'; - strncat(host, hptr->h_name, hostlen); + gai_strcpy(host, hptr->h_name, hostlen); socket_ops::freehostent(hptr); } else @@ -1463,8 +1472,7 @@ inline asio::error_code getnameinfo_emulation( servent* sptr = ::getservbyport(port, (flags & NI_DGRAM) ? "udp" : 0); if (sptr && sptr->s_name && sptr->s_name[0] != '\0') { - *serv = '\0'; - strncat(serv, sptr->s_name, servlen); + gai_strcpy(serv, sptr->s_name, servlen); } else { @@ -1518,10 +1526,10 @@ inline asio::error_code translate_addrinfo_error(int error) default: // Possibly the non-portable EAI_SYSTEM. #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) return asio::error_code( - WSAGetLastError(), asio::native_ecat); + WSAGetLastError(), asio::error::system_category); #else return asio::error_code( - errno, asio::native_ecat); + errno, asio::error::system_category); #endif } } diff --git a/libtorrent/include/libtorrent/asio/detail/win_event.hpp b/libtorrent/include/libtorrent/asio/detail/win_event.hpp index 68f55ff13..c73ed56ea 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_event.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_event.hpp @@ -23,6 +23,7 @@ #if defined(BOOST_WINDOWS) +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/socket_types.hpp" @@ -47,7 +48,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "event"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/win_iocp_io_service.hpp b/libtorrent/include/libtorrent/asio/detail/win_iocp_io_service.hpp index 4957fb01a..61eeb1745 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_iocp_io_service.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_iocp_io_service.hpp @@ -63,7 +63,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "iocp"); boost::throw_exception(e); } @@ -173,7 +174,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -228,7 +230,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -247,7 +250,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "pqcs"); boost::throw_exception(e); } @@ -312,7 +316,7 @@ private: { DWORD last_error = ::GetLastError(); ec = asio::error_code(last_error, - asio::native_ecat); + asio::error::system_category); return 0; } diff --git a/libtorrent/include/libtorrent/asio/detail/win_iocp_socket_service.hpp b/libtorrent/include/libtorrent/asio/detail/win_iocp_socket_service.hpp index dcef56576..17d1d5887 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_iocp_socket_service.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_iocp_socket_service.hpp @@ -337,7 +337,8 @@ public: if (!cancel_io_ex(sock_as_handle, 0)) { DWORD last_error = ::GetLastError(); - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); } else { @@ -358,7 +359,8 @@ public: if (!::CancelIo(sock_as_handle)) { DWORD last_error = ::GetLastError(); - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); } else { @@ -664,7 +666,8 @@ public: last_error = WSAECONNRESET; else if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); return 0; } @@ -715,7 +718,8 @@ public: #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); if (ec.value() == ERROR_NETNAME_DELETED) { if (handler_op->cancel_token_.expired()) @@ -817,7 +821,8 @@ public: { asio::io_service::work work(this->io_service()); ptr.reset(); - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -861,7 +866,8 @@ public: DWORD last_error = ::WSAGetLastError(); if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); return 0; } @@ -910,7 +916,8 @@ public: #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); if (ec.value() == ERROR_PORT_UNREACHABLE) { ec = asio::error::connection_refused; @@ -993,7 +1000,8 @@ public: { asio::io_service::work work(this->io_service()); ptr.reset(); - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1047,7 +1055,8 @@ public: last_error = WSAECONNRESET; else if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); return 0; } if (bytes_transferred == 0) @@ -1105,7 +1114,8 @@ public: #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); if (ec.value() == ERROR_NETNAME_DELETED) { if (handler_op->cancel_token_.expired()) @@ -1212,7 +1222,8 @@ public: { asio::io_service::work work(this->io_service()); ptr.reset(); - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1258,7 +1269,8 @@ public: DWORD last_error = ::WSAGetLastError(); if (last_error == ERROR_PORT_UNREACHABLE) last_error = WSAECONNREFUSED; - ec = asio::error_code(last_error, asio::native_ecat); + ec = asio::error_code(last_error, + asio::error::system_category); return 0; } if (bytes_transferred == 0) @@ -1324,7 +1336,8 @@ public: #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) // Map non-portable errors to their portable counterparts. - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); if (ec.value() == ERROR_PORT_UNREACHABLE) { ec = asio::error::connection_refused; @@ -1418,7 +1431,8 @@ public: { asio::io_service::work work(this->io_service()); ptr.reset(); - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); iocp_service_.post(bind_handler(handler, ec, bytes_transferred)); } else @@ -1655,7 +1669,8 @@ public: ptr.reset(); // Call the handler. - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); asio_handler_invoke_helpers::invoke( detail::bind_handler(handler, ec), &handler); } @@ -1755,7 +1770,8 @@ public: { asio::io_service::work work(this->io_service()); ptr.reset(); - asio::error_code ec(last_error, asio::native_ecat); + asio::error_code ec(last_error, + asio::error::system_category); iocp_service_.post(bind_handler(handler, ec)); } } @@ -1831,8 +1847,8 @@ public: // If connection failed then post the handler with the error code. if (connect_error) { - ec = asio::error_code( - connect_error, asio::native_ecat); + ec = asio::error_code(connect_error, + asio::error::system_category); io_service_.post(bind_handler(handler_, ec)); return true; } diff --git a/libtorrent/include/libtorrent/asio/detail/win_mutex.hpp b/libtorrent/include/libtorrent/asio/detail/win_mutex.hpp index 82659831f..4d1bc20c2 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_mutex.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_mutex.hpp @@ -23,6 +23,7 @@ #if defined(BOOST_WINDOWS) +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/socket_types.hpp" @@ -48,7 +49,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "mutex"); boost::throw_exception(e); } @@ -67,7 +68,7 @@ public: if (error != 0) { asio::system_error e( - asio::error_code(error, asio::native_ecat), + asio::error_code(error, asio::error::system_category), "mutex"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/win_thread.hpp b/libtorrent/include/libtorrent/asio/detail/win_thread.hpp index a6c9b15d2..c6bd61af5 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_thread.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_thread.hpp @@ -23,6 +23,7 @@ #if defined(BOOST_WINDOWS) +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/socket_types.hpp" @@ -54,7 +55,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "thread"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/win_tss_ptr.hpp b/libtorrent/include/libtorrent/asio/detail/win_tss_ptr.hpp index d3e2f8161..d84810d41 100644 --- a/libtorrent/include/libtorrent/asio/detail/win_tss_ptr.hpp +++ b/libtorrent/include/libtorrent/asio/detail/win_tss_ptr.hpp @@ -23,6 +23,7 @@ #if defined(BOOST_WINDOWS) +#include "asio/error.hpp" #include "asio/system_error.hpp" #include "asio/detail/noncopyable.hpp" #include "asio/detail/socket_types.hpp" @@ -47,7 +48,8 @@ public: { DWORD last_error = ::GetLastError(); asio::system_error e( - asio::error_code(last_error, asio::native_ecat), + asio::error_code(last_error, + asio::error::system_category), "tss"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/detail/winsock_init.hpp b/libtorrent/include/libtorrent/asio/detail/winsock_init.hpp index 67c69e8ce..874d2b77b 100644 --- a/libtorrent/include/libtorrent/asio/detail/winsock_init.hpp +++ b/libtorrent/include/libtorrent/asio/detail/winsock_init.hpp @@ -85,7 +85,8 @@ public: if (this != &instance_ && ref_->result() != 0) { asio::system_error e( - asio::error_code(ref_->result(), asio::native_ecat), + asio::error_code(ref_->result(), + asio::error::system_category), "winsock"); boost::throw_exception(e); } diff --git a/libtorrent/include/libtorrent/asio/error.hpp b/libtorrent/include/libtorrent/asio/error.hpp index 935cc6796..a8316be2c 100644 --- a/libtorrent/include/libtorrent/asio/error.hpp +++ b/libtorrent/include/libtorrent/asio/error.hpp @@ -37,327 +37,195 @@ /// INTERNAL ONLY. # define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__) -# define ASIO_NATIVE_ERROR(e) \ - asio::error_code(e, \ - asio::native_ecat) -# define ASIO_SOCKET_ERROR(e) \ - asio::error_code(WSA ## e, \ - asio::native_ecat) -# define ASIO_NETDB_ERROR(e) \ - asio::error_code(WSA ## e, \ - asio::native_ecat) -# define ASIO_GETADDRINFO_ERROR(e) \ - asio::error_code(WSA ## e, \ - asio::native_ecat) -# define ASIO_MISC_ERROR(e) \ - asio::error_code(e, \ - asio::misc_ecat) +# define ASIO_NATIVE_ERROR(e) e +# define ASIO_SOCKET_ERROR(e) WSA ## e +# define ASIO_NETDB_ERROR(e) WSA ## e +# define ASIO_GETADDRINFO_ERROR(e) WSA ## e # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_win #else -# define ASIO_NATIVE_ERROR(e) \ - asio::error_code(e, \ - asio::native_ecat) -# define ASIO_SOCKET_ERROR(e) \ - asio::error_code(e, \ - asio::native_ecat) -# define ASIO_NETDB_ERROR(e) \ - asio::error_code(e, \ - asio::netdb_ecat) -# define ASIO_GETADDRINFO_ERROR(e) \ - asio::error_code(e, \ - asio::addrinfo_ecat) -# define ASIO_MISC_ERROR(e) \ - asio::error_code(e, \ - asio::misc_ecat) +# define ASIO_NATIVE_ERROR(e) e +# define ASIO_SOCKET_ERROR(e) e +# define ASIO_NETDB_ERROR(e) e +# define ASIO_GETADDRINFO_ERROR(e) e # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix #endif namespace asio { +namespace error { -namespace detail { - -/// Hack to keep asio library header-file-only. -template -class error_base +enum basic_errors { -public: - // boostify: error category declarations go here. - /// Permission denied. - static const asio::error_code access_denied; + access_denied = ASIO_SOCKET_ERROR(EACCES), /// Address family not supported by protocol. - static const asio::error_code address_family_not_supported; + address_family_not_supported = ASIO_SOCKET_ERROR(EAFNOSUPPORT), /// Address already in use. - static const asio::error_code address_in_use; + address_in_use = ASIO_SOCKET_ERROR(EADDRINUSE), /// Transport endpoint is already connected. - static const asio::error_code already_connected; - - /// Already open. - static const asio::error_code already_open; + already_connected = ASIO_SOCKET_ERROR(EISCONN), /// Operation already in progress. - static const asio::error_code already_started; + already_started = ASIO_SOCKET_ERROR(EALREADY), /// A connection has been aborted. - static const asio::error_code connection_aborted; + connection_aborted = ASIO_SOCKET_ERROR(ECONNABORTED), /// Connection refused. - static const asio::error_code connection_refused; + connection_refused = ASIO_SOCKET_ERROR(ECONNREFUSED), /// Connection reset by peer. - static const asio::error_code connection_reset; + connection_reset = ASIO_SOCKET_ERROR(ECONNRESET), /// Bad file descriptor. - static const asio::error_code bad_descriptor; - - /// End of file or stream. - static const asio::error_code eof; + bad_descriptor = ASIO_SOCKET_ERROR(EBADF), /// Bad address. - static const asio::error_code fault; - - /// Host not found (authoritative). - static const asio::error_code host_not_found; - - /// Host not found (non-authoritative). - static const asio::error_code host_not_found_try_again; + fault = ASIO_SOCKET_ERROR(EFAULT), /// No route to host. - static const asio::error_code host_unreachable; + host_unreachable = ASIO_SOCKET_ERROR(EHOSTUNREACH), /// Operation now in progress. - static const asio::error_code in_progress; + in_progress = ASIO_SOCKET_ERROR(EINPROGRESS), /// Interrupted system call. - static const asio::error_code interrupted; + interrupted = ASIO_SOCKET_ERROR(EINTR), /// Invalid argument. - static const asio::error_code invalid_argument; + invalid_argument = ASIO_SOCKET_ERROR(EINVAL), /// Message too long. - static const asio::error_code message_size; + message_size = ASIO_SOCKET_ERROR(EMSGSIZE), /// Network is down. - static const asio::error_code network_down; + network_down = ASIO_SOCKET_ERROR(ENETDOWN), /// Network dropped connection on reset. - static const asio::error_code network_reset; + network_reset = ASIO_SOCKET_ERROR(ENETRESET), /// Network is unreachable. - static const asio::error_code network_unreachable; + network_unreachable = ASIO_SOCKET_ERROR(ENETUNREACH), /// Too many open files. - static const asio::error_code no_descriptors; + no_descriptors = ASIO_SOCKET_ERROR(EMFILE), /// No buffer space available. - static const asio::error_code no_buffer_space; - - /// The query is valid but does not have associated address data. - static const asio::error_code no_data; + no_buffer_space = ASIO_SOCKET_ERROR(ENOBUFS), /// Cannot allocate memory. - static const asio::error_code no_memory; + no_memory = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY), + ASIO_NATIVE_ERROR(ENOMEM)), /// Operation not permitted. - static const asio::error_code no_permission; + no_permission = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED), + ASIO_NATIVE_ERROR(EPERM)), /// Protocol not available. - static const asio::error_code no_protocol_option; - - /// A non-recoverable error occurred. - static const asio::error_code no_recovery; + no_protocol_option = ASIO_SOCKET_ERROR(ENOPROTOOPT), /// Transport endpoint is not connected. - static const asio::error_code not_connected; - - /// Element not found. - static const asio::error_code not_found; + not_connected = ASIO_SOCKET_ERROR(ENOTCONN), /// Socket operation on non-socket. - static const asio::error_code not_socket; + not_socket = ASIO_SOCKET_ERROR(ENOTSOCK), /// Operation cancelled. - static const asio::error_code operation_aborted; + operation_aborted = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED), + ASIO_NATIVE_ERROR(ECANCELED)), /// Operation not supported. - static const asio::error_code operation_not_supported; - - /// The service is not supported for the given socket type. - static const asio::error_code service_not_found; - - /// The socket type is not supported. - static const asio::error_code socket_type_not_supported; + operation_not_supported = ASIO_SOCKET_ERROR(EOPNOTSUPP), /// Cannot send after transport endpoint shutdown. - static const asio::error_code shut_down; + shut_down = ASIO_SOCKET_ERROR(ESHUTDOWN), /// Connection timed out. - static const asio::error_code timed_out; + timed_out = ASIO_SOCKET_ERROR(ETIMEDOUT), /// Resource temporarily unavailable. - static const asio::error_code try_again; + try_again = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(ERROR_RETRY), + ASIO_NATIVE_ERROR(EAGAIN)), /// The socket is marked non-blocking and the requested operation would block. - static const asio::error_code would_block; + would_block = ASIO_SOCKET_ERROR(EWOULDBLOCK) +}; -private: - error_base(); +enum netdb_errors +{ + /// Host not found (authoritative). + host_not_found = ASIO_NETDB_ERROR(HOST_NOT_FOUND), + + /// Host not found (non-authoritative). + host_not_found_try_again = ASIO_NETDB_ERROR(TRY_AGAIN), + + /// The query is valid but does not have associated address data. + no_data = ASIO_NETDB_ERROR(NO_DATA), + + /// A non-recoverable error occurred. + no_recovery = ASIO_NETDB_ERROR(NO_RECOVERY) +}; + +enum addrinfo_errors +{ + /// The service is not supported for the given socket type. + service_not_found = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND), + ASIO_GETADDRINFO_ERROR(EAI_SERVICE)), + + /// The socket type is not supported. + socket_type_not_supported = ASIO_WIN_OR_POSIX( + ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT), + ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE)) +}; + +enum misc_errors +{ + /// Already open. + already_open = 1, + + /// End of file or stream. + eof, + + /// Element not found. + not_found }; // boostify: error category definitions go here. -template const asio::error_code -error_base::access_denied = ASIO_SOCKET_ERROR(EACCES); - -template const asio::error_code -error_base::address_family_not_supported = ASIO_SOCKET_ERROR( - EAFNOSUPPORT); - -template const asio::error_code -error_base::address_in_use = ASIO_SOCKET_ERROR(EADDRINUSE); - -template const asio::error_code -error_base::already_connected = ASIO_SOCKET_ERROR(EISCONN); - -template const asio::error_code -error_base::already_open = ASIO_MISC_ERROR(1); - -template const asio::error_code -error_base::already_started = ASIO_SOCKET_ERROR(EALREADY); - -template const asio::error_code -error_base::connection_aborted = ASIO_SOCKET_ERROR(ECONNABORTED); - -template const asio::error_code -error_base::connection_refused = ASIO_SOCKET_ERROR(ECONNREFUSED); - -template const asio::error_code -error_base::connection_reset = ASIO_SOCKET_ERROR(ECONNRESET); - -template const asio::error_code -error_base::bad_descriptor = ASIO_SOCKET_ERROR(EBADF); - -template const asio::error_code -error_base::eof = ASIO_MISC_ERROR(2); - -template const asio::error_code -error_base::fault = ASIO_SOCKET_ERROR(EFAULT); - -template const asio::error_code -error_base::host_not_found = ASIO_NETDB_ERROR(HOST_NOT_FOUND); - -template const asio::error_code -error_base::host_not_found_try_again = ASIO_NETDB_ERROR(TRY_AGAIN); - -template const asio::error_code -error_base::host_unreachable = ASIO_SOCKET_ERROR(EHOSTUNREACH); - -template const asio::error_code -error_base::in_progress = ASIO_SOCKET_ERROR(EINPROGRESS); - -template const asio::error_code -error_base::interrupted = ASIO_SOCKET_ERROR(EINTR); - -template const asio::error_code -error_base::invalid_argument = ASIO_SOCKET_ERROR(EINVAL); - -template const asio::error_code -error_base::message_size = ASIO_SOCKET_ERROR(EMSGSIZE); - -template const asio::error_code -error_base::network_down = ASIO_SOCKET_ERROR(ENETDOWN); - -template const asio::error_code -error_base::network_reset = ASIO_SOCKET_ERROR(ENETRESET); - -template const asio::error_code -error_base::network_unreachable = ASIO_SOCKET_ERROR(ENETUNREACH); - -template const asio::error_code -error_base::no_descriptors = ASIO_SOCKET_ERROR(EMFILE); - -template const asio::error_code -error_base::no_buffer_space = ASIO_SOCKET_ERROR(ENOBUFS); - -template const asio::error_code -error_base::no_data = ASIO_NETDB_ERROR(NO_DATA); - -template const asio::error_code -error_base::no_memory = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY), - ASIO_NATIVE_ERROR(ENOMEM)); - -template const asio::error_code -error_base::no_permission = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED), - ASIO_NATIVE_ERROR(EPERM)); - -template const asio::error_code -error_base::no_protocol_option = ASIO_SOCKET_ERROR(ENOPROTOOPT); - -template const asio::error_code -error_base::no_recovery = ASIO_NETDB_ERROR(NO_RECOVERY); - -template const asio::error_code -error_base::not_connected = ASIO_SOCKET_ERROR(ENOTCONN); - -template const asio::error_code -error_base::not_found = ASIO_MISC_ERROR(3); - -template const asio::error_code -error_base::not_socket = ASIO_SOCKET_ERROR(ENOTSOCK); - -template const asio::error_code -error_base::operation_aborted = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED), - ASIO_NATIVE_ERROR(ECANCELED)); - -template const asio::error_code -error_base::operation_not_supported = ASIO_SOCKET_ERROR(EOPNOTSUPP); - -template const asio::error_code -error_base::service_not_found = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND), - ASIO_GETADDRINFO_ERROR(EAI_SERVICE)); - -template const asio::error_code -error_base::socket_type_not_supported = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT), - ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE)); - -template const asio::error_code -error_base::shut_down = ASIO_SOCKET_ERROR(ESHUTDOWN); - -template const asio::error_code -error_base::timed_out = ASIO_SOCKET_ERROR(ETIMEDOUT); - -template const asio::error_code -error_base::try_again = ASIO_WIN_OR_POSIX( - ASIO_NATIVE_ERROR(ERROR_RETRY), - ASIO_NATIVE_ERROR(EAGAIN)); - -template const asio::error_code -error_base::would_block = ASIO_SOCKET_ERROR(EWOULDBLOCK); - -} // namespace detail - -/// Contains error constants. -class error : public asio::detail::error_base +inline asio::error_code make_error_code(basic_errors e) { -private: - error(); -}; + return asio::error_code(static_cast(e), system_category); +} +inline asio::error_code make_error_code(netdb_errors e) +{ + return asio::error_code(static_cast(e), netdb_category); +} + +inline asio::error_code make_error_code(addrinfo_errors e) +{ + return asio::error_code(static_cast(e), addrinfo_category); +} + +inline asio::error_code make_error_code(misc_errors e) +{ + return asio::error_code(static_cast(e), misc_category); +} + +} // namespace error } // namespace asio #undef ASIO_NATIVE_ERROR #undef ASIO_SOCKET_ERROR #undef ASIO_NETDB_ERROR #undef ASIO_GETADDRINFO_ERROR -#undef ASIO_MISC_ERROR #undef ASIO_WIN_OR_POSIX #include "asio/impl/error_code.ipp" diff --git a/libtorrent/include/libtorrent/asio/error_code.hpp b/libtorrent/include/libtorrent/asio/error_code.hpp index 0614490e2..0941a8c00 100644 --- a/libtorrent/include/libtorrent/asio/error_code.hpp +++ b/libtorrent/include/libtorrent/asio/error_code.hpp @@ -32,24 +32,27 @@ namespace asio { -/// Available error code categories. -enum error_category +namespace error { - /// Native error codes. - native_ecat = ASIO_WIN_OR_POSIX(0, 0), + /// Available error code categories. + enum error_category + { + /// System error codes. + system_category = ASIO_WIN_OR_POSIX(0, 0), - /// Error codes from NetDB functions. - netdb_ecat = ASIO_WIN_OR_POSIX(native_ecat, 1), + /// Error codes from NetDB functions. + netdb_category = ASIO_WIN_OR_POSIX(system_category, 1), - /// Error codes from getaddrinfo. - addrinfo_ecat = ASIO_WIN_OR_POSIX(native_ecat, 2), + /// Error codes from getaddrinfo. + addrinfo_category = ASIO_WIN_OR_POSIX(system_category, 2), - /// Miscellaneous error codes. - misc_ecat = ASIO_WIN_OR_POSIX(3, 3), + /// Miscellaneous error codes. + misc_category = ASIO_WIN_OR_POSIX(3, 3), - /// SSL error codes. - ssl_ecat = ASIO_WIN_OR_POSIX(4, 4) -}; + /// SSL error codes. + ssl_category = ASIO_WIN_OR_POSIX(4, 4) + }; +} // namespace error /// Class to represent an error code value. class error_code @@ -61,17 +64,24 @@ public: /// Default constructor. error_code() : value_(0), - category_(native_ecat) + category_(error::system_category) { } /// Construct with specific error code and category. - error_code(value_type v, error_category c) + error_code(value_type v, error::error_category c) : value_(v), category_(c) { } + /// Construct from an error code enum. + template + error_code(ErrorEnum e) + { + *this = make_error_code(e); + } + /// Get the error value. value_type value() const { @@ -79,7 +89,7 @@ public: } /// Get the error category. - error_category category() const + error::error_category category() const { return category_; } @@ -125,7 +135,7 @@ private: value_type value_; // The category associated with the error code. - error_category category_; + error::error_category category_; }; } // namespace asio diff --git a/libtorrent/include/libtorrent/asio/impl/error_code.ipp b/libtorrent/include/libtorrent/asio/impl/error_code.ipp index da2f98833..f66b6fd94 100644 --- a/libtorrent/include/libtorrent/asio/impl/error_code.ipp +++ b/libtorrent/include/libtorrent/asio/impl/error_code.ipp @@ -35,10 +35,12 @@ inline std::string error_code::message() const return "Already open."; if (*this == error::not_found) return "Not found."; - if (category_ == ssl_ecat) + if (category_ == error::ssl_category) return "SSL error."; #if defined(BOOST_WINDOWS) || defined(__CYGWIN__) value_type value = value_; + if (category() != error::system_category && *this != error::eof) + return "asio error"; if (*this == error::eof) value = ERROR_HANDLE_EOF; char* msg = 0; @@ -76,6 +78,8 @@ inline std::string error_code::message() const return "Service not found."; if (*this == error::socket_type_not_supported) return "Socket type not supported."; + if (category() != error::system_category) + return "asio error"; #if defined(__sun) || defined(__QNX__) return strerror(value_); #elif defined(__MACH__) && defined(__APPLE__) \ diff --git a/libtorrent/include/libtorrent/asio/impl/read_until.ipp b/libtorrent/include/libtorrent/asio/impl/read_until.ipp index 64c15ec7d..8b69a11c6 100644 --- a/libtorrent/include/libtorrent/asio/impl/read_until.ipp +++ b/libtorrent/include/libtorrent/asio/impl/read_until.ipp @@ -311,7 +311,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + asio::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -388,7 +389,8 @@ void async_read_until(AsyncReadStream& s, // No match. Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + asio::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } @@ -469,7 +471,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + asio::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -559,7 +562,8 @@ void async_read_until(AsyncReadStream& s, // Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + asio::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } @@ -641,7 +645,8 @@ namespace detail if (streambuf_.size() == streambuf_.max_size()) { std::size_t bytes = 0; - handler_(error::not_found, bytes); + asio::error_code ec(error::not_found); + handler_(ec, bytes); return; } @@ -731,7 +736,8 @@ void async_read_until(AsyncReadStream& s, // Check if buffer is full. if (b.size() == b.max_size()) { - s.io_service().post(detail::bind_handler(handler, error::not_found, 0)); + asio::error_code ec(error::not_found); + s.io_service().post(detail::bind_handler(handler, ec, 0)); return; } diff --git a/libtorrent/include/libtorrent/asio/ip/basic_endpoint.hpp b/libtorrent/include/libtorrent/asio/ip/basic_endpoint.hpp index 499d82631..3d1316e22 100644 --- a/libtorrent/include/libtorrent/asio/ip/basic_endpoint.hpp +++ b/libtorrent/include/libtorrent/asio/ip/basic_endpoint.hpp @@ -307,7 +307,7 @@ public: private: // Helper function to determine whether the endpoint is IPv4. #if defined(_AIX) - template struct is_v4_helper {}; + template struct is_v4_helper {}; template static bool is_v4(const T& ss, is_v4_helper* = 0) diff --git a/libtorrent/include/libtorrent/asio/ssl/detail/openssl_operation.hpp b/libtorrent/include/libtorrent/asio/ssl/detail/openssl_operation.hpp index b7a564464..5fd3ebba4 100755 --- a/libtorrent/include/libtorrent/asio/ssl/detail/openssl_operation.hpp +++ b/libtorrent/include/libtorrent/asio/ssl/detail/openssl_operation.hpp @@ -174,12 +174,12 @@ public: if (error_code == SSL_ERROR_SYSCALL) { return handler_(asio::error_code( - sys_error_code, asio::native_ecat), rc); + sys_error_code, asio::error::system_category), rc); } else { return handler_(asio::error_code( - error_code, asio::ssl_ecat), rc); + error_code, asio::error::ssl_category), rc); } } diff --git a/libtorrent/include/libtorrent/peer_connection.hpp b/libtorrent/include/libtorrent/peer_connection.hpp index 5e65f767a..ea16a8d0a 100755 --- a/libtorrent/include/libtorrent/peer_connection.hpp +++ b/libtorrent/include/libtorrent/peer_connection.hpp @@ -155,8 +155,7 @@ namespace libtorrent int prefer_whole_pieces() const { - if (m_prefer_whole_pieces == 0) - return peer_info_struct() && peer_info_struct()->on_parole ? 1 : 0; + if (on_parole()) return 1; return m_prefer_whole_pieces; } diff --git a/libtorrent/include/libtorrent/peer_info.hpp b/libtorrent/include/libtorrent/peer_info.hpp index 82a4675e7..046df2a6b 100755 --- a/libtorrent/include/libtorrent/peer_info.hpp +++ b/libtorrent/include/libtorrent/peer_info.hpp @@ -117,6 +117,11 @@ namespace libtorrent // for yet int download_queue_length; + // the number of requests that is + // tried to be maintained (this is + // typically a function of download speed) + int target_dl_queue_length; + // this is the number of requests // the peer has sent to us // that we haven't sent yet diff --git a/libtorrent/include/libtorrent/storage.hpp b/libtorrent/include/libtorrent/storage.hpp index 80f12588b..e52196c76 100755 --- a/libtorrent/include/libtorrent/storage.hpp +++ b/libtorrent/include/libtorrent/storage.hpp @@ -201,8 +201,8 @@ namespace libtorrent void async_read( peer_request const& r - , boost::function const& handler - , char* buffer = 0); + , boost::function const& handler + , char* buffer = 0); void async_write( peer_request const& r diff --git a/libtorrent/src/Makefile.am b/libtorrent/src/Makefile.am index ede56a893..671cb75e5 100644 --- a/libtorrent/src/Makefile.am +++ b/libtorrent/src/Makefile.am @@ -97,4 +97,3 @@ libtorrent_la_LIBADD = @ZLIB@ -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ - AM_CXXFLAGS= -ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @ZLIBINCL@ @DEBUGFLAGS@ @PTHREAD_CFLAGS@ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION AM_LDFLAGS= $(LDFLAGS) -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@ - diff --git a/libtorrent/src/disk_io_thread.cpp b/libtorrent/src/disk_io_thread.cpp index 9e7471db5..e07a884cf 100644 --- a/libtorrent/src/disk_io_thread.cpp +++ b/libtorrent/src/disk_io_thread.cpp @@ -255,4 +255,3 @@ namespace libtorrent } } - diff --git a/libtorrent/src/http_connection.cpp b/libtorrent/src/http_connection.cpp index 03e0688de..2b306ca6d 100644 --- a/libtorrent/src/http_connection.cpp +++ b/libtorrent/src/http_connection.cpp @@ -385,4 +385,3 @@ void http_connection::rate_limit(int limit) } - diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index a3d522b89..ad2102f0d 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -2019,8 +2019,9 @@ namespace libtorrent p.load_balancing = total_free_upload(); - p.download_queue_length = (int)download_queue().size(); - p.upload_queue_length = (int)upload_queue().size(); + p.download_queue_length = int(download_queue().size() + m_request_queue.size()); + p.target_dl_queue_length = int(desired_queue_size()); + p.upload_queue_length = int(upload_queue().size()); if (boost::optional ret = downloading_piece_progress()) { diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index 8c8911e7c..8fa623fa3 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -1125,7 +1125,7 @@ namespace libtorrent , interesting_blocks, backup_blocks, num_blocks , prefer_whole_pieces, peer, speed, on_parole); - if (num_blocks == 0) return; + if (num_blocks <= 0) return; if (rarest_first) { @@ -1364,6 +1364,13 @@ namespace libtorrent if (prefer_whole_pieces > 0 && !exclusive_active) continue; + // don't pick too many back-up blocks + if (i->state != none + && i->state != speed + && !exclusive_active + && int(backup_blocks.size()) >= num_blocks) + continue; + for (int j = 0; j < num_blocks_in_piece; ++j) { // ignore completed blocks and already requested blocks @@ -1412,9 +1419,15 @@ namespace libtorrent if (num_blocks <= 0) return 0; if (on_parole) return num_blocks; + int to_copy; + if (prefer_whole_pieces == 0) + to_copy = (std::min)(int(backup_blocks.size()), num_blocks); + else + to_copy = int(backup_blocks.size()); + interesting_blocks.insert(interesting_blocks.end() - , backup_blocks.begin(), backup_blocks.end()); - num_blocks -= int(backup_blocks.size()); + , backup_blocks.begin(), backup_blocks.begin() + to_copy); + num_blocks -= to_copy; backup_blocks.clear(); if (num_blocks <= 0) return 0; diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index 3193ae455..6e81da0d5 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -284,6 +284,8 @@ namespace libtorrent for (std::vector::iterator i = interesting_pieces.begin(); i != interesting_pieces.end(); ++i) { + if (prefer_whole_pieces == 0 && num_requests <= 0) break; + if (p.is_requested(*i)) { if (num_requests <= 0) break; diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index cfbb0e65a..0aeb84bbe 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -2380,4 +2380,3 @@ namespace detail } }} - diff --git a/libtorrent/src/storage.cpp b/libtorrent/src/storage.cpp index 258b91c95..e1ddd20ae 100755 --- a/libtorrent/src/storage.cpp +++ b/libtorrent/src/storage.cpp @@ -2209,4 +2209,3 @@ namespace libtorrent #endif } // namespace libtorrent - diff --git a/libtorrent/src/upnp.cpp b/libtorrent/src/upnp.cpp index 103a71620..043cf4b94 100644 --- a/libtorrent/src/upnp.cpp +++ b/libtorrent/src/upnp.cpp @@ -994,4 +994,3 @@ void upnp::close() } } -