reupping asio and some lt fixes

This commit is contained in:
Marcos Pinto 2007-09-12 22:43:51 +00:00
commit b7f0447228
33 changed files with 308 additions and 350 deletions

View file

@ -157,7 +157,8 @@ public:
int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
if (result != 0) 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); read_op_queue_.dispatch_all_operations(descriptor, ec);
} }
} }
@ -190,7 +191,8 @@ public:
int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
if (result != 0) 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); write_op_queue_.dispatch_all_operations(descriptor, ec);
} }
} }
@ -219,7 +221,8 @@ public:
int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
if (result != 0) 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); except_op_queue_.dispatch_all_operations(descriptor, ec);
} }
} }
@ -250,7 +253,8 @@ public:
int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev); int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
if (result != 0) 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); write_op_queue_.dispatch_all_operations(descriptor, ec);
except_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); int result = epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, descriptor, &ev);
if (result != 0) 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); read_op_queue_.dispatch_all_operations(descriptor, ec);
write_op_queue_.dispatch_all_operations(descriptor, ec); write_op_queue_.dispatch_all_operations(descriptor, ec);
except_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); int fd = epoll_create(epoll_size);
if (fd == -1) if (fd == -1)
{ {
boost::throw_exception(asio::system_error( boost::throw_exception(
asio::error_code(errno, asio::native_ecat), asio::system_error(
asio::error_code(errno,
asio::error::system_category),
"epoll")); "epoll"));
} }
return fd; return fd;

View file

@ -150,7 +150,8 @@ public:
EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, 0, 0, 0); EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, 0, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); read_op_queue_.dispatch_all_operations(descriptor, ec);
} }
} }
@ -176,7 +177,8 @@ public:
EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); 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); EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); except_op_queue_.dispatch_all_operations(descriptor, ec);
} }
} }
@ -224,7 +227,8 @@ public:
EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0); EV_SET(&event, descriptor, EVFILT_WRITE, EV_ADD, 0, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); 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); EV_SET(&event, descriptor, EVFILT_READ, EV_ADD, EV_OOBAND, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); except_op_queue_.dispatch_all_operations(descriptor, ec);
write_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) if (events[i].flags & EV_ERROR)
{ {
asio::error_code 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); except_op_queue_.dispatch_all_operations(descriptor, error);
read_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); EV_SET(&event, descriptor, EVFILT_READ, EV_DELETE, 0, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); except_op_queue_.dispatch_all_operations(descriptor, error);
read_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) if (events[i].flags & EV_ERROR)
{ {
asio::error_code 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); write_op_queue_.dispatch_all_operations(descriptor, error);
} }
else else
@ -451,7 +457,8 @@ private:
EV_SET(&event, descriptor, EVFILT_WRITE, EV_DELETE, 0, 0, 0); EV_SET(&event, descriptor, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
if (::kevent(kqueue_fd_, &event, 1, 0, 0, 0) == -1) 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); write_op_queue_.dispatch_all_operations(descriptor, error);
} }
} }
@ -505,8 +512,10 @@ private:
int fd = kqueue(); int fd = kqueue();
if (fd == -1) if (fd == -1)
{ {
boost::throw_exception(asio::system_error( boost::throw_exception(
asio::error_code(errno, asio::native_ecat), asio::system_error(
asio::error_code(errno,
asio::error::system_category),
"kqueue")); "kqueue"));
} }
return fd; return fd;

View file

@ -29,6 +29,7 @@
#include <pthread.h> #include <pthread.h>
#include "asio/detail/pop_options.hpp" #include "asio/detail/pop_options.hpp"
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
@ -47,7 +48,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"event"); "event");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -28,6 +28,7 @@
#include <pthread.h> #include <pthread.h>
#include "asio/detail/pop_options.hpp" #include "asio/detail/pop_options.hpp"
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
#include "asio/detail/scoped_lock.hpp" #include "asio/detail/scoped_lock.hpp"
@ -50,7 +51,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"mutex"); "mutex");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -69,7 +70,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"mutex"); "mutex");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -82,7 +83,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"mutex"); "mutex");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -29,6 +29,7 @@
#include <pthread.h> #include <pthread.h>
#include "asio/detail/pop_options.hpp" #include "asio/detail/pop_options.hpp"
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
@ -52,7 +53,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"thread"); "thread");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -28,6 +28,7 @@
#include <pthread.h> #include <pthread.h>
#include "asio/detail/pop_options.hpp" #include "asio/detail/pop_options.hpp"
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
@ -46,7 +47,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"tss"); "tss");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -157,7 +157,7 @@ public:
if (int err = reactor_.register_descriptor(sock.get())) 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; return ec;
} }
@ -181,7 +181,7 @@ public:
if (int err = reactor_.register_descriptor(native_socket)) 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; return ec;
} }
@ -1124,7 +1124,7 @@ public:
bool operator()(const asio::error_code& result) bool operator()(const asio::error_code& result)
{ {
// Check whether the operation was successful. // Check whether the operation was successful.
if (result != 0) if (result)
{ {
io_service_.post(bind_handler(handler_, result, 0)); io_service_.post(bind_handler(handler_, result, 0));
return true; return true;
@ -1489,7 +1489,7 @@ public:
if (connect_error) if (connect_error)
{ {
ec = asio::error_code(connect_error, ec = asio::error_code(connect_error,
asio::native_ecat); asio::error::system_category);
io_service_.post(bind_handler(handler_, ec)); io_service_.post(bind_handler(handler_, ec));
return true; return true;
} }

View file

@ -52,9 +52,10 @@ inline ReturnType error_wrapper(ReturnType return_value,
asio::error_code& ec) asio::error_code& ec)
{ {
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
ec = asio::error_code(WSAGetLastError(), asio::native_ecat); ec = asio::error_code(WSAGetLastError(),
asio::error::system_category);
#else #else
ec = asio::error_code(errno, asio::native_ecat); ec = asio::error_code(errno, asio::error::system_category);
#endif #endif
return return_value; return return_value;
} }
@ -923,6 +924,13 @@ inline void gai_free(void* p)
::operator delete(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 }; enum { gai_clone_flag = 1 << 30 };
inline int gai_aistruct(addrinfo_type*** next, const addrinfo_type* hints, 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] if (host != 0 && host[0] != '\0' && hptr->h_name && hptr->h_name[0]
&& (hints.ai_flags & AI_CANONNAME) && canon == 0) && (hints.ai_flags & AI_CANONNAME) && canon == 0)
{ {
canon = gai_alloc<char>(strlen(hptr->h_name) + 1); std::size_t canon_len = strlen(hptr->h_name) + 1;
canon = gai_alloc<char>(canon_len);
if (canon == 0) if (canon == 0)
{ {
freeaddrinfo_emulation(aihead); freeaddrinfo_emulation(aihead);
socket_ops::freehostent(hptr); socket_ops::freehostent(hptr);
return EAI_MEMORY; return EAI_MEMORY;
} }
strcpy(canon, hptr->h_name); gai_strcpy(canon, hptr->h_name, canon_len);
} }
// Create an addrinfo structure for each returned address. // Create an addrinfo structure for each returned address.
@ -1335,13 +1344,14 @@ inline int getaddrinfo_emulation(const char* host, const char* service,
} }
else else
{ {
aihead->ai_canonname = gai_alloc<char>(strlen(search[0].host) + 1); std::size_t canonname_len = strlen(search[0].host) + 1;
aihead->ai_canonname = gai_alloc<char>(canonname_len);
if (aihead->ai_canonname == 0) if (aihead->ai_canonname == 0)
{ {
freeaddrinfo_emulation(aihead); freeaddrinfo_emulation(aihead);
return EAI_MEMORY; return EAI_MEMORY;
} }
strcpy(aihead->ai_canonname, search[0].host); gai_strcpy(aihead->ai_canonname, search[0].host, canonname_len);
} }
} }
gai_free(canon); gai_free(canon);
@ -1424,8 +1434,7 @@ inline asio::error_code getnameinfo_emulation(
*dot = 0; *dot = 0;
} }
} }
*host = '\0'; gai_strcpy(host, hptr->h_name, hostlen);
strncat(host, hptr->h_name, hostlen);
socket_ops::freehostent(hptr); socket_ops::freehostent(hptr);
} }
else else
@ -1463,8 +1472,7 @@ inline asio::error_code getnameinfo_emulation(
servent* sptr = ::getservbyport(port, (flags & NI_DGRAM) ? "udp" : 0); servent* sptr = ::getservbyport(port, (flags & NI_DGRAM) ? "udp" : 0);
if (sptr && sptr->s_name && sptr->s_name[0] != '\0') if (sptr && sptr->s_name && sptr->s_name[0] != '\0')
{ {
*serv = '\0'; gai_strcpy(serv, sptr->s_name, servlen);
strncat(serv, sptr->s_name, servlen);
} }
else else
{ {
@ -1518,10 +1526,10 @@ inline asio::error_code translate_addrinfo_error(int error)
default: // Possibly the non-portable EAI_SYSTEM. default: // Possibly the non-portable EAI_SYSTEM.
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
return asio::error_code( return asio::error_code(
WSAGetLastError(), asio::native_ecat); WSAGetLastError(), asio::error::system_category);
#else #else
return asio::error_code( return asio::error_code(
errno, asio::native_ecat); errno, asio::error::system_category);
#endif #endif
} }
} }

View file

@ -23,6 +23,7 @@
#if defined(BOOST_WINDOWS) #if defined(BOOST_WINDOWS)
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp" #include "asio/detail/socket_types.hpp"
@ -47,7 +48,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"event"); "event");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -63,7 +63,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"iocp"); "iocp");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -173,7 +174,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"pqcs"); "pqcs");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -228,7 +230,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"pqcs"); "pqcs");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -247,7 +250,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"pqcs"); "pqcs");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -312,7 +316,7 @@ private:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
ec = asio::error_code(last_error, ec = asio::error_code(last_error,
asio::native_ecat); asio::error::system_category);
return 0; return 0;
} }

View file

@ -337,7 +337,8 @@ public:
if (!cancel_io_ex(sock_as_handle, 0)) if (!cancel_io_ex(sock_as_handle, 0))
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
} }
else else
{ {
@ -358,7 +359,8 @@ public:
if (!::CancelIo(sock_as_handle)) if (!::CancelIo(sock_as_handle))
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
} }
else else
{ {
@ -664,7 +666,8 @@ public:
last_error = WSAECONNRESET; last_error = WSAECONNRESET;
else if (last_error == ERROR_PORT_UNREACHABLE) else if (last_error == ERROR_PORT_UNREACHABLE)
last_error = WSAECONNREFUSED; last_error = WSAECONNREFUSED;
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
return 0; return 0;
} }
@ -715,7 +718,8 @@ public:
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Map non-portable errors to their portable counterparts. // 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 (ec.value() == ERROR_NETNAME_DELETED)
{ {
if (handler_op->cancel_token_.expired()) if (handler_op->cancel_token_.expired())
@ -817,7 +821,8 @@ public:
{ {
asio::io_service::work work(this->io_service()); asio::io_service::work work(this->io_service());
ptr.reset(); 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)); iocp_service_.post(bind_handler(handler, ec, bytes_transferred));
} }
else else
@ -861,7 +866,8 @@ public:
DWORD last_error = ::WSAGetLastError(); DWORD last_error = ::WSAGetLastError();
if (last_error == ERROR_PORT_UNREACHABLE) if (last_error == ERROR_PORT_UNREACHABLE)
last_error = WSAECONNREFUSED; last_error = WSAECONNREFUSED;
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
return 0; return 0;
} }
@ -910,7 +916,8 @@ public:
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Map non-portable errors to their portable counterparts. // 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) if (ec.value() == ERROR_PORT_UNREACHABLE)
{ {
ec = asio::error::connection_refused; ec = asio::error::connection_refused;
@ -993,7 +1000,8 @@ public:
{ {
asio::io_service::work work(this->io_service()); asio::io_service::work work(this->io_service());
ptr.reset(); 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)); iocp_service_.post(bind_handler(handler, ec, bytes_transferred));
} }
else else
@ -1047,7 +1055,8 @@ public:
last_error = WSAECONNRESET; last_error = WSAECONNRESET;
else if (last_error == ERROR_PORT_UNREACHABLE) else if (last_error == ERROR_PORT_UNREACHABLE)
last_error = WSAECONNREFUSED; last_error = WSAECONNREFUSED;
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
return 0; return 0;
} }
if (bytes_transferred == 0) if (bytes_transferred == 0)
@ -1105,7 +1114,8 @@ public:
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Map non-portable errors to their portable counterparts. // 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 (ec.value() == ERROR_NETNAME_DELETED)
{ {
if (handler_op->cancel_token_.expired()) if (handler_op->cancel_token_.expired())
@ -1212,7 +1222,8 @@ public:
{ {
asio::io_service::work work(this->io_service()); asio::io_service::work work(this->io_service());
ptr.reset(); 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)); iocp_service_.post(bind_handler(handler, ec, bytes_transferred));
} }
else else
@ -1258,7 +1269,8 @@ public:
DWORD last_error = ::WSAGetLastError(); DWORD last_error = ::WSAGetLastError();
if (last_error == ERROR_PORT_UNREACHABLE) if (last_error == ERROR_PORT_UNREACHABLE)
last_error = WSAECONNREFUSED; last_error = WSAECONNREFUSED;
ec = asio::error_code(last_error, asio::native_ecat); ec = asio::error_code(last_error,
asio::error::system_category);
return 0; return 0;
} }
if (bytes_transferred == 0) if (bytes_transferred == 0)
@ -1324,7 +1336,8 @@ public:
#endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING) #endif // defined(ASIO_ENABLE_BUFFER_DEBUGGING)
// Map non-portable errors to their portable counterparts. // 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) if (ec.value() == ERROR_PORT_UNREACHABLE)
{ {
ec = asio::error::connection_refused; ec = asio::error::connection_refused;
@ -1418,7 +1431,8 @@ public:
{ {
asio::io_service::work work(this->io_service()); asio::io_service::work work(this->io_service());
ptr.reset(); 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)); iocp_service_.post(bind_handler(handler, ec, bytes_transferred));
} }
else else
@ -1655,7 +1669,8 @@ public:
ptr.reset(); ptr.reset();
// Call the handler. // 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( asio_handler_invoke_helpers::invoke(
detail::bind_handler(handler, ec), &handler); detail::bind_handler(handler, ec), &handler);
} }
@ -1755,7 +1770,8 @@ public:
{ {
asio::io_service::work work(this->io_service()); asio::io_service::work work(this->io_service());
ptr.reset(); 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)); iocp_service_.post(bind_handler(handler, ec));
} }
} }
@ -1831,8 +1847,8 @@ public:
// If connection failed then post the handler with the error code. // If connection failed then post the handler with the error code.
if (connect_error) if (connect_error)
{ {
ec = asio::error_code( ec = asio::error_code(connect_error,
connect_error, asio::native_ecat); asio::error::system_category);
io_service_.post(bind_handler(handler_, ec)); io_service_.post(bind_handler(handler_, ec));
return true; return true;
} }

View file

@ -23,6 +23,7 @@
#if defined(BOOST_WINDOWS) #if defined(BOOST_WINDOWS)
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp" #include "asio/detail/socket_types.hpp"
@ -48,7 +49,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"mutex"); "mutex");
boost::throw_exception(e); boost::throw_exception(e);
} }
@ -67,7 +68,7 @@ public:
if (error != 0) if (error != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(error, asio::native_ecat), asio::error_code(error, asio::error::system_category),
"mutex"); "mutex");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -23,6 +23,7 @@
#if defined(BOOST_WINDOWS) #if defined(BOOST_WINDOWS)
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp" #include "asio/detail/socket_types.hpp"
@ -54,7 +55,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"thread"); "thread");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -23,6 +23,7 @@
#if defined(BOOST_WINDOWS) #if defined(BOOST_WINDOWS)
#include "asio/error.hpp"
#include "asio/system_error.hpp" #include "asio/system_error.hpp"
#include "asio/detail/noncopyable.hpp" #include "asio/detail/noncopyable.hpp"
#include "asio/detail/socket_types.hpp" #include "asio/detail/socket_types.hpp"
@ -47,7 +48,8 @@ public:
{ {
DWORD last_error = ::GetLastError(); DWORD last_error = ::GetLastError();
asio::system_error e( asio::system_error e(
asio::error_code(last_error, asio::native_ecat), asio::error_code(last_error,
asio::error::system_category),
"tss"); "tss");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -85,7 +85,8 @@ public:
if (this != &instance_ && ref_->result() != 0) if (this != &instance_ && ref_->result() != 0)
{ {
asio::system_error e( asio::system_error e(
asio::error_code(ref_->result(), asio::native_ecat), asio::error_code(ref_->result(),
asio::error::system_category),
"winsock"); "winsock");
boost::throw_exception(e); boost::throw_exception(e);
} }

View file

@ -37,327 +37,195 @@
/// INTERNAL ONLY. /// INTERNAL ONLY.
# define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined # define ASIO_WIN_OR_POSIX(e_win, e_posix) implementation_defined
#elif defined(BOOST_WINDOWS) || defined(__CYGWIN__) #elif defined(BOOST_WINDOWS) || defined(__CYGWIN__)
# define ASIO_NATIVE_ERROR(e) \ # define ASIO_NATIVE_ERROR(e) e
asio::error_code(e, \ # define ASIO_SOCKET_ERROR(e) WSA ## e
asio::native_ecat) # define ASIO_NETDB_ERROR(e) WSA ## e
# define ASIO_SOCKET_ERROR(e) \ # define ASIO_GETADDRINFO_ERROR(e) WSA ## 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_WIN_OR_POSIX(e_win, e_posix) e_win # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_win
#else #else
# define ASIO_NATIVE_ERROR(e) \ # define ASIO_NATIVE_ERROR(e) e
asio::error_code(e, \ # define ASIO_SOCKET_ERROR(e) e
asio::native_ecat) # define ASIO_NETDB_ERROR(e) e
# define ASIO_SOCKET_ERROR(e) \ # define ASIO_GETADDRINFO_ERROR(e) 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_WIN_OR_POSIX(e_win, e_posix) e_posix # define ASIO_WIN_OR_POSIX(e_win, e_posix) e_posix
#endif #endif
namespace asio { namespace asio {
namespace error {
namespace detail { enum basic_errors
/// Hack to keep asio library header-file-only.
template <typename T>
class error_base
{ {
public:
// boostify: error category declarations go here.
/// Permission denied. /// Permission denied.
static const asio::error_code access_denied; access_denied = ASIO_SOCKET_ERROR(EACCES),
/// Address family not supported by protocol. /// 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. /// Address already in use.
static const asio::error_code address_in_use; address_in_use = ASIO_SOCKET_ERROR(EADDRINUSE),
/// Transport endpoint is already connected. /// Transport endpoint is already connected.
static const asio::error_code already_connected; already_connected = ASIO_SOCKET_ERROR(EISCONN),
/// Already open.
static const asio::error_code already_open;
/// Operation already in progress. /// Operation already in progress.
static const asio::error_code already_started; already_started = ASIO_SOCKET_ERROR(EALREADY),
/// A connection has been aborted. /// A connection has been aborted.
static const asio::error_code connection_aborted; connection_aborted = ASIO_SOCKET_ERROR(ECONNABORTED),
/// Connection refused. /// Connection refused.
static const asio::error_code connection_refused; connection_refused = ASIO_SOCKET_ERROR(ECONNREFUSED),
/// Connection reset by peer. /// Connection reset by peer.
static const asio::error_code connection_reset; connection_reset = ASIO_SOCKET_ERROR(ECONNRESET),
/// Bad file descriptor. /// Bad file descriptor.
static const asio::error_code bad_descriptor; bad_descriptor = ASIO_SOCKET_ERROR(EBADF),
/// End of file or stream.
static const asio::error_code eof;
/// Bad address. /// Bad address.
static const asio::error_code fault; fault = ASIO_SOCKET_ERROR(EFAULT),
/// 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;
/// No route to host. /// No route to host.
static const asio::error_code host_unreachable; host_unreachable = ASIO_SOCKET_ERROR(EHOSTUNREACH),
/// Operation now in progress. /// Operation now in progress.
static const asio::error_code in_progress; in_progress = ASIO_SOCKET_ERROR(EINPROGRESS),
/// Interrupted system call. /// Interrupted system call.
static const asio::error_code interrupted; interrupted = ASIO_SOCKET_ERROR(EINTR),
/// Invalid argument. /// Invalid argument.
static const asio::error_code invalid_argument; invalid_argument = ASIO_SOCKET_ERROR(EINVAL),
/// Message too long. /// Message too long.
static const asio::error_code message_size; message_size = ASIO_SOCKET_ERROR(EMSGSIZE),
/// Network is down. /// Network is down.
static const asio::error_code network_down; network_down = ASIO_SOCKET_ERROR(ENETDOWN),
/// Network dropped connection on reset. /// Network dropped connection on reset.
static const asio::error_code network_reset; network_reset = ASIO_SOCKET_ERROR(ENETRESET),
/// Network is unreachable. /// Network is unreachable.
static const asio::error_code network_unreachable; network_unreachable = ASIO_SOCKET_ERROR(ENETUNREACH),
/// Too many open files. /// Too many open files.
static const asio::error_code no_descriptors; no_descriptors = ASIO_SOCKET_ERROR(EMFILE),
/// No buffer space available. /// No buffer space available.
static const asio::error_code no_buffer_space; no_buffer_space = ASIO_SOCKET_ERROR(ENOBUFS),
/// The query is valid but does not have associated address data.
static const asio::error_code no_data;
/// Cannot allocate memory. /// 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. /// 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. /// Protocol not available.
static const asio::error_code no_protocol_option; no_protocol_option = ASIO_SOCKET_ERROR(ENOPROTOOPT),
/// A non-recoverable error occurred.
static const asio::error_code no_recovery;
/// Transport endpoint is not connected. /// Transport endpoint is not connected.
static const asio::error_code not_connected; not_connected = ASIO_SOCKET_ERROR(ENOTCONN),
/// Element not found.
static const asio::error_code not_found;
/// Socket operation on non-socket. /// Socket operation on non-socket.
static const asio::error_code not_socket; not_socket = ASIO_SOCKET_ERROR(ENOTSOCK),
/// Operation cancelled. /// 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. /// Operation not supported.
static const asio::error_code operation_not_supported; operation_not_supported = ASIO_SOCKET_ERROR(EOPNOTSUPP),
/// 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;
/// Cannot send after transport endpoint shutdown. /// Cannot send after transport endpoint shutdown.
static const asio::error_code shut_down; shut_down = ASIO_SOCKET_ERROR(ESHUTDOWN),
/// Connection timed out. /// Connection timed out.
static const asio::error_code timed_out; timed_out = ASIO_SOCKET_ERROR(ETIMEDOUT),
/// Resource temporarily unavailable. /// 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. /// 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: enum netdb_errors
error_base(); {
/// 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. // boostify: error category definitions go here.
template <typename T> const asio::error_code inline asio::error_code make_error_code(basic_errors e)
error_base<T>::access_denied = ASIO_SOCKET_ERROR(EACCES);
template <typename T> const asio::error_code
error_base<T>::address_family_not_supported = ASIO_SOCKET_ERROR(
EAFNOSUPPORT);
template <typename T> const asio::error_code
error_base<T>::address_in_use = ASIO_SOCKET_ERROR(EADDRINUSE);
template <typename T> const asio::error_code
error_base<T>::already_connected = ASIO_SOCKET_ERROR(EISCONN);
template <typename T> const asio::error_code
error_base<T>::already_open = ASIO_MISC_ERROR(1);
template <typename T> const asio::error_code
error_base<T>::already_started = ASIO_SOCKET_ERROR(EALREADY);
template <typename T> const asio::error_code
error_base<T>::connection_aborted = ASIO_SOCKET_ERROR(ECONNABORTED);
template <typename T> const asio::error_code
error_base<T>::connection_refused = ASIO_SOCKET_ERROR(ECONNREFUSED);
template <typename T> const asio::error_code
error_base<T>::connection_reset = ASIO_SOCKET_ERROR(ECONNRESET);
template <typename T> const asio::error_code
error_base<T>::bad_descriptor = ASIO_SOCKET_ERROR(EBADF);
template <typename T> const asio::error_code
error_base<T>::eof = ASIO_MISC_ERROR(2);
template <typename T> const asio::error_code
error_base<T>::fault = ASIO_SOCKET_ERROR(EFAULT);
template <typename T> const asio::error_code
error_base<T>::host_not_found = ASIO_NETDB_ERROR(HOST_NOT_FOUND);
template <typename T> const asio::error_code
error_base<T>::host_not_found_try_again = ASIO_NETDB_ERROR(TRY_AGAIN);
template <typename T> const asio::error_code
error_base<T>::host_unreachable = ASIO_SOCKET_ERROR(EHOSTUNREACH);
template <typename T> const asio::error_code
error_base<T>::in_progress = ASIO_SOCKET_ERROR(EINPROGRESS);
template <typename T> const asio::error_code
error_base<T>::interrupted = ASIO_SOCKET_ERROR(EINTR);
template <typename T> const asio::error_code
error_base<T>::invalid_argument = ASIO_SOCKET_ERROR(EINVAL);
template <typename T> const asio::error_code
error_base<T>::message_size = ASIO_SOCKET_ERROR(EMSGSIZE);
template <typename T> const asio::error_code
error_base<T>::network_down = ASIO_SOCKET_ERROR(ENETDOWN);
template <typename T> const asio::error_code
error_base<T>::network_reset = ASIO_SOCKET_ERROR(ENETRESET);
template <typename T> const asio::error_code
error_base<T>::network_unreachable = ASIO_SOCKET_ERROR(ENETUNREACH);
template <typename T> const asio::error_code
error_base<T>::no_descriptors = ASIO_SOCKET_ERROR(EMFILE);
template <typename T> const asio::error_code
error_base<T>::no_buffer_space = ASIO_SOCKET_ERROR(ENOBUFS);
template <typename T> const asio::error_code
error_base<T>::no_data = ASIO_NETDB_ERROR(NO_DATA);
template <typename T> const asio::error_code
error_base<T>::no_memory = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(ERROR_OUTOFMEMORY),
ASIO_NATIVE_ERROR(ENOMEM));
template <typename T> const asio::error_code
error_base<T>::no_permission = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(ERROR_ACCESS_DENIED),
ASIO_NATIVE_ERROR(EPERM));
template <typename T> const asio::error_code
error_base<T>::no_protocol_option = ASIO_SOCKET_ERROR(ENOPROTOOPT);
template <typename T> const asio::error_code
error_base<T>::no_recovery = ASIO_NETDB_ERROR(NO_RECOVERY);
template <typename T> const asio::error_code
error_base<T>::not_connected = ASIO_SOCKET_ERROR(ENOTCONN);
template <typename T> const asio::error_code
error_base<T>::not_found = ASIO_MISC_ERROR(3);
template <typename T> const asio::error_code
error_base<T>::not_socket = ASIO_SOCKET_ERROR(ENOTSOCK);
template <typename T> const asio::error_code
error_base<T>::operation_aborted = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(ERROR_OPERATION_ABORTED),
ASIO_NATIVE_ERROR(ECANCELED));
template <typename T> const asio::error_code
error_base<T>::operation_not_supported = ASIO_SOCKET_ERROR(EOPNOTSUPP);
template <typename T> const asio::error_code
error_base<T>::service_not_found = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(WSATYPE_NOT_FOUND),
ASIO_GETADDRINFO_ERROR(EAI_SERVICE));
template <typename T> const asio::error_code
error_base<T>::socket_type_not_supported = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(WSAESOCKTNOSUPPORT),
ASIO_GETADDRINFO_ERROR(EAI_SOCKTYPE));
template <typename T> const asio::error_code
error_base<T>::shut_down = ASIO_SOCKET_ERROR(ESHUTDOWN);
template <typename T> const asio::error_code
error_base<T>::timed_out = ASIO_SOCKET_ERROR(ETIMEDOUT);
template <typename T> const asio::error_code
error_base<T>::try_again = ASIO_WIN_OR_POSIX(
ASIO_NATIVE_ERROR(ERROR_RETRY),
ASIO_NATIVE_ERROR(EAGAIN));
template <typename T> const asio::error_code
error_base<T>::would_block = ASIO_SOCKET_ERROR(EWOULDBLOCK);
} // namespace detail
/// Contains error constants.
class error : public asio::detail::error_base<error>
{ {
private: return asio::error_code(static_cast<int>(e), system_category);
error(); }
};
inline asio::error_code make_error_code(netdb_errors e)
{
return asio::error_code(static_cast<int>(e), netdb_category);
}
inline asio::error_code make_error_code(addrinfo_errors e)
{
return asio::error_code(static_cast<int>(e), addrinfo_category);
}
inline asio::error_code make_error_code(misc_errors e)
{
return asio::error_code(static_cast<int>(e), misc_category);
}
} // namespace error
} // namespace asio } // namespace asio
#undef ASIO_NATIVE_ERROR #undef ASIO_NATIVE_ERROR
#undef ASIO_SOCKET_ERROR #undef ASIO_SOCKET_ERROR
#undef ASIO_NETDB_ERROR #undef ASIO_NETDB_ERROR
#undef ASIO_GETADDRINFO_ERROR #undef ASIO_GETADDRINFO_ERROR
#undef ASIO_MISC_ERROR
#undef ASIO_WIN_OR_POSIX #undef ASIO_WIN_OR_POSIX
#include "asio/impl/error_code.ipp" #include "asio/impl/error_code.ipp"

View file

@ -32,24 +32,27 @@
namespace asio { namespace asio {
/// Available error code categories. namespace error
enum error_category
{ {
/// Native error codes. /// Available error code categories.
native_ecat = ASIO_WIN_OR_POSIX(0, 0), enum error_category
{
/// System error codes.
system_category = ASIO_WIN_OR_POSIX(0, 0),
/// Error codes from NetDB functions. /// Error codes from NetDB functions.
netdb_ecat = ASIO_WIN_OR_POSIX(native_ecat, 1), netdb_category = ASIO_WIN_OR_POSIX(system_category, 1),
/// Error codes from getaddrinfo. /// Error codes from getaddrinfo.
addrinfo_ecat = ASIO_WIN_OR_POSIX(native_ecat, 2), addrinfo_category = ASIO_WIN_OR_POSIX(system_category, 2),
/// Miscellaneous error codes. /// Miscellaneous error codes.
misc_ecat = ASIO_WIN_OR_POSIX(3, 3), misc_category = ASIO_WIN_OR_POSIX(3, 3),
/// SSL error codes. /// SSL error codes.
ssl_ecat = ASIO_WIN_OR_POSIX(4, 4) ssl_category = ASIO_WIN_OR_POSIX(4, 4)
}; };
} // namespace error
/// Class to represent an error code value. /// Class to represent an error code value.
class error_code class error_code
@ -61,17 +64,24 @@ public:
/// Default constructor. /// Default constructor.
error_code() error_code()
: value_(0), : value_(0),
category_(native_ecat) category_(error::system_category)
{ {
} }
/// Construct with specific error code and 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), : value_(v),
category_(c) category_(c)
{ {
} }
/// Construct from an error code enum.
template <typename ErrorEnum>
error_code(ErrorEnum e)
{
*this = make_error_code(e);
}
/// Get the error value. /// Get the error value.
value_type value() const value_type value() const
{ {
@ -79,7 +89,7 @@ public:
} }
/// Get the error category. /// Get the error category.
error_category category() const error::error_category category() const
{ {
return category_; return category_;
} }
@ -125,7 +135,7 @@ private:
value_type value_; value_type value_;
// The category associated with the error code. // The category associated with the error code.
error_category category_; error::error_category category_;
}; };
} // namespace asio } // namespace asio

View file

@ -35,10 +35,12 @@ inline std::string error_code::message() const
return "Already open."; return "Already open.";
if (*this == error::not_found) if (*this == error::not_found)
return "Not found."; return "Not found.";
if (category_ == ssl_ecat) if (category_ == error::ssl_category)
return "SSL error."; return "SSL error.";
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__) #if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
value_type value = value_; value_type value = value_;
if (category() != error::system_category && *this != error::eof)
return "asio error";
if (*this == error::eof) if (*this == error::eof)
value = ERROR_HANDLE_EOF; value = ERROR_HANDLE_EOF;
char* msg = 0; char* msg = 0;
@ -76,6 +78,8 @@ inline std::string error_code::message() const
return "Service not found."; return "Service not found.";
if (*this == error::socket_type_not_supported) if (*this == error::socket_type_not_supported)
return "Socket type not supported."; return "Socket type not supported.";
if (category() != error::system_category)
return "asio error";
#if defined(__sun) || defined(__QNX__) #if defined(__sun) || defined(__QNX__)
return strerror(value_); return strerror(value_);
#elif defined(__MACH__) && defined(__APPLE__) \ #elif defined(__MACH__) && defined(__APPLE__) \

View file

@ -311,7 +311,8 @@ namespace detail
if (streambuf_.size() == streambuf_.max_size()) if (streambuf_.size() == streambuf_.max_size())
{ {
std::size_t bytes = 0; std::size_t bytes = 0;
handler_(error::not_found, bytes); asio::error_code ec(error::not_found);
handler_(ec, bytes);
return; return;
} }
@ -388,7 +389,8 @@ void async_read_until(AsyncReadStream& s,
// No match. Check if buffer is full. // No match. Check if buffer is full.
if (b.size() == b.max_size()) 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; return;
} }
@ -469,7 +471,8 @@ namespace detail
if (streambuf_.size() == streambuf_.max_size()) if (streambuf_.size() == streambuf_.max_size())
{ {
std::size_t bytes = 0; std::size_t bytes = 0;
handler_(error::not_found, bytes); asio::error_code ec(error::not_found);
handler_(ec, bytes);
return; return;
} }
@ -559,7 +562,8 @@ void async_read_until(AsyncReadStream& s,
// Check if buffer is full. // Check if buffer is full.
if (b.size() == b.max_size()) 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; return;
} }
@ -641,7 +645,8 @@ namespace detail
if (streambuf_.size() == streambuf_.max_size()) if (streambuf_.size() == streambuf_.max_size())
{ {
std::size_t bytes = 0; std::size_t bytes = 0;
handler_(error::not_found, bytes); asio::error_code ec(error::not_found);
handler_(ec, bytes);
return; return;
} }
@ -731,7 +736,8 @@ void async_read_until(AsyncReadStream& s,
// Check if buffer is full. // Check if buffer is full.
if (b.size() == b.max_size()) 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; return;
} }

View file

@ -307,7 +307,7 @@ public:
private: private:
// Helper function to determine whether the endpoint is IPv4. // Helper function to determine whether the endpoint is IPv4.
#if defined(_AIX) #if defined(_AIX)
template <typename T, unsigned short (T::*)> struct is_v4_helper {}; template <typename T, unsigned char (T::*)> struct is_v4_helper {};
template <typename T> template <typename T>
static bool is_v4(const T& ss, is_v4_helper<T, &T::ss_family>* = 0) static bool is_v4(const T& ss, is_v4_helper<T, &T::ss_family>* = 0)

View file

@ -174,12 +174,12 @@ public:
if (error_code == SSL_ERROR_SYSCALL) if (error_code == SSL_ERROR_SYSCALL)
{ {
return handler_(asio::error_code( return handler_(asio::error_code(
sys_error_code, asio::native_ecat), rc); sys_error_code, asio::error::system_category), rc);
} }
else else
{ {
return handler_(asio::error_code( return handler_(asio::error_code(
error_code, asio::ssl_ecat), rc); error_code, asio::error::ssl_category), rc);
} }
} }

View file

@ -155,8 +155,7 @@ namespace libtorrent
int prefer_whole_pieces() const int prefer_whole_pieces() const
{ {
if (m_prefer_whole_pieces == 0) if (on_parole()) return 1;
return peer_info_struct() && peer_info_struct()->on_parole ? 1 : 0;
return m_prefer_whole_pieces; return m_prefer_whole_pieces;
} }

View file

@ -117,6 +117,11 @@ namespace libtorrent
// for yet // for yet
int download_queue_length; 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 // this is the number of requests
// the peer has sent to us // the peer has sent to us
// that we haven't sent yet // that we haven't sent yet

View file

@ -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_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@ AM_LDFLAGS= $(LDFLAGS) -l@BOOST_DATE_TIME_LIB@ -l@BOOST_FILESYSTEM_LIB@ -l@BOOST_THREAD_LIB@ @PTHREAD_LIBS@

View file

@ -255,4 +255,3 @@ namespace libtorrent
} }
} }

View file

@ -385,4 +385,3 @@ void http_connection::rate_limit(int limit)
} }

View file

@ -2019,8 +2019,9 @@ namespace libtorrent
p.load_balancing = total_free_upload(); p.load_balancing = total_free_upload();
p.download_queue_length = (int)download_queue().size(); p.download_queue_length = int(download_queue().size() + m_request_queue.size());
p.upload_queue_length = (int)upload_queue().size(); p.target_dl_queue_length = int(desired_queue_size());
p.upload_queue_length = int(upload_queue().size());
if (boost::optional<piece_block_progress> ret = downloading_piece_progress()) if (boost::optional<piece_block_progress> ret = downloading_piece_progress())
{ {

View file

@ -1125,7 +1125,7 @@ namespace libtorrent
, interesting_blocks, backup_blocks, num_blocks , interesting_blocks, backup_blocks, num_blocks
, prefer_whole_pieces, peer, speed, on_parole); , prefer_whole_pieces, peer, speed, on_parole);
if (num_blocks == 0) return; if (num_blocks <= 0) return;
if (rarest_first) if (rarest_first)
{ {
@ -1364,6 +1364,13 @@ namespace libtorrent
if (prefer_whole_pieces > 0 && !exclusive_active) continue; 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) for (int j = 0; j < num_blocks_in_piece; ++j)
{ {
// ignore completed blocks and already requested blocks // ignore completed blocks and already requested blocks
@ -1412,9 +1419,15 @@ namespace libtorrent
if (num_blocks <= 0) return 0; if (num_blocks <= 0) return 0;
if (on_parole) return num_blocks; 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() interesting_blocks.insert(interesting_blocks.end()
, backup_blocks.begin(), backup_blocks.end()); , backup_blocks.begin(), backup_blocks.begin() + to_copy);
num_blocks -= int(backup_blocks.size()); num_blocks -= to_copy;
backup_blocks.clear(); backup_blocks.clear();
if (num_blocks <= 0) return 0; if (num_blocks <= 0) return 0;

View file

@ -284,6 +284,8 @@ namespace libtorrent
for (std::vector<piece_block>::iterator i = interesting_pieces.begin(); for (std::vector<piece_block>::iterator i = interesting_pieces.begin();
i != interesting_pieces.end(); ++i) i != interesting_pieces.end(); ++i)
{ {
if (prefer_whole_pieces == 0 && num_requests <= 0) break;
if (p.is_requested(*i)) if (p.is_requested(*i))
{ {
if (num_requests <= 0) break; if (num_requests <= 0) break;

View file

@ -2380,4 +2380,3 @@ namespace detail
} }
}} }}

View file

@ -2209,4 +2209,3 @@ namespace libtorrent
#endif #endif
} // namespace libtorrent } // namespace libtorrent

View file

@ -994,4 +994,3 @@ void upnp::close()
} }
} }