Renamed socket_error to error.

This commit is contained in:
chris 2004-07-02 08:44:01 +00:00
parent 7984317e7d
commit 08b48e11b8
50 changed files with 431 additions and 412 deletions

View File

@ -55,5 +55,6 @@ Add asynchronous functions to the asio::ipv4::basic_host_resolver template.
Error message internationalisation
----------------------------------
Determine what to do with the asio::socket_error messages that are not provided
by the operating system, with respect to internationalisation.
Determine what to do with the asio::error messages that are not provided by the
operating system, with respect to internationalisation. This might be done by
checking the locale of the output stream to which the error will be written.

View File

@ -63,6 +63,7 @@ nobase_include_HEADERS = \
asio/detail/winsock_init.hpp \
asio/dgram_socket.hpp \
asio/dgram_socket_base.hpp \
asio/error.hpp \
asio/error_handler.hpp \
asio/fixed_buffer.hpp \
asio/ipv4/address.hpp \
@ -80,7 +81,6 @@ nobase_include_HEADERS = \
asio/service_factory.hpp \
asio/socket_acceptor.hpp \
asio/socket_connector.hpp \
asio/socket_error.hpp \
asio/socket_option.hpp \
asio/stream_socket.hpp \
asio/stream_socket_base.hpp \

View File

@ -30,6 +30,7 @@
#include "asio/demuxer.hpp"
#include "asio/dgram_socket.hpp"
#include "asio/dgram_socket_base.hpp"
#include "asio/error.hpp"
#include "asio/error_handler.hpp"
#include "asio/fixed_buffer.hpp"
#include "asio/ipv4/address.hpp"
@ -46,7 +47,6 @@
#include "asio/service_factory.hpp"
#include "asio/socket_acceptor.hpp"
#include "asio/socket_connector.hpp"
#include "asio/socket_error.hpp"
#include "asio/socket_option.hpp"
#include "asio/stream_socket.hpp"
#include "asio/stream_socket_base.hpp"

View File

@ -83,7 +83,7 @@ public:
* @param endpoint An endpoint on the local machine to which the dgram socket
* will be bound.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
basic_dgram_socket(demuxer_type& d, const Endpoint& endpoint)
@ -120,7 +120,7 @@ public:
*
* @param protocol An object specifying which protocol is to be used.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Protocol>
void open(const Protocol& protocol)
@ -139,7 +139,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Protocol, typename Error_Handler>
@ -156,7 +156,7 @@ public:
* @param endpoint An endpoint on the local machine to which the dgram socket
* will be bound.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void bind(const Endpoint& endpoint)
@ -176,7 +176,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -215,7 +215,7 @@ public:
*
* @param option The new option value to be set on the socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void set_option(const Option& option)
@ -233,7 +233,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -248,7 +248,7 @@ public:
*
* @param option The option value to be obtained from the socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void get_option(Option& option)
@ -266,7 +266,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -282,7 +282,7 @@ public:
* @param endpoint An endpoint object that receives the local endpoint of the
* socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void get_local_endpoint(Endpoint& endpoint)
@ -301,7 +301,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -317,7 +317,7 @@ public:
*
* @param what Determines what types of operation will no longer be allowed.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void shutdown(shutdown_type what)
{
@ -335,7 +335,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>
@ -358,7 +358,7 @@ public:
*
* @returns The number of bytes sent.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
size_t sendto(const void* data, size_t length, const Endpoint& destination)
@ -383,7 +383,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*
* @returns The number of bytes sent.
@ -413,8 +413,8 @@ public:
* Copies will be made of the handler as required. The equivalent function
* signature of the handler must be:
* @code void handler(
* const asio::socket_error& error, // Result of operation
* size_t bytes_sent // Number of bytes sent
* const asio::error& error, // Result of operation
* size_t bytes_sent // Number of bytes sent
* ); @endcode
*/
template <typename Endpoint, typename Handler>
@ -440,7 +440,7 @@ public:
*
* @returns The number of bytes received.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
size_t recvfrom(void* data, size_t max_length, Endpoint& sender_endpoint)
@ -467,7 +467,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*
* @returns The number of bytes received.
@ -501,8 +501,8 @@ public:
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const asio::socket_error& error, // Result of operation
* size_t bytes_recvd // Number of bytes received
* const asio::error& error, // Result of operation
* size_t bytes_recvd // Number of bytes received
* ); @endcode
*/
template <typename Endpoint, typename Handler>

View File

@ -83,7 +83,7 @@ public:
* @param listen_backlog The maximum length of the queue of pending
* connections. A value of 0 means use the default queue length.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
basic_socket_acceptor(demuxer_type& d, const Endpoint& endpoint,
@ -139,7 +139,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Protocol, typename Error_Handler>
@ -156,7 +156,7 @@ public:
* @param endpoint An endpoint on the local machine to which the socket
* acceptor will be bound.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void bind(const Endpoint& endpoint)
@ -176,7 +176,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -212,7 +212,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>
@ -251,7 +251,7 @@ public:
*
* @param option The new option value to be set on the acceptor.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void set_option(const Option& option)
@ -269,7 +269,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -285,7 +285,7 @@ public:
*
* @param option The option value to be obtained from the acceptor.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void get_option(Option& option)
@ -304,7 +304,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -321,7 +321,7 @@ public:
* @param endpoint An endpoint object that receives the local endpoint of the
* acceptor.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void get_local_endpoint(Endpoint& endpoint)
@ -341,7 +341,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -359,7 +359,7 @@ public:
* @param peer_socket The stream socket into which the new connection will be
* accepted.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Stream>
void accept(Stream& peer_socket)
@ -381,7 +381,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Error_Handler>
@ -403,7 +403,7 @@ public:
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Handler>
@ -425,7 +425,7 @@ public:
* @param peer_endpoint An endpoint object which will receive the endpoint of
* the remote peer.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Stream, typename Endpoint>
void accept_endpoint(Stream& peer_socket, Endpoint& peer_endpoint)
@ -451,7 +451,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Endpoint, typename Error_Handler>
@ -481,7 +481,7 @@ public:
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Endpoint, typename Handler>

View File

@ -114,7 +114,7 @@ public:
* Since the constructor opens the connector by default, you should only need
* to call this function if there has been a prior call to close().
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void open()
{
@ -132,7 +132,7 @@ public:
* @param protocol The protocol to be used for all new connections
* established using the connector.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Protocol>
void open(const Protocol& protocol)
@ -175,7 +175,7 @@ public:
* @param peer_endpoint The remote endpoint to which the socket will be
* connected.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Stream, typename Endpoint>
void connect(Stream& peer_socket, const Endpoint& peer_endpoint)
@ -199,7 +199,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Endpoint, typename Error_Handler>
@ -226,7 +226,7 @@ public:
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Stream, typename Endpoint, typename Handler>

View File

@ -147,7 +147,7 @@ public:
*
* @param option The new option value to be set on the socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void set_option(const Option& option)
@ -165,7 +165,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -180,7 +180,7 @@ public:
*
* @param option The option value to be obtained from the socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Option>
void get_option(Option& option)
@ -198,7 +198,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Option, typename Error_Handler>
@ -214,7 +214,7 @@ public:
* @param endpoint An endpoint object that receives the local endpoint of the
* socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void get_local_endpoint(Endpoint& endpoint)
@ -233,7 +233,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -249,7 +249,7 @@ public:
* @param endpoint An endpoint object that receives the remote endpoint of
* the socket.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
template <typename Endpoint>
void get_remote_endpoint(Endpoint& endpoint)
@ -268,7 +268,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Endpoint, typename Error_Handler>
@ -284,7 +284,7 @@ public:
*
* @param what Determines what types of operation will no longer be allowed.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void shutdown(shutdown_type what)
{
@ -302,7 +302,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>
@ -324,7 +324,7 @@ public:
* @returns The number of bytes sent or 0 if the connection was closed
* cleanly.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*
* @note The send operation may not transmit all of the data to the peer.
* Consider using the asio::send_n() function if you need to ensure that all
@ -349,7 +349,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*
* @returns The number of bytes sent or 0 if the connection was closed
@ -380,8 +380,8 @@ public:
* Copies will be made of the handler as required. The equivalent function
* signature of the handler must be:
* @code void handler(
* const asio::socket_error& error, // Result of operation
* size_t bytes_sent // Number of bytes sent
* const asio::error& error, // Result of operation
* size_t bytes_sent // Number of bytes sent
* ); @endcode
*
* @note The send operation may not transmit all of the data to the peer.
@ -407,7 +407,7 @@ public:
* @returns The number of bytes received or 0 if the connection was closed
* cleanly.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*
* @note The recv operation may not receive all of the requested number of
* bytes. Consider using the asio::recv_n() function if you need to ensure
@ -433,7 +433,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*
* @returns The number of bytes received or 0 if the connection was closed
@ -465,8 +465,8 @@ public:
* completes. Copies will be made of the handler as required. The equivalent
* function signature of the handler must be:
* @code void handler(
* const asio::socket_error& error, // Result of operation
* size_t bytes_recvd // Number of bytes received
* const asio::error& error, // Result of operation
* size_t bytes_recvd // Number of bytes received
* ); @endcode
*
* @note The recv operation may not receive all of the requested number of

View File

@ -18,8 +18,8 @@
#include "asio/detail/push_options.hpp"
#include "asio/dgram_socket_base.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
@ -65,14 +65,14 @@ public:
{
if (protocol.type() != SOCK_DGRAM)
{
error_handler(socket_error(socket_error::invalid_argument));
error_handler(asio::error(asio::error::invalid_argument));
return;
}
socket_holder sock(socket_ops::socket(protocol.family(), protocol.type(),
protocol.protocol()));
if (sock.get() == invalid_socket)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
else
impl = sock.release();
}
@ -84,7 +84,7 @@ public:
{
if (socket_ops::bind(impl, endpoint.native_data(),
endpoint.native_size()) == socket_error_retval)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Destroy a dgram socket implementation.
@ -104,7 +104,7 @@ public:
{
if (socket_ops::setsockopt(impl, option.level(), option.name(),
option.data(), option.size()))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Set a socket option.
@ -114,7 +114,7 @@ public:
socket_len_type size = option.size();
if (socket_ops::getsockopt(impl, option.level(), option.name(),
option.data(), &size))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Get the local endpoint.
@ -124,7 +124,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getsockname(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -148,7 +148,7 @@ public:
break;
}
if (socket_ops::shutdown(impl, shutdown_flag) != 0)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Send a datagram to the specified endpoint. Returns the number of bytes
@ -161,7 +161,7 @@ public:
destination.native_data(), destination.native_size());
if (bytes_sent < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
return bytes_sent;
@ -186,15 +186,15 @@ public:
{
int bytes = socket_ops::sendto(impl_, data_, length_, 0,
destination_.native_data(), destination_.native_size());
socket_error error(bytes < 0
? socket_ops::get_error() : socket_error::success);
asio::error error(bytes < 0
? socket_ops::get_error() : asio::error::success);
demuxer_.post(bind_handler(handler_, error, bytes < 0 ? 0 : bytes));
demuxer_.work_finished();
}
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error, 0));
demuxer_.work_finished();
}
@ -216,7 +216,7 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error, 0));
}
else
@ -238,7 +238,7 @@ public:
sender_endpoint.native_data(), &addr_len);
if (bytes_recvd < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
@ -267,8 +267,8 @@ public:
socket_addr_len_type addr_len = sender_endpoint_.native_size();
int bytes = socket_ops::recvfrom(impl_, data_, max_length_, 0,
sender_endpoint_.native_data(), &addr_len);
socket_error error(bytes < 0
? socket_ops::get_error() : socket_error::success);
asio::error error(bytes < 0
? socket_ops::get_error() : asio::error::success);
sender_endpoint_.native_size(addr_len);
demuxer_.post(bind_handler(handler_, error, bytes < 0 ? 0 : bytes));
demuxer_.work_finished();
@ -276,7 +276,7 @@ public:
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error, 0));
demuxer_.work_finished();
}
@ -299,7 +299,7 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error, 0));
}
else

View File

@ -18,8 +18,8 @@
#include "asio/detail/push_options.hpp"
#include "asio/basic_stream_socket.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
@ -66,7 +66,7 @@ public:
socket_holder sock(socket_ops::socket(protocol.family(), protocol.type(),
protocol.protocol()));
if (sock.get() == invalid_socket)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
else
impl = sock.release();
}
@ -78,7 +78,7 @@ public:
{
if (socket_ops::bind(impl, endpoint.native_data(),
endpoint.native_size()) == socket_error_retval)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Place the socket acceptor into the state where it will listen for new
@ -90,7 +90,7 @@ public:
backlog = SOMAXCONN;
if (socket_ops::listen(impl, backlog) == socket_error_retval)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Close a socket acceptor implementation.
@ -110,7 +110,7 @@ public:
{
if (socket_ops::setsockopt(impl, option.level(), option.name(),
option.data(), option.size()))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Set a socket option.
@ -120,7 +120,7 @@ public:
socket_len_type size = option.size();
if (socket_ops::getsockopt(impl, option.level(), option.name(),
option.data(), &size))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Get the local endpoint.
@ -130,7 +130,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getsockname(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -143,14 +143,14 @@ public:
// We cannot accept a socket that is already open.
if (peer.impl() != invalid_socket)
{
error_handler(socket_error(socket_error::already_connected));
error_handler(asio::error(asio::error::already_connected));
return;
}
socket_type new_socket = socket_ops::accept(impl, 0, 0);
if (int error = socket_ops::get_error())
if (int err = socket_ops::get_error())
{
error_handler(socket_error(error));
error_handler(asio::error(err));
return;
}
@ -167,16 +167,16 @@ public:
// We cannot accept a socket that is already open.
if (peer.impl() != invalid_socket)
{
error_handler(socket_error(socket_error::already_connected));
error_handler(asio::error(asio::error::already_connected));
return;
}
socket_addr_len_type addr_len = peer_endpoint.native_size();
socket_type new_socket = socket_ops::accept(impl,
peer_endpoint.native_data(), &addr_len);
if (int error = socket_ops::get_error())
if (int err = socket_ops::get_error())
{
error_handler(socket_error(error));
error_handler(asio::error(err));
return;
}
@ -201,8 +201,8 @@ public:
void do_operation()
{
socket_type new_socket = socket_ops::accept(impl_, 0, 0);
socket_error error(new_socket == invalid_socket
? socket_ops::get_error() : socket_error::success);
asio::error error(new_socket == invalid_socket
? socket_ops::get_error() : asio::error::success);
peer_.set_impl(new_socket);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
@ -210,7 +210,7 @@ public:
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
}
@ -230,12 +230,12 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error));
}
else if (peer.impl() != invalid_socket)
{
socket_error error(socket_error::already_connected);
asio::error error(asio::error::already_connected);
demuxer_.post(bind_handler(handler, error));
}
else
@ -268,8 +268,8 @@ public:
socket_addr_len_type addr_len = peer_endpoint_.native_size();
socket_type new_socket = socket_ops::accept(impl_,
peer_endpoint_.native_data(), &addr_len);
socket_error error(new_socket == invalid_socket
? socket_ops::get_error() : socket_error::success);
asio::error error(new_socket == invalid_socket
? socket_ops::get_error() : asio::error::success);
peer_endpoint_.native_size(addr_len);
peer_.set_impl(new_socket);
demuxer_.post(bind_handler(handler_, error));
@ -278,7 +278,7 @@ public:
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
}
@ -301,12 +301,12 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error));
}
else if (peer.impl() != invalid_socket)
{
socket_error error(socket_error::already_connected);
asio::error error(asio::error::already_connected);
demuxer_.post(bind_handler(handler, error));
}
else

View File

@ -23,8 +23,8 @@
#include "asio/detail/pop_options.hpp"
#include "asio/basic_stream_socket.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/mutex.hpp"
#include "asio/detail/socket_ops.hpp"
@ -192,7 +192,7 @@ public:
// We cannot connect a socket that is already open.
if (peer.impl() != invalid_socket)
{
error_handler(socket_error(socket_error::already_connected));
error_handler(asio::error(asio::error::already_connected));
return;
}
@ -207,7 +207,7 @@ public:
// We can only connect stream sockets.
if (type != SOCK_STREAM)
{
error_handler(socket_error(socket_error::invalid_argument));
error_handler(asio::error(asio::error::invalid_argument));
return;
}
@ -216,7 +216,7 @@ public:
socket_holder sock(socket_ops::socket(family, type, proto));
if (sock.get() == invalid_socket)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return;
}
@ -227,7 +227,7 @@ public:
impl->remove_socket(sock.get());
if (result == socket_error_retval)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return;
}
@ -262,7 +262,7 @@ public:
if (socket_ops::getsockopt(new_socket_, SOL_SOCKET, SO_ERROR,
&connect_error, &connect_error_len) == socket_error_retval)
{
socket_error error(socket_ops::get_error());
asio::error error(socket_ops::get_error());
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
return;
@ -271,7 +271,7 @@ public:
// If connection failed then post the handler with the error code.
if (connect_error)
{
socket_error error(connect_error);
asio::error error(connect_error);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
return;
@ -281,7 +281,7 @@ public:
ioctl_arg_type non_blocking = 0;
if (socket_ops::ioctl(new_socket_, FIONBIO, &non_blocking))
{
socket_error error(socket_ops::get_error());
asio::error error(socket_ops::get_error());
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
return;
@ -290,7 +290,7 @@ public:
// Post the result of the successful connection operation.
peer_.set_impl(new_socket_);
new_socket_holder.release();
socket_error error(socket_error::success);
asio::error error(asio::error::success);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
}
@ -299,7 +299,7 @@ public:
{
// The socket is closed when the reactor_.close_descriptor is called,
// so no need to close it here.
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error));
demuxer_.work_finished();
}
@ -322,14 +322,14 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error));
return;
}
if (peer.impl() != invalid_socket)
{
socket_error error(socket_error::already_connected);
asio::error error(asio::error::already_connected);
demuxer_.post(bind_handler(handler, error));
return;
}
@ -345,7 +345,7 @@ public:
// We can only connect stream sockets.
if (type != SOCK_STREAM)
{
socket_error error(socket_error::invalid_argument);
asio::error error(asio::error::invalid_argument);
demuxer_.post(bind_handler(handler, error));
return;
}
@ -355,7 +355,7 @@ public:
socket_holder new_socket(socket_ops::socket(family, type, proto));
if (new_socket.get() == invalid_socket)
{
socket_error error(socket_ops::get_error());
asio::error error(socket_ops::get_error());
demuxer_.post(bind_handler(handler, error));
return;
}
@ -365,7 +365,7 @@ public:
ioctl_arg_type non_blocking = 1;
if (socket_ops::ioctl(new_socket.get(), FIONBIO, &non_blocking))
{
socket_error error(socket_ops::get_error());
asio::error error(socket_ops::get_error());
demuxer_.post(bind_handler(handler, error));
return;
}
@ -377,11 +377,11 @@ public:
// The connect operation has finished successfully so we need to post the
// handler immediately.
peer.set_impl(new_socket.release());
socket_error error(socket_error::success);
asio::error error(asio::error::success);
demuxer_.post(bind_handler(handler, error));
}
else if (socket_ops::get_error() == socket_error::in_progress
|| socket_ops::get_error() == socket_error::would_block)
else if (socket_ops::get_error() == asio::error::in_progress
|| socket_ops::get_error() == asio::error::would_block)
{
// The connection is happening in the background, and we need to wait
// until the socket becomes writeable.
@ -395,7 +395,7 @@ public:
else
{
// The connect operation has failed, so post the handler immediately.
socket_error error(socket_ops::get_error());
asio::error error(socket_ops::get_error());
demuxer_.post(bind_handler(handler, error));
}
}

View File

@ -17,8 +17,8 @@
#include "asio/detail/push_options.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/stream_socket_base.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/socket_ops.hpp"
@ -80,7 +80,7 @@ public:
{
if (socket_ops::setsockopt(impl, option.level(), option.name(),
option.data(), option.size()))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Set a socket option.
@ -90,7 +90,7 @@ public:
socket_len_type size = option.size();
if (socket_ops::getsockopt(impl, option.level(), option.name(),
option.data(), &size))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Get the local endpoint.
@ -100,7 +100,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getsockname(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -111,7 +111,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getpeername(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -135,7 +135,7 @@ public:
break;
}
if (socket_ops::shutdown(impl, shutdown_flag) != 0)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Send the given data to the peer. Returns the number of bytes sent or
@ -147,7 +147,7 @@ public:
int bytes_sent = socket_ops::send(impl, data, length, 0);
if (bytes_sent < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
return bytes_sent;
@ -170,15 +170,15 @@ public:
void do_operation()
{
int bytes = socket_ops::send(impl_, data_, length_, 0);
socket_error error(bytes < 0
? socket_ops::get_error() : socket_error::success);
asio::error error(bytes < 0
? socket_ops::get_error() : asio::error::success);
demuxer_.post(bind_handler(handler_, error, bytes < 0 ? 0 : bytes));
demuxer_.work_finished();
}
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error, 0));
demuxer_.work_finished();
}
@ -199,7 +199,7 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error, 0));
}
else
@ -219,7 +219,7 @@ public:
int bytes_recvd = socket_ops::recv(impl, data, max_length, 0);
if (bytes_recvd < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
return bytes_recvd;
@ -242,15 +242,15 @@ public:
void do_operation()
{
int bytes = socket_ops::recv(impl_, data_, max_length_, 0);
socket_error error(bytes < 0
? socket_ops::get_error() : socket_error::success);
asio::error error(bytes < 0
? socket_ops::get_error() : asio::error::success);
demuxer_.post(bind_handler(handler_, error, bytes < 0 ? 0 : bytes));
demuxer_.work_finished();
}
void do_cancel()
{
socket_error error(socket_error::operation_aborted);
asio::error error(asio::error::operation_aborted);
demuxer_.post(bind_handler(handler_, error, 0));
demuxer_.work_finished();
}
@ -271,7 +271,7 @@ public:
{
if (impl == null())
{
socket_error error(socket_error::bad_descriptor);
asio::error error(asio::error::bad_descriptor);
demuxer_.post(bind_handler(handler, error, 0));
}
else

View File

@ -25,6 +25,7 @@
#endif
#include "asio/detail/pop_options.hpp"
#include "asio/error.hpp"
#include "asio/detail/socket_types.hpp"
namespace asio {
@ -226,7 +227,7 @@ inline const char* inet_ntop(int af, const void* src, char* dest,
if (af != AF_INET)
{
set_error(socket_error::address_family_not_supported);
set_error(asio::error::address_family_not_supported);
return 0;
}
@ -241,14 +242,14 @@ inline const char* inet_ntop(int af, const void* src, char* dest,
// Windows may not set an error code on failure.
if (get_error() == 0)
set_error(socket_error::invalid_argument);
set_error(asio::error::invalid_argument);
return 0;
#else // defined(_WIN32)
const char* result = error_wrapper(::inet_ntop(af, src, dest, length));
if (result == 0 && get_error() == 0)
set_error(socket_error::invalid_argument);
set_error(asio::error::invalid_argument);
return result;
#endif // defined(_WIN32)
}
@ -261,7 +262,7 @@ inline int inet_pton(int af, const char* src, void* dest)
if (af != AF_INET)
{
set_error(socket_error::address_family_not_supported);
set_error(asio::error::address_family_not_supported);
return -1;
}
@ -274,13 +275,13 @@ inline int inet_pton(int af, const char* src, void* dest)
// Windows may not set an error code on failure.
if (get_error() == 0)
set_error(socket_error::invalid_argument);
set_error(asio::error::invalid_argument);
return 0;
#else // defined(_WIN32)
int result = error_wrapper(::inet_pton(af, src, dest));
if (result <= 0 && get_error() == 0)
set_error(socket_error::invalid_argument);
set_error(asio::error::invalid_argument);
return result;
#endif // defined(_WIN32)
}
@ -296,15 +297,15 @@ inline int translate_netdb_error(int error)
switch (error)
{
case 0:
return socket_error::success;
return asio::error::success;
case HOST_NOT_FOUND:
return socket_error::host_not_found;
return asio::error::host_not_found;
case TRY_AGAIN:
return socket_error::host_not_found_try_again;
return asio::error::host_not_found_try_again;
case NO_RECOVERY:
return socket_error::no_recovery;
return asio::error::no_recovery;
case NO_DATA:
return socket_error::no_host_data;
return asio::error::no_host_data;
default:
return get_error();
}

View File

@ -17,7 +17,7 @@
#include "asio/detail/push_options.hpp"
#include "asio/socket_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
@ -34,7 +34,7 @@ public:
socket_holder acceptor(socket_ops::socket(AF_INET, SOCK_STREAM,
IPPROTO_TCP));
if (acceptor.get() == invalid_socket)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
int opt = 1;
socket_ops::setsockopt(acceptor.get(), SOL_SOCKET, SO_REUSEADDR, &opt,
@ -47,30 +47,30 @@ public:
addr.sin_port = 0;
if (socket_ops::bind(acceptor.get(), (const socket_addr_type*)&addr,
addr_len) == socket_error_retval)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
if (getsockname(acceptor.get(), (socket_addr_type*)&addr, &addr_len)
== socket_error_retval)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
if (socket_ops::listen(acceptor.get(), SOMAXCONN) == socket_error_retval)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
socket_holder client(socket_ops::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP));
if (client.get() == invalid_socket)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
if (socket_ops::connect(client.get(), (const socket_addr_type*)&addr,
addr_len) == socket_error_retval)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
socket_holder server(socket_ops::accept(acceptor.get(), 0, 0));
if (server.get() == invalid_socket)
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
ioctl_arg_type non_blocking = 1;
if (socket_ops::ioctl(client.get(), FIONBIO, &non_blocking))
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
opt = 1;
socket_ops::setsockopt(client.get(), IPPROTO_TCP, TCP_NODELAY, &opt,
@ -78,7 +78,7 @@ public:
non_blocking = 1;
if (socket_ops::ioctl(server.get(), FIONBIO, &non_blocking))
throw socket_error(socket_ops::get_error());
throw asio::error(socket_ops::get_error());
opt = 1;
socket_ops::setsockopt(server.get(), IPPROTO_TCP, TCP_NODELAY, &opt,

View File

@ -21,8 +21,8 @@
#include "asio/basic_demuxer.hpp"
#include "asio/dgram_socket_base.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/socket_holder.hpp"
#include "asio/detail/socket_ops.hpp"
@ -72,7 +72,7 @@ public:
{
if (protocol.type() != SOCK_DGRAM)
{
error_handler(socket_error(socket_error::invalid_argument));
error_handler(asio::error(asio::error::invalid_argument));
return;
}
@ -80,7 +80,7 @@ public:
protocol.protocol()));
if (sock.get() == invalid_socket)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return;
}
@ -96,7 +96,7 @@ public:
{
if (socket_ops::bind(impl, endpoint.native_data(),
endpoint.native_size()) == socket_error_retval)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Destroy a dgram socket implementation.
@ -116,7 +116,7 @@ public:
{
if (socket_ops::setsockopt(impl, option.level(), option.name(),
option.data(), option.size()))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Set a socket option.
@ -126,7 +126,7 @@ public:
socket_len_type size = option.size();
if (socket_ops::getsockopt(impl, option.level(), option.name(),
option.data(), &size))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Get the local endpoint.
@ -137,7 +137,7 @@ public:
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getsockname(impl, endpoint.native_data(), &addr_len))
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return;
}
@ -164,7 +164,7 @@ public:
break;
}
if (socket_ops::shutdown(impl, shutdown_flag) != 0)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Send a datagram to the specified endpoint. Returns the number of bytes
@ -177,7 +177,7 @@ public:
destination.native_data(), destination.native_size());
if (bytes_sent < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
@ -202,7 +202,7 @@ public:
{
sendto_operation<Handler>* h =
static_cast<sendto_operation<Handler>*>(op);
socket_error error(last_error);
asio::error error(last_error);
try
{
h->handler_(error, bytes_transferred);
@ -240,7 +240,7 @@ public:
if (result != 0 && last_error != WSA_IO_PENDING)
{
delete sendto_op;
socket_error error(last_error);
asio::error error(last_error);
demuxer_service_.post(bind_handler(handler, error, bytes_transferred));
demuxer_service_.work_finished();
}
@ -257,7 +257,7 @@ public:
sender_endpoint.native_data(), &addr_len);
if (bytes_recvd < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
@ -293,7 +293,7 @@ public:
recvfrom_operation<Endpoint, Handler>* h =
static_cast<recvfrom_operation<Endpoint, Handler>*>(op);
h->endpoint_.native_size(h->endpoint_size_);
socket_error error(last_error);
asio::error error(last_error);
try
{
h->handler_(error, bytes_transferred);
@ -336,7 +336,7 @@ public:
if (result != 0 && last_error != WSA_IO_PENDING)
{
delete recvfrom_op;
socket_error error(last_error);
asio::error error(last_error);
demuxer_service_.post(bind_handler(handler, error, bytes_transferred));
demuxer_service_.work_finished();
}

View File

@ -20,8 +20,8 @@
#if defined(_WIN32) // This service is only supported on Win32
#include "asio/basic_demuxer.hpp"
#include "asio/error.hpp"
#include "asio/service_factory.hpp"
#include "asio/socket_error.hpp"
#include "asio/stream_socket_base.hpp"
#include "asio/detail/bind_handler.hpp"
#include "asio/detail/socket_ops.hpp"
@ -88,7 +88,7 @@ public:
{
if (socket_ops::setsockopt(impl, option.level(), option.name(),
option.data(), option.size()))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Set a socket option.
@ -98,7 +98,7 @@ public:
socket_len_type size = option.size();
if (socket_ops::getsockopt(impl, option.level(), option.name(),
option.data(), &size))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Get the local endpoint.
@ -108,7 +108,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getsockname(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -119,7 +119,7 @@ public:
{
socket_addr_len_type addr_len = endpoint.native_size();
if (socket_ops::getpeername(impl, endpoint.native_data(), &addr_len))
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
endpoint.native_size(addr_len);
}
@ -143,7 +143,7 @@ public:
break;
}
if (socket_ops::shutdown(impl, shutdown_flag) != 0)
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
}
// Send the given data to the peer. Returns the number of bytes sent or
@ -155,7 +155,7 @@ public:
int bytes_sent = socket_ops::send(impl, data, length, 0);
if (bytes_sent < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
return bytes_sent;
@ -178,7 +178,7 @@ public:
DWORD last_error, size_t bytes_transferred)
{
send_operation<Handler>* h = static_cast<send_operation<Handler>*>(op);
socket_error error(last_error);
asio::error error(last_error);
try
{
h->handler_(error, bytes_transferred);
@ -214,7 +214,7 @@ public:
if (result != 0 && last_error != WSA_IO_PENDING)
{
delete send_op;
socket_error error(last_error);
asio::error error(last_error);
demuxer_service_.post(bind_handler(handler, error, bytes_transferred));
demuxer_service_.work_finished();
}
@ -229,7 +229,7 @@ public:
int bytes_recvd = socket_ops::recv(impl, data, max_length, 0);
if (bytes_recvd < 0)
{
error_handler(socket_error(socket_ops::get_error()));
error_handler(asio::error(socket_ops::get_error()));
return 0;
}
return bytes_recvd;
@ -252,7 +252,7 @@ public:
DWORD last_error, size_t bytes_transferred)
{
recv_operation<Handler>* h = static_cast<recv_operation<Handler>*>(op);
socket_error error(last_error);
asio::error error(last_error);
try
{
h->handler_(error, bytes_transferred);
@ -290,7 +290,7 @@ public:
if (result != 0 && last_error != WSA_IO_PENDING)
{
delete recv_op;
socket_error error(last_error);
asio::error error(last_error);
demuxer_service_.post(bind_handler(handler, error, bytes_transferred));
demuxer_service_.work_finished();
}

View File

@ -1,6 +1,6 @@
//
// socket_error.hpp
// ~~~~~~~~~~~~~~~~
// error.hpp
// ~~~~~~~~~
//
// Copyright (c) 2003, 2004 Christopher M. Kohlhoff (chris@kohlhoff.com)
//
@ -12,16 +12,14 @@
// no claim as to its suitability for any purpose.
//
#ifndef ASIO_SOCKET_ERROR_HPP
#define ASIO_SOCKET_ERROR_HPP
#ifndef ASIO_ERROR_HPP
#define ASIO_ERROR_HPP
#include "asio/detail/push_options.hpp"
#include "asio/detail/push_options.hpp"
#include <cerrno>
#include <exception>
#include <string>
#include <iostream>
#include "asio/detail/pop_options.hpp"
#include "asio/detail/socket_types.hpp"
@ -36,8 +34,8 @@ namespace asio {
# define ASIO_NETDB_ERROR(e) 16384 + e
#endif
/// The socket_error class is used to encapsulate socket error codes.
class socket_error
/// The error class is used to encapsulate system error codes.
class error
: public std::exception
{
public:
@ -156,26 +154,26 @@ public:
};
/// Default constructor.
socket_error()
error()
: code_(success)
{
}
/// Construct with a specific error code.
socket_error(int code)
error(int code)
: code_(code)
{
}
// Destructor.
virtual ~socket_error() throw ()
virtual ~error() throw ()
{
}
// Get the string for the type of exception.
virtual const char* what() const throw ()
{
return "Socket error";
return "asio error";
}
/// Get the code associated with the error.
@ -184,54 +182,6 @@ public:
return code_;
}
/// Get the message associated with the error.
std::string message() const
{
#if defined(_WIN32)
if (code_ == ENOMEM || code_ == EPERM || code_ == EAGAIN)
{
return std::string(strerror(code_));
}
else
{
void* msg_buf = 0;
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, code_,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&msg_buf, 0, 0);
std::string msg((LPCTSTR)msg_buf);
::LocalFree(msg_buf);
if (msg.size() && msg[msg.size() - 1] == '\n')
msg.resize(msg.size() - 1);
if (msg.size() && msg[msg.size() - 1] == '\r')
msg.resize(msg.size() - 1);
return msg;
}
#else // _WIN32
switch (code_)
{
case host_not_found:
return "Host not found (authoritative).";
case host_not_found_try_again:
return "Host not found (non-authoritative), try again later.";
case no_recovery:
return "A non-recoverable error occurred during database lookup.";
case no_host_data:
return "The name is valid, but it does not have associated data.";
default:
break;
}
#if defined(__sun)
return std::string(strerror(code_));
#else // __sun
if (code_ == operation_aborted)
return "Operation cancelled.";
char buf[256] = "";
return std::string(strerror_r(code_, buf, sizeof(buf)));
#endif // __sun
#endif // _WIN32
}
struct unspecified_bool_type_t;
typedef unspecified_bool_type_t* unspecified_bool_type;
@ -251,33 +201,98 @@ public:
}
/// Equality operator to compare two error objects.
friend bool operator==(const socket_error& e1, const socket_error& e2)
friend bool operator==(const error& e1, const error& e2)
{
return e1.code_ == e2.code_;
}
/// Inequality operator to compare two error objects.
friend bool operator!=(const socket_error& e1, const socket_error& e2)
friend bool operator!=(const error& e1, const error& e2)
{
return e1.code_ != e2.code_;
}
/// Write an error message to an output stream.
friend std::ostream& operator<<(std::ostream& os, const socket_error& e)
{
os << e.what() << ": " << e.message();
return os;
}
private:
// The code associated with the error.
int code_;
};
/// Output the string associated with an error.
/**
* Used to output a human-readable string that is associated with an error.
*
* @param os The output stream to which the string will be written.
*
* @param e The error to be written.
*
* @return The output stream.
*
* @relates asio::error
*/
template <typename Ostream>
Ostream& operator<<(Ostream& os, const error& e)
{
#if defined(_WIN32)
if (e.code() == ENOMEM || e.code() == EPERM || e.code() == EAGAIN)
{
os << strerror(e.code());
}
else
{
LPTSTR msg = 0;
DWORD length = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS, 0, e.code(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&msg, 0, 0);
if (length && msg[length - 1] == '\n')
msg[--length] = '\0';
if (length && msg[length - 1] == '\r')
msg[--length] = '\0';
if (length)
os << msg;
else
os << e.what() << ' ' << e.code();
::LocalFree(msg);
}
#else // _WIN32
switch (e.code())
{
case error::host_not_found:
os << "Host not found (authoritative).";
break;
case error::host_not_found_try_again:
os << "Host not found (non-authoritative), try again later.";
break;
case error::no_recovery:
os << "A non-recoverable error occurred during database lookup.";
break;
case error::no_host_data:
os << "The name is valid, but it does not have associated data.";
break;
#if !defined(__sun)
case error::operation_aborted:
os << "Operation aborted.";
break;
#endif // !__sun
default:
#if defined(__sun)
os << strerror(e.code());
#else // __sun
{
char buf[256] = "";
os << strerror_r(e.code(), buf, sizeof(buf));
}
#endif // __sun
break;
}
#endif // _WIN32
return os;
}
} // namespace asio
#undef ASIO_SOCKET_ERROR
#include "asio/detail/pop_options.hpp"
#endif // ASIO_SOCKET_ERROR_HPP
#endif // ASIO_ERROR_HPP

View File

@ -20,12 +20,12 @@
namespace asio {
/// This class is used to indicate a placeholder for the actual error value.
class error_t {};
class error_placeholder_t {};
namespace {
/// This variable is used as a placeholder for the error value.
error_t error;
error_placeholder_t the_error;
} // namespace
@ -86,14 +86,14 @@ private:
/// Compare the error for equality with a given value.
template <typename Value> inline
expression<value_eq_error<Value> > operator==(Value value, error_t)
expression<value_eq_error<Value> > operator==(Value value, error_placeholder_t)
{
return make_expression(value_eq_error<Value>(value));
}
/// Compare the error for equality with a given value.
template <typename Value> inline
expression<value_eq_error<Value> > operator==(error_t, Value value)
expression<value_eq_error<Value> > operator==(error_placeholder_t, Value value)
{
return make_expression(value_eq_error<Value>(value));
}
@ -123,14 +123,16 @@ private:
/// Compare the error for inequality with a given value.
template <typename Value> inline
expression<value_neq_error<Value> > operator!=(Value value, error_t)
expression<value_neq_error<Value> > operator!=(Value value,
error_placeholder_t)
{
return make_expression(value_neq_error<Value>(value));
}
/// Compare the error for inequality with a given value.
template <typename Value> inline
expression<value_neq_error<Value> > operator!=(error_t, Value value)
expression<value_neq_error<Value> > operator!=(error_placeholder_t,
Value value)
{
return make_expression(value_neq_error<Value>(value));
}

View File

@ -21,7 +21,7 @@
#include <string>
#include "asio/detail/pop_options.hpp"
#include "asio/socket_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/socket_types.hpp"
namespace asio {
@ -55,7 +55,7 @@ public:
address(const std::string& host)
{
if (asio::detail::socket_ops::inet_pton(AF_INET, host.c_str(), &addr_) <= 0)
throw socket_error(asio::detail::socket_ops::get_error());
throw asio::error(asio::detail::socket_ops::get_error());
}
/// Copy constructor.
@ -99,7 +99,7 @@ public:
const char* addr = asio::detail::socket_ops::inet_ntop(AF_INET, &addr_,
addr_str, asio::detail::max_addr_str_len);
if (addr == 0)
throw socket_error(asio::detail::socket_ops::get_error());
throw asio::error(asio::detail::socket_ops::get_error());
return addr;
}

View File

@ -82,7 +82,7 @@ public:
*
* @param h A host object that receives information about the local machine.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void get_local_host(host& h)
{
@ -101,7 +101,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>
@ -121,7 +121,7 @@ public:
* specified address. After successful completion of this function, the host
* object is guaranteed to contain at least one address.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void get_host_by_address(const address& addr, host& h)
{
@ -143,7 +143,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>
@ -163,7 +163,7 @@ public:
* @param h A host object that receives information assocated with the
* specified host name.
*
* @throws socket_error Thrown on failure.
* @throws asio::error Thrown on failure.
*/
void get_host_by_name(const std::string& name, host& h)
{
@ -184,7 +184,7 @@ public:
* will be made of the handler as required. The equivalent function signature
* of the handler must be:
* @code void error_handler(
* const asio::socket_error& error // Result of operation
* const asio::error& error // Result of operation
* ); @endcode
*/
template <typename Error_Handler>

View File

@ -22,7 +22,7 @@
#include <boost/noncopyable.hpp>
#include "asio/detail/pop_options.hpp"
#include "asio/socket_error.hpp"
#include "asio/error.hpp"
#include "asio/detail/socket_ops.hpp"
#include "asio/detail/socket_types.hpp"
#include "asio/ipv4/host.hpp"
@ -87,7 +87,7 @@ public:
{
char name[1024];
if (asio::detail::socket_ops::gethostname(name, sizeof(name)) != 0)
error_handler(socket_error(asio::detail::socket_ops::get_error()));
error_handler(asio::error(asio::detail::socket_ops::get_error()));
else
get_host_by_name(impl, name, h, error_handler);
}
@ -105,9 +105,9 @@ public:
if (asio::detail::socket_ops::gethostbyaddr_r(
reinterpret_cast<const char*>(&a), sizeof(in_addr), AF_INET, &ent,
buf, sizeof(buf), &error) == 0)
error_handler(socket_error(error));
error_handler(asio::error(error));
else if (ent.h_length != sizeof(in_addr))
error_handler(socket_error(socket_error::host_not_found));
error_handler(asio::error(asio::error::host_not_found));
else
populate_host_object(h, ent);
}
@ -122,9 +122,9 @@ public:
int error = 0;
if (asio::detail::socket_ops::gethostbyname_r(name.c_str(), &ent, buf,
sizeof(buf), &error) == 0)
error_handler(socket_error(error));
error_handler(asio::error(error));
else if (ent.h_addrtype != AF_INET || ent.h_length != sizeof(in_addr))
error_handler(socket_error(socket_error::host_not_found));
error_handler(asio::error(asio::error::host_not_found));
else
populate_host_object(h, ent);
}

View File

@ -17,6 +17,7 @@
#include "asio/detail/push_options.hpp"
#include "asio/error.hpp"
#include "asio/socket_option.hpp"
#include "asio/ipv4/address.hpp"
#include "asio/detail/socket_types.hpp"
@ -157,7 +158,7 @@ public:
void native_size(native_size_type size)
{
if (size != sizeof(addr_))
throw socket_error(socket_error::invalid_argument);
throw asio::error(asio::error::invalid_argument);
}
/// Get the port associated with the endpoint. The port number is always in

View File

@ -17,6 +17,7 @@
#include "asio/detail/push_options.hpp"
#include "asio/error.hpp"
#include "asio/detail/socket_types.hpp"
namespace asio {
@ -152,7 +153,7 @@ public:
void native_size(native_size_type size)
{
if (size != sizeof(addr_))
throw socket_error(socket_error::invalid_argument);
throw asio::error(asio::error::invalid_argument);
}
/// Get the port associated with the endpoint. The port number is always in

View File

@ -43,6 +43,7 @@ documentation</a> for more information on how to use <tt>boost::bind</tt>.
\li asio::demuxer
\li asio::dgram_socket
\li asio::error
\li asio::ipv4::address
\li asio::ipv4::host
\li asio::ipv4::host_resolver
@ -53,7 +54,6 @@ documentation</a> for more information on how to use <tt>boost::bind</tt>.
\li asio::locking_dispatcher
\li asio::socket_acceptor
\li asio::socket_connector
\li asio::socket_error
\li asio::stream_socket
\li asio::thread
\li asio::timer

View File

@ -31,7 +31,7 @@ public:
private:
void handle_connect(const asio::socket_error& error)
void handle_connect(const asio::error& error)
{
if (!error)
{
@ -42,7 +42,7 @@ private:
}
}
void handle_recv_header(const asio::socket_error& error, size_t last_length)
void handle_recv_header(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0 && recv_msg_.decode_header())
{
@ -56,7 +56,7 @@ private:
}
}
void handle_recv_body(const asio::socket_error& error, size_t last_length)
void handle_recv_body(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0)
{
@ -86,7 +86,7 @@ private:
}
}
void handle_send(const asio::socket_error& error, size_t last_length)
void handle_send(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0)
{
@ -154,9 +154,9 @@ int main(int argc, char* argv[])
c.close();
t.join();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -98,7 +98,7 @@ public:
}
}
void handle_recv_header(const asio::socket_error& error, size_t last_length)
void handle_recv_header(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0 && recv_msg_.decode_header())
{
@ -112,7 +112,7 @@ public:
}
}
void handle_recv_body(const asio::socket_error& error, size_t last_length)
void handle_recv_body(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0)
{
@ -128,7 +128,7 @@ public:
}
}
void handle_send(const asio::socket_error& error, size_t last_length)
void handle_send(const asio::error& error, size_t last_length)
{
if (!error && last_length > 0)
{
@ -171,7 +171,7 @@ public:
asio::arg::error));
}
void handle_accept(chat_session_ptr session, const asio::socket_error& error)
void handle_accept(chat_session_ptr session, const asio::error& error)
{
if (!error)
{
@ -217,9 +217,9 @@ int main(int argc, char* argv[])
d.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -23,7 +23,7 @@ public:
asio::arg::bytes_recvd));
}
void handle_recv(const asio::socket_error& error, size_t bytes_recvd)
void handle_recv(const asio::error& error, size_t bytes_recvd)
{
if (!error && bytes_recvd > 0)
{
@ -37,7 +37,7 @@ public:
}
}
void handle_send(const asio::socket_error& error, size_t last_bytes_sent)
void handle_send(const asio::error& error, size_t last_bytes_sent)
{
if (!error && last_bytes_sent > 0)
{
@ -70,7 +70,7 @@ public:
asio::arg::error));
}
void handle_accept(session* new_session, const asio::socket_error& error)
void handle_accept(session* new_session, const asio::error& error)
{
if (!error)
{
@ -108,9 +108,9 @@ int main(int argc, char* argv[])
d.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -15,7 +15,7 @@ public:
asio::arg::bytes_recvd));
}
void handle_recvfrom(const asio::socket_error& error, size_t bytes_recvd)
void handle_recvfrom(const asio::error& error, size_t bytes_recvd)
{
if (!error && bytes_recvd > 0)
{
@ -31,7 +31,7 @@ public:
}
}
void handle_sendto(const asio::socket_error& error, size_t bytes_sent)
void handle_sendto(const asio::error& error, size_t bytes_sent)
{
socket_.async_recvfrom(data_, max_length, sender_endpoint_,
boost::bind(&server::handle_recvfrom, this, asio::arg::error,
@ -63,9 +63,9 @@ int main(int argc, char* argv[])
d.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -39,9 +39,9 @@ int main(int argc, char* argv[])
std::cout.write(reply, reply_length);
std::cout << "\n";
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -19,9 +19,9 @@ void session(stream_socket_ptr sock)
if (asio::send_n(*sock, data, length) <= 0)
break;
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error in thread: " << e.message() << "\n";
std::cerr << "Error in thread: " << e << "\n";
}
catch (std::exception& e)
{
@ -55,9 +55,9 @@ int main(int argc, char* argv[])
using namespace std; // For atoi.
server(d, atoi(argv[1]));
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -38,9 +38,9 @@ int main(int argc, char* argv[])
std::cout.write(reply, reply_length);
std::cout << "\n";
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -31,9 +31,9 @@ int main(int argc, char* argv[])
using namespace std; // For atoi.
server(d, atoi(argv[1]));
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << "Socket error: " << e.message() << "\n";
std::cerr << e << "\n";
}
catch (std::exception& e)
{

View File

@ -20,11 +20,11 @@ public:
timer_.async_wait(boost::bind(&socket_acceptor::close, &acceptor_));
}
void handle_accept(const socket_error& error)
void handle_accept(const error& err)
{
if (error)
if (err)
{
std::cout << "Accept error: " << error.message() << "\n";
std::cout << "Accept error: " << err << "\n";
}
else
{

View File

@ -21,11 +21,11 @@ public:
timer_.async_wait(boost::bind(&socket_connector::close, &connector_));
}
void handle_connect(const socket_error& error)
void handle_connect(const error& err)
{
if (error)
if (err)
{
std::cout << "Connect error: " << error.message() << "\n";
std::cout << "Connect error: " << err << "\n";
}
else
{

View File

@ -20,11 +20,11 @@ public:
timer_.async_wait(boost::bind(&dgram_socket::close, &socket_));
}
void handle_recvfrom(const socket_error& error, size_t length)
void handle_recvfrom(const error& err, size_t length)
{
if (error)
if (err)
{
std::cout << "Receive error: " << error.message() << "\n";
std::cout << "Receive error: " << err << "\n";
}
else
{

View File

@ -27,7 +27,7 @@ int main(int argc, char* argv[])
while (size_t len = socket.recv(buf, sizeof(buf)))
std::cout.write(buf, len);
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -23,7 +23,7 @@ int main()
asio::send_n(socket, msg.c_str(), msg.length(), 0, asio::ignore_error());
}
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -4,7 +4,7 @@
#include "asio.hpp"
void handle_send(asio::stream_socket* socket, char* send_buf,
const asio::socket_error& /*error*/, size_t /*last_bytes_sent*/,
const asio::error& /*error*/, size_t /*last_bytes_sent*/,
size_t /*total_bytes_sent*/)
{
using namespace std; // For free.
@ -13,7 +13,7 @@ void handle_send(asio::stream_socket* socket, char* send_buf,
}
void handle_accept(asio::socket_acceptor* acceptor,
asio::stream_socket* socket, const asio::socket_error& error)
asio::stream_socket* socket, const asio::error& error)
{
if (!error)
{
@ -52,7 +52,7 @@ int main()
demuxer.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -28,7 +28,7 @@ int main(int argc, char* argv[])
size_t len = socket.recvfrom(recv_buf, sizeof(recv_buf), sender_endpoint);
std::cout.write(recv_buf, len);
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -16,8 +16,7 @@ int main()
char recv_buf[1];
asio::ipv4::udp::endpoint remote_endpoint;
socket.recvfrom(recv_buf, sizeof(recv_buf), remote_endpoint,
asio::throw_error_if(
asio::error != asio::socket_error::message_size));
asio::throw_error_if(asio::the_error != asio::error::message_size));
using namespace std; // For time_t, time and ctime.
time_t now = time(0);
@ -27,7 +26,7 @@ int main()
asio::ignore_error());
}
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -3,7 +3,7 @@
#include "boost/bind.hpp"
#include "asio.hpp"
void handle_sendto(char* send_buf, const asio::socket_error& /*error*/,
void handle_sendto(char* send_buf, const asio::error& /*error*/,
size_t /*bytes_sent*/)
{
using namespace std; // For free.
@ -12,9 +12,9 @@ void handle_sendto(char* send_buf, const asio::socket_error& /*error*/,
void handle_recvfrom(asio::dgram_socket* socket, char* recv_buf,
size_t recv_length, asio::ipv4::udp::endpoint* remote_endpoint,
const asio::socket_error& error, size_t /*bytes_recvd*/)
const asio::error& error, size_t /*bytes_recvd*/)
{
if (!error || error == asio::socket_error::message_size)
if (!error || error == asio::error::message_size)
{
using namespace std; // For time_t, time, ctime, strdup and strlen.
time_t now = time(0);
@ -49,7 +49,7 @@ int main()
demuxer.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -11,7 +11,7 @@ void handle_tcp_send(asio::stream_socket* socket, char* send_buf)
}
void handle_tcp_accept(asio::socket_acceptor* acceptor,
asio::stream_socket* socket, const asio::socket_error& error)
asio::stream_socket* socket, const asio::error& error)
{
if (!error)
{
@ -42,9 +42,9 @@ void handle_udp_sendto(char* send_buf)
void handle_udp_recvfrom(asio::dgram_socket* socket, char* recv_buf,
size_t recv_length, asio::ipv4::udp::endpoint* remote_endpoint,
const asio::socket_error& error)
const asio::error& error)
{
if (!error || error == asio::socket_error::message_size)
if (!error || error == asio::error::message_size)
{
using namespace std; // For time_t, time, ctime, strdup and strlen.
time_t now = time(0);
@ -86,7 +86,7 @@ int main()
demuxer.run();
}
catch (asio::socket_error& e)
catch (asio::error& e)
{
std::cerr << e << std::endl;
}

View File

@ -100,9 +100,9 @@ public:
dispatcher_.post(boost::bind(&stream_socket::close, &socket_));
}
void handle_recv(const socket_error& error, size_t length)
void handle_recv(const error& err, size_t length)
{
if (!error && length > 0)
if (!err && length > 0)
{
bytes_recvd_ += length;
@ -121,10 +121,9 @@ public:
}
}
void handle_send(const socket_error& error, size_t last_length,
size_t total_length)
void handle_send(const error& err, size_t last_length, size_t total_length)
{
if (!error && last_length > 0)
if (!err && last_length > 0)
{
bytes_sent_ += total_length;
@ -196,9 +195,9 @@ public:
boost::mem_fn(&session::stop));
}
void handle_connect(session* new_session, const socket_error& error)
void handle_connect(session* new_session, const error& err)
{
if (!error)
if (!err)
{
sessions_.push_back(new_session);
new_session->start();

View File

@ -55,11 +55,11 @@ public:
arg::bytes_recvd)));
}
void handle_recv(const socket_error& error, size_t length)
void handle_recv(const error& err, size_t length)
{
--op_count_;
if (!error && length > 0)
if (!err && length > 0)
{
recv_data_length_ = length;
++unsent_count_;
@ -80,11 +80,11 @@ public:
demuxer_.post(boost::bind(&session::destroy, this));
}
void handle_send(const socket_error& error, size_t last_length)
void handle_send(const error& err, size_t last_length)
{
--op_count_;
if (!error && last_length > 0)
if (!err && last_length > 0)
{
--unsent_count_;
if (unsent_count_ == 1)
@ -139,9 +139,9 @@ public:
boost::bind(&server::handle_accept, this, new_session, arg::error));
}
void handle_accept(session* new_session, const socket_error& error)
void handle_accept(session* new_session, const error& err)
{
if (!error)
if (!err)
{
new_session->start();
new_session = new session(demuxer_, block_size_);

View File

@ -19,17 +19,17 @@
using namespace asio;
void handle_send(size_t expected_bytes_sent, const socket_error& error,
void handle_send(size_t expected_bytes_sent, const error& err,
size_t bytes_sent)
{
UNIT_TEST_CHECK(!error);
UNIT_TEST_CHECK(!err);
UNIT_TEST_CHECK(expected_bytes_sent == bytes_sent);
}
void handle_recv(size_t expected_bytes_recvd, const socket_error& error,
void handle_recv(size_t expected_bytes_recvd, const error& err,
size_t bytes_recvd)
{
UNIT_TEST_CHECK(!error);
UNIT_TEST_CHECK(!err);
UNIT_TEST_CHECK(expected_bytes_recvd == bytes_recvd);
}

View File

@ -26,7 +26,7 @@ void error_handler_test()
socket_connector c(d);
ipv4::tcp::endpoint endpoint(321, ipv4::address::any());
socket_error expected_err;
error expected_err;
c.connect(s, endpoint, set_error(expected_err));
std::ostringstream os;
@ -34,27 +34,27 @@ void error_handler_test()
UNIT_TEST_CHECK(!os.str().empty());
os.str("");
c.connect(s, endpoint, error == expected_err || log_error(os));
c.connect(s, endpoint, the_error == expected_err || log_error(os));
UNIT_TEST_CHECK(os.str().empty());
os.str("");
c.connect(s, endpoint, error == expected_err && log_error(os));
c.connect(s, endpoint, the_error == expected_err && log_error(os));
UNIT_TEST_CHECK(!os.str().empty());
os.str("");
c.connect(s, endpoint, error != expected_err || log_error(os));
c.connect(s, endpoint, the_error != expected_err || log_error(os));
UNIT_TEST_CHECK(!os.str().empty());
os.str("");
c.connect(s, endpoint, error != expected_err && log_error(os));
c.connect(s, endpoint, the_error != expected_err && log_error(os));
UNIT_TEST_CHECK(os.str().empty());
os.str("");
c.connect(s, endpoint, log_error_if(os, error == expected_err));
c.connect(s, endpoint, log_error_if(os, the_error == expected_err));
UNIT_TEST_CHECK(!os.str().empty());
os.str("");
c.connect(s, endpoint, log_error_if(os, error != expected_err));
c.connect(s, endpoint, log_error_if(os, the_error != expected_err));
UNIT_TEST_CHECK(os.str().empty());
try
@ -62,127 +62,127 @@ void error_handler_test()
c.connect(s, endpoint, throw_error());
UNIT_TEST_CHECK(0);
}
catch (socket_error&)
catch (error&)
{
}
try
{
c.connect(s, endpoint, error == expected_err || throw_error());
c.connect(s, endpoint, the_error == expected_err || throw_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, error == expected_err && throw_error());
c.connect(s, endpoint, the_error == expected_err && throw_error());
UNIT_TEST_CHECK(0);
}
catch (socket_error&)
catch (error&)
{
}
try
{
c.connect(s, endpoint, error != expected_err || throw_error());
c.connect(s, endpoint, the_error != expected_err || throw_error());
UNIT_TEST_CHECK(0);
}
catch (socket_error&)
catch (error&)
{
}
try
{
c.connect(s, endpoint, error != expected_err && throw_error());
c.connect(s, endpoint, the_error != expected_err && throw_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, throw_error_if(error == expected_err));
c.connect(s, endpoint, throw_error_if(the_error == expected_err));
UNIT_TEST_CHECK(0);
}
catch (socket_error&)
catch (error&)
{
}
try
{
c.connect(s, endpoint, throw_error_if(error != expected_err));
c.connect(s, endpoint, throw_error_if(the_error != expected_err));
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
socket_error err;
error err;
c.connect(s, endpoint, set_error(err));
UNIT_TEST_CHECK(err == expected_err);
c.connect(s, endpoint, error == expected_err || set_error(err));
c.connect(s, endpoint, the_error == expected_err || set_error(err));
UNIT_TEST_CHECK(err != expected_err);
c.connect(s, endpoint, error == expected_err && set_error(err));
c.connect(s, endpoint, the_error == expected_err && set_error(err));
UNIT_TEST_CHECK(err == expected_err);
c.connect(s, endpoint, error != expected_err || set_error(err));
c.connect(s, endpoint, the_error != expected_err || set_error(err));
UNIT_TEST_CHECK(err == expected_err);
c.connect(s, endpoint, error != expected_err && set_error(err));
c.connect(s, endpoint, the_error != expected_err && set_error(err));
UNIT_TEST_CHECK(err != expected_err);
c.connect(s, endpoint, set_error_if(err, error == expected_err));
c.connect(s, endpoint, set_error_if(err, the_error == expected_err));
UNIT_TEST_CHECK(err == expected_err);
c.connect(s, endpoint, set_error_if(err, error != expected_err));
c.connect(s, endpoint, set_error_if(err, the_error != expected_err));
UNIT_TEST_CHECK(err != expected_err);
try
{
c.connect(s, endpoint, ignore_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, error == expected_err || ignore_error());
c.connect(s, endpoint, the_error == expected_err || ignore_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, error == expected_err && ignore_error());
c.connect(s, endpoint, the_error == expected_err && ignore_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, error != expected_err || ignore_error());
c.connect(s, endpoint, the_error != expected_err || ignore_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
try
{
c.connect(s, endpoint, error != expected_err && ignore_error());
c.connect(s, endpoint, the_error != expected_err && ignore_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
@ -190,9 +190,9 @@ void error_handler_test()
try
{
c.connect(s, endpoint,
ignore_error_if(error == expected_err) || throw_error());
ignore_error_if(the_error == expected_err) || throw_error());
}
catch (socket_error&)
catch (error&)
{
UNIT_TEST_CHECK(0);
}
@ -200,10 +200,10 @@ void error_handler_test()
try
{
c.connect(s, endpoint,
ignore_error_if(error != expected_err) || throw_error());
ignore_error_if(the_error != expected_err) || throw_error());
UNIT_TEST_CHECK(0);
}
catch (socket_error&)
catch (error&)
{
}
}

View File

@ -56,7 +56,7 @@ public:
template <typename Handler>
void async_send(const void* data, size_t length, Handler handler)
{
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, 0));
}
@ -74,7 +74,7 @@ public:
template <typename Handler>
void async_recv(void* data, size_t length, Handler handler)
{
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, 0));
}

View File

@ -56,7 +56,7 @@ public:
template <typename Handler>
void async_send(const void* data, size_t length, Handler handler)
{
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, 0));
}
@ -74,7 +74,7 @@ public:
template <typename Handler>
void async_recv(void* data, size_t length, Handler handler)
{
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, 0));
}

View File

@ -95,7 +95,7 @@ public:
void async_recv(void* data, size_t length, Handler handler)
{
size_t bytes_recvd = recv(data, length);
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, bytes_recvd));
}
@ -168,7 +168,7 @@ void test_recv_with_error_handler()
UNIT_TEST_CHECK(s.check(recv_buf, 10));
}
void async_recv_handler(const asio::socket_error& e, size_t bytes_recvd,
void async_recv_handler(const asio::error& e, size_t bytes_recvd,
size_t expected_bytes_recvd, bool* called)
{
*called = true;
@ -332,7 +332,7 @@ void test_recv_n_with_error_handler()
UNIT_TEST_CHECK(s.check(recv_buf, sizeof(recv_data)));
}
void async_recv_n_handler(const asio::socket_error& e, size_t last_bytes_recvd,
void async_recv_n_handler(const asio::error& e, size_t last_bytes_recvd,
size_t total_bytes_recvd, size_t expected_last_bytes_recvd,
size_t expected_total_bytes_recvd, bool* called)
{
@ -703,7 +703,7 @@ void test_recv_at_least_n_with_error_handler()
UNIT_TEST_CHECK(s.check(recv_buf, sizeof(recv_data)));
}
void async_recv_at_least_n_handler(const asio::socket_error& e,
void async_recv_at_least_n_handler(const asio::error& e,
size_t last_bytes_recvd, size_t total_bytes_recvd,
size_t expected_last_bytes_recvd, size_t expected_total_bytes_recvd,
bool* called)

View File

@ -96,7 +96,7 @@ public:
void async_send(const void* data, size_t length, Handler handler)
{
size_t bytes_sent = send(data, length);
asio::socket_error error;
asio::error error;
demuxer_.post(asio::detail::bind_handler(handler, error, bytes_sent));
}
@ -161,7 +161,7 @@ void test_send_with_error_handler()
UNIT_TEST_CHECK(s.check(send_data, 10));
}
void async_send_handler(const asio::socket_error& e, size_t bytes_sent,
void async_send_handler(const asio::error& e, size_t bytes_sent,
size_t expected_bytes_sent, bool* called)
{
*called = true;
@ -307,7 +307,7 @@ void test_send_n_with_error_handler()
UNIT_TEST_CHECK(s.check(send_data, sizeof(send_data)));
}
void async_send_n_handler(const asio::socket_error& e, size_t last_bytes_sent,
void async_send_n_handler(const asio::error& e, size_t last_bytes_sent,
size_t total_bytes_sent, size_t expected_last_bytes_sent,
size_t expected_total_bytes_sent, bool* called)
{
@ -640,7 +640,7 @@ void test_send_at_least_n_with_error_handler()
UNIT_TEST_CHECK(s.check(send_data, sizeof(send_data)));
}
void async_send_at_least_n_handler(const asio::socket_error& e,
void async_send_at_least_n_handler(const asio::error& e,
size_t last_bytes_sent, size_t total_bytes_sent,
size_t expected_last_bytes_sent, size_t expected_total_bytes_sent,
bool* called)

View File

@ -19,14 +19,14 @@
using namespace asio;
void handle_accept(const socket_error& error)
void handle_accept(const error& err)
{
UNIT_TEST_CHECK(!error);
UNIT_TEST_CHECK(!err);
}
void handle_connect(const socket_error& error)
void handle_connect(const error& err)
{
UNIT_TEST_CHECK(!error);
UNIT_TEST_CHECK(!err);
}
void socket_acceptor_test()