Use protocol-specific socket and acceptor types. The stream_socket,
datagram_socket and socket_acceptor typedefs have been removed.
This commit is contained in:
parent
12fdd7b4c5
commit
efb4d691b9
@ -1,5 +1,4 @@
|
||||
nobase_include_HEADERS = \
|
||||
asio.hpp \
|
||||
asio/basic_datagram_socket.hpp \
|
||||
asio/basic_deadline_timer.hpp \
|
||||
asio/basic_io_service.hpp \
|
||||
@ -14,7 +13,6 @@ nobase_include_HEADERS = \
|
||||
asio/buffered_write_stream.hpp \
|
||||
asio/buffered_write_stream_fwd.hpp \
|
||||
asio/completion_condition.hpp \
|
||||
asio/datagram_socket.hpp \
|
||||
asio/datagram_socket_service.hpp \
|
||||
asio/deadline_timer.hpp \
|
||||
asio/deadline_timer_service.hpp \
|
||||
@ -97,7 +95,6 @@ nobase_include_HEADERS = \
|
||||
asio/placeholders.hpp \
|
||||
asio/read.hpp \
|
||||
asio/service_factory.hpp \
|
||||
asio/socket_acceptor.hpp \
|
||||
asio/socket_acceptor_service.hpp \
|
||||
asio/socket_base.hpp \
|
||||
asio/ssl/basic_context.hpp \
|
||||
@ -113,12 +110,13 @@ nobase_include_HEADERS = \
|
||||
asio/ssl/stream_base.hpp \
|
||||
asio/ssl/stream_service.hpp \
|
||||
asio/ssl.hpp \
|
||||
asio/stream_socket.hpp \
|
||||
asio/stream_socket_service.hpp \
|
||||
asio/system_exception.hpp \
|
||||
asio/thread.hpp \
|
||||
asio/time_traits.hpp \
|
||||
asio/write.hpp
|
||||
asio/write.hpp \
|
||||
asio.hpp
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
$(srcdir)/Makefile.in
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "asio/buffered_write_stream_fwd.hpp"
|
||||
#include "asio/buffered_write_stream.hpp"
|
||||
#include "asio/completion_condition.hpp"
|
||||
#include "asio/datagram_socket.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
#include "asio/deadline_timer_service.hpp"
|
||||
#include "asio/deadline_timer.hpp"
|
||||
@ -51,10 +50,8 @@
|
||||
#include "asio/placeholders.hpp"
|
||||
#include "asio/read.hpp"
|
||||
#include "asio/service_factory.hpp"
|
||||
#include "asio/socket_acceptor.hpp"
|
||||
#include "asio/socket_acceptor_service.hpp"
|
||||
#include "asio/socket_base.hpp"
|
||||
#include "asio/stream_socket.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
#include "asio/system_exception.hpp"
|
||||
#include "asio/thread.hpp"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <boost/config.hpp>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
@ -59,6 +60,12 @@ public:
|
||||
/// The io_service type for this type.
|
||||
typedef typename service_type::io_service_type io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef typename service_type::protocol_type protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename service_type::endpoint_type endpoint_type;
|
||||
|
||||
/// The type used for reporting errors.
|
||||
typedef asio::error error_type;
|
||||
|
||||
@ -75,11 +82,31 @@ public:
|
||||
* socket.
|
||||
*/
|
||||
explicit basic_datagram_socket(io_service_type& io_service)
|
||||
: service_(io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_.null())
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_datagram_socket.
|
||||
/**
|
||||
* This constructor creates and opens a datagram socket.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(io_service_type& io_service,
|
||||
const protocol_type& protocol)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
@ -87,7 +114,7 @@ public:
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will usei
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
@ -96,21 +123,41 @@ public:
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
basic_datagram_socket(io_service_type& io_service, const Endpoint& endpoint)
|
||||
: service_(io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_.null())
|
||||
basic_datagram_socket(io_service_type& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_.open(impl_, endpoint.protocol(), throw_error());
|
||||
service_->open(impl_, endpoint.protocol(), throw_error());
|
||||
close_on_block_exit auto_close(service_, impl_);
|
||||
service_.bind(impl_, endpoint, throw_error());
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
auto_close.cancel();
|
||||
}
|
||||
|
||||
/// Construct a basic_datagram_socket on an existing implementation.
|
||||
/**
|
||||
* This constructor creates a datagram socket to hold an existing
|
||||
* implementation.
|
||||
*
|
||||
* @param io_service The io_service object that the datagram socket will use
|
||||
* to dispatch handlers for any asynchronous operations performed on the
|
||||
* socket.
|
||||
*
|
||||
* @param impl The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_datagram_socket(io_service_type& io_service, impl_type impl)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(impl)
|
||||
{
|
||||
service_->assign(impl_, impl);
|
||||
}
|
||||
|
||||
/// Destructor.
|
||||
~basic_datagram_socket()
|
||||
{
|
||||
service_.close(impl_, ignore_error());
|
||||
service_->close(impl_, ignore_error());
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
@ -123,7 +170,7 @@ public:
|
||||
*/
|
||||
io_service_type& io_service()
|
||||
{
|
||||
return service_.io_service();
|
||||
return service_->io_service();
|
||||
}
|
||||
|
||||
/// Open the socket using the specified protocol.
|
||||
@ -141,10 +188,9 @@ public:
|
||||
* socket.open(asio::ipv4::udp());
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol>
|
||||
void open(const Protocol& protocol)
|
||||
void open(const protocol_type& protocol = protocol_type())
|
||||
{
|
||||
service_.open(impl_, protocol, throw_error());
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Open the socket using the specified protocol.
|
||||
@ -172,10 +218,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(const Protocol& protocol, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void open(const protocol_type& protocol, Error_Handler error_handler)
|
||||
{
|
||||
service_.open(impl_, protocol, error_handler);
|
||||
service_->open(impl_, protocol, error_handler);
|
||||
}
|
||||
|
||||
/// Close the socket.
|
||||
@ -190,7 +236,7 @@ public:
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
service_.close(impl_, throw_error());
|
||||
service_->close(impl_, throw_error());
|
||||
}
|
||||
|
||||
/// Close the socket.
|
||||
@ -223,7 +269,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void close(Error_Handler error_handler)
|
||||
{
|
||||
service_.close(impl_, error_handler);
|
||||
service_->close(impl_, error_handler);
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
@ -260,7 +306,7 @@ public:
|
||||
*/
|
||||
void set_impl(impl_type new_impl)
|
||||
{
|
||||
service_.assign(impl_, new_impl);
|
||||
service_->assign(impl_, new_impl);
|
||||
}
|
||||
|
||||
/// Bind the socket to the given local endpoint.
|
||||
@ -280,10 +326,9 @@ public:
|
||||
* socket.bind(asio::ipv4::udp::endpoint(12345));
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void bind(const Endpoint& endpoint)
|
||||
void bind(const endpoint_type& endpoint)
|
||||
{
|
||||
service_.bind(impl_, endpoint, throw_error());
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Bind the socket to the given local endpoint.
|
||||
@ -314,10 +359,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(const Endpoint& endpoint, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void bind(const endpoint_type& endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_.bind(impl_, endpoint, error_handler);
|
||||
service_->bind(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Connect a datagram socket to the specified endpoint.
|
||||
@ -343,10 +388,9 @@ public:
|
||||
* socket.connect(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void connect(const Endpoint& peer_endpoint)
|
||||
void connect(const endpoint_type& peer_endpoint)
|
||||
{
|
||||
service_.connect(impl_, peer_endpoint, throw_error());
|
||||
service_->connect(impl_, peer_endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Connect a datagram socket to the specified endpoint.
|
||||
@ -382,10 +426,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void connect(const Endpoint& peer_endpoint, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void connect(const endpoint_type& peer_endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_.connect(impl_, peer_endpoint, error_handler);
|
||||
service_->connect(impl_, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
@ -429,10 +473,10 @@ public:
|
||||
* socket.async_connect(endpoint, connect_handler);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_connect(const Endpoint& peer_endpoint, Handler handler)
|
||||
template <typename Handler>
|
||||
void async_connect(const endpoint_type& peer_endpoint, Handler handler)
|
||||
{
|
||||
service_.async_connect(impl_, peer_endpoint, handler);
|
||||
service_->async_connect(impl_, peer_endpoint, handler);
|
||||
}
|
||||
|
||||
/// Set an option on the socket.
|
||||
@ -465,7 +509,7 @@ public:
|
||||
template <typename Socket_Option>
|
||||
void set_option(const Socket_Option& option)
|
||||
{
|
||||
service_.set_option(impl_, option, throw_error());
|
||||
service_->set_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Set an option on the socket.
|
||||
@ -508,7 +552,7 @@ public:
|
||||
template <typename Socket_Option, typename Error_Handler>
|
||||
void set_option(const Socket_Option& option, Error_Handler error_handler)
|
||||
{
|
||||
service_.set_option(impl_, option, error_handler);
|
||||
service_->set_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Get an option from the socket.
|
||||
@ -542,7 +586,7 @@ public:
|
||||
template <typename Socket_Option>
|
||||
void get_option(Socket_Option& option) const
|
||||
{
|
||||
service_.get_option(impl_, option, throw_error());
|
||||
service_->get_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Get an option from the socket.
|
||||
@ -586,7 +630,7 @@ public:
|
||||
template <typename Socket_Option, typename Error_Handler>
|
||||
void get_option(Socket_Option& option, Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_option(impl_, option, error_handler);
|
||||
service_->get_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Perform an IO control command on the socket.
|
||||
@ -614,7 +658,7 @@ public:
|
||||
template <typename IO_Control_Command>
|
||||
void io_control(IO_Control_Command& command)
|
||||
{
|
||||
service_.io_control(impl_, command, throw_error());
|
||||
service_->io_control(impl_, command, throw_error());
|
||||
}
|
||||
|
||||
/// Perform an IO control command on the socket.
|
||||
@ -652,7 +696,7 @@ public:
|
||||
template <typename IO_Control_Command, typename Error_Handler>
|
||||
void io_control(IO_Control_Command& command, Error_Handler error_handler)
|
||||
{
|
||||
service_.io_control(impl_, command, error_handler);
|
||||
service_->io_control(impl_, command, error_handler);
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the socket.
|
||||
@ -672,10 +716,9 @@ public:
|
||||
* socket.get_local_endpoint(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void get_local_endpoint(Endpoint& endpoint) const
|
||||
void get_local_endpoint(endpoint_type& endpoint) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, throw_error());
|
||||
service_->get_local_endpoint(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the socket.
|
||||
@ -705,11 +748,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, error_handler);
|
||||
service_->get_local_endpoint(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Get the remote endpoint of the socket.
|
||||
@ -729,10 +772,9 @@ public:
|
||||
* socket.get_remote_endpoint(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void get_remote_endpoint(Endpoint& endpoint) const
|
||||
void get_remote_endpoint(endpoint_type& endpoint) const
|
||||
{
|
||||
service_.get_remote_endpoint(impl_, endpoint, throw_error());
|
||||
service_->get_remote_endpoint(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Get the remote endpoint of the socket.
|
||||
@ -762,11 +804,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_remote_endpoint(Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_remote_endpoint(endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_remote_endpoint(impl_, endpoint, error_handler);
|
||||
service_->get_remote_endpoint(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Disable sends or receives on the socket.
|
||||
@ -788,7 +830,7 @@ public:
|
||||
*/
|
||||
void shutdown(shutdown_type what)
|
||||
{
|
||||
service_.shutdown(impl_, what, throw_error());
|
||||
service_->shutdown(impl_, what, throw_error());
|
||||
}
|
||||
|
||||
/// Disable sends or receives on the socket.
|
||||
@ -822,7 +864,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void shutdown(shutdown_type what, Error_Handler error_handler)
|
||||
{
|
||||
service_.shutdown(impl_, what, error_handler);
|
||||
service_->shutdown(impl_, what, error_handler);
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
@ -852,7 +894,7 @@ public:
|
||||
template <typename Const_Buffers>
|
||||
std::size_t send(const Const_Buffers& buffers, message_flags flags)
|
||||
{
|
||||
return service_.send(impl_, buffers, flags, throw_error());
|
||||
return service_->send(impl_, buffers, flags, throw_error());
|
||||
}
|
||||
|
||||
/// Send some data on a connected socket.
|
||||
@ -881,7 +923,7 @@ public:
|
||||
std::size_t send(const Const_Buffers& buffers, message_flags flags,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.send(impl_, buffers, flags, error_handler);
|
||||
return service_->send(impl_, buffers, flags, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send on a connected socket.
|
||||
@ -926,7 +968,7 @@ public:
|
||||
void async_send(const Const_Buffers& buffers, message_flags flags,
|
||||
Handler handler)
|
||||
{
|
||||
service_.async_send(impl_, buffers, flags, handler);
|
||||
service_->async_send(impl_, buffers, flags, handler);
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
@ -955,11 +997,11 @@ public:
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename Const_Buffers, typename Endpoint>
|
||||
template <typename Const_Buffers>
|
||||
std::size_t send_to(const Const_Buffers& buffers, message_flags flags,
|
||||
const Endpoint& destination)
|
||||
const endpoint_type& destination)
|
||||
{
|
||||
return service_.send_to(impl_, buffers, flags, destination, throw_error());
|
||||
return service_->send_to(impl_, buffers, flags, destination, throw_error());
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
@ -983,11 +1025,11 @@ public:
|
||||
*
|
||||
* @returns The number of bytes sent.
|
||||
*/
|
||||
template <typename Const_Buffers, typename Endpoint, typename Error_Handler>
|
||||
template <typename Const_Buffers, typename Error_Handler>
|
||||
std::size_t send_to(const Const_Buffers& buffers, message_flags flags,
|
||||
const Endpoint& destination, Error_Handler error_handler)
|
||||
const endpoint_type& destination, Error_Handler error_handler)
|
||||
{
|
||||
return service_.send_to(impl_, buffers, flags, destination, error_handler);
|
||||
return service_->send_to(impl_, buffers, flags, destination, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@ -1028,11 +1070,11 @@ public:
|
||||
* buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename Const_Buffers, typename Endpoint, typename Handler>
|
||||
template <typename Const_Buffers, typename Handler>
|
||||
void async_send_to(const Const_Buffers& buffers, message_flags flags,
|
||||
const Endpoint& destination, Handler handler)
|
||||
const endpoint_type& destination, Handler handler)
|
||||
{
|
||||
service_.async_send_to(impl_, buffers, flags, destination, handler);
|
||||
service_->async_send_to(impl_, buffers, flags, destination, handler);
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
@ -1064,7 +1106,7 @@ public:
|
||||
template <typename Mutable_Buffers>
|
||||
std::size_t receive(const Mutable_Buffers& buffers, message_flags flags)
|
||||
{
|
||||
return service_.receive(impl_, buffers, flags, throw_error());
|
||||
return service_->receive(impl_, buffers, flags, throw_error());
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
@ -1094,7 +1136,7 @@ public:
|
||||
std::size_t receive(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive(impl_, buffers, flags, error_handler);
|
||||
return service_->receive(impl_, buffers, flags, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive on a connected socket.
|
||||
@ -1139,7 +1181,7 @@ public:
|
||||
void async_receive(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Handler handler)
|
||||
{
|
||||
service_.async_receive(impl_, buffers, flags, handler);
|
||||
service_->async_receive(impl_, buffers, flags, handler);
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
@ -1170,11 +1212,11 @@ public:
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename Mutable_Buffers, typename Endpoint>
|
||||
template <typename Mutable_Buffers>
|
||||
std::size_t receive_from(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Endpoint& sender_endpoint)
|
||||
endpoint_type& sender_endpoint)
|
||||
{
|
||||
return service_.receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
return service_->receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
throw_error());
|
||||
}
|
||||
|
||||
@ -1199,11 +1241,11 @@ public:
|
||||
*
|
||||
* @returns The number of bytes received.
|
||||
*/
|
||||
template <typename Mutable_Buffers, typename Endpoint, typename Error_Handler>
|
||||
template <typename Mutable_Buffers, typename Error_Handler>
|
||||
std::size_t receive_from(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Endpoint& sender_endpoint, Error_Handler error_handler)
|
||||
endpoint_type& sender_endpoint, Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
return service_->receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
error_handler);
|
||||
}
|
||||
|
||||
@ -1245,17 +1287,24 @@ public:
|
||||
* multiple buffers in one go, and how to use it with arrays, boost::array or
|
||||
* std::vector.
|
||||
*/
|
||||
template <typename Mutable_Buffers, typename Endpoint, typename Handler>
|
||||
template <typename Mutable_Buffers, typename Handler>
|
||||
void async_receive_from(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Endpoint& sender_endpoint, Handler handler)
|
||||
endpoint_type& sender_endpoint, Handler handler)
|
||||
{
|
||||
service_.async_receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
service_->async_receive_from(impl_, buffers, flags, sender_endpoint,
|
||||
handler);
|
||||
}
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
void swap(basic_datagram_socket<Service>& other)
|
||||
{
|
||||
std::swap(service_, other.service_);
|
||||
std::swap(impl_, other.impl_);
|
||||
}
|
||||
|
||||
private:
|
||||
/// The backend service implementation.
|
||||
service_type& service_;
|
||||
service_type* service_;
|
||||
|
||||
/// The underlying native implementation.
|
||||
impl_type impl_;
|
||||
@ -1264,8 +1313,8 @@ private:
|
||||
class close_on_block_exit
|
||||
{
|
||||
public:
|
||||
close_on_block_exit(service_type& service, impl_type& impl)
|
||||
: service_(&service), impl_(impl)
|
||||
close_on_block_exit(service_type* service, impl_type& impl)
|
||||
: service_(service), impl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1288,6 +1337,14 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
template <typename Service>
|
||||
inline void swap(basic_datagram_socket<Service>& a,
|
||||
basic_datagram_socket<Service>& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <algorithm>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/error_handler.hpp"
|
||||
#include "asio/service_factory.hpp"
|
||||
@ -65,6 +69,15 @@ public:
|
||||
/// The io_service type for this type.
|
||||
typedef typename service_type::io_service_type io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef typename service_type::protocol_type protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename service_type::endpoint_type endpoint_type;
|
||||
|
||||
/// The socket type to be accepted.
|
||||
typedef typename service_type::socket_type socket_type;
|
||||
|
||||
/// The type used for reporting errors.
|
||||
typedef asio::error error_type;
|
||||
|
||||
@ -79,11 +92,31 @@ public:
|
||||
* acceptor.
|
||||
*/
|
||||
explicit basic_socket_acceptor(io_service_type& io_service)
|
||||
: service_(io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_.null())
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct an open acceptor.
|
||||
/**
|
||||
* This constructor creates an acceptor and automatically opens it.
|
||||
*
|
||||
* @param io_service The io_service object that the acceptor will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the
|
||||
* acceptor.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_socket_acceptor(io_service_type& io_service,
|
||||
const protocol_type& protocol)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Construct an acceptor opened on the given endpoint.
|
||||
/**
|
||||
* This constructor creates an acceptor and automatically opens it to listen
|
||||
@ -109,23 +142,40 @@ public:
|
||||
* acceptor.listen(listen_backlog);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
basic_socket_acceptor(io_service_type& io_service, const Endpoint& endpoint,
|
||||
int listen_backlog = 0)
|
||||
: service_(io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_.null())
|
||||
basic_socket_acceptor(io_service_type& io_service,
|
||||
const endpoint_type& endpoint, int listen_backlog = 0)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_.open(impl_, endpoint.protocol(), throw_error());
|
||||
service_->open(impl_, endpoint.protocol(), throw_error());
|
||||
close_on_block_exit auto_close(service_, impl_);
|
||||
service_.bind(impl_, endpoint, throw_error());
|
||||
service_.listen(impl_, listen_backlog, throw_error());
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
service_->listen(impl_, listen_backlog, throw_error());
|
||||
auto_close.cancel();
|
||||
}
|
||||
|
||||
/// Construct a basic_socket_acceptor on an existing implementation.
|
||||
/**
|
||||
* This constructor creates an acceptor to hold an existing implementation.
|
||||
*
|
||||
* @param io_service The io_service object that the acceptor will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param impl The new underlying acceptor implementation.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_socket_acceptor(io_service_type& io_service, impl_type impl)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(impl)
|
||||
{
|
||||
service_->assign(impl_, impl);
|
||||
}
|
||||
|
||||
/// Destructor.
|
||||
~basic_socket_acceptor()
|
||||
{
|
||||
service_.close(impl_, ignore_error());
|
||||
service_->close(impl_, ignore_error());
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
@ -138,7 +188,7 @@ public:
|
||||
*/
|
||||
io_service_type& io_service()
|
||||
{
|
||||
return service_.io_service();
|
||||
return service_->io_service();
|
||||
}
|
||||
|
||||
/// Open the acceptor using the specified protocol.
|
||||
@ -154,10 +204,9 @@ public:
|
||||
* acceptor.open(asio::ipv4::tcp());
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol>
|
||||
void open(const Protocol& protocol)
|
||||
void open(const protocol_type& protocol = protocol_type())
|
||||
{
|
||||
service_.open(impl_, protocol, throw_error());
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Open the acceptor using the specified protocol.
|
||||
@ -185,10 +234,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(const Protocol& protocol, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void open(const protocol_type& protocol, Error_Handler error_handler)
|
||||
{
|
||||
service_.open(impl_, protocol, error_handler);
|
||||
service_->open(impl_, protocol, error_handler);
|
||||
}
|
||||
|
||||
/// Bind the acceptor to the given local endpoint.
|
||||
@ -208,10 +257,9 @@ public:
|
||||
* acceptor.bind(asio::ipv4::tcp::endpoint(12345));
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void bind(const Endpoint& endpoint)
|
||||
void bind(const endpoint_type& endpoint)
|
||||
{
|
||||
service_.bind(impl_, endpoint, throw_error());
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Bind the acceptor to the given local endpoint.
|
||||
@ -242,10 +290,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(const Endpoint& endpoint, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void bind(const endpoint_type& endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_.bind(impl_, endpoint, error_handler);
|
||||
service_->bind(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Place the acceptor into the state where it will listen for new
|
||||
@ -259,7 +307,7 @@ public:
|
||||
*/
|
||||
void listen(int backlog = 0)
|
||||
{
|
||||
service_.listen(impl_, backlog, throw_error());
|
||||
service_->listen(impl_, backlog, throw_error());
|
||||
}
|
||||
|
||||
/// Place the acceptor into the state where it will listen for new
|
||||
@ -293,7 +341,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void listen(int backlog, Error_Handler error_handler)
|
||||
{
|
||||
service_.listen(impl_, backlog, error_handler);
|
||||
service_->listen(impl_, backlog, error_handler);
|
||||
}
|
||||
|
||||
/// Close the acceptor.
|
||||
@ -308,7 +356,7 @@ public:
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
service_.close(impl_, throw_error());
|
||||
service_->close(impl_, throw_error());
|
||||
}
|
||||
|
||||
/// Close the acceptor.
|
||||
@ -341,7 +389,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void close(Error_Handler error_handler)
|
||||
{
|
||||
service_.close(impl_, error_handler);
|
||||
service_->close(impl_, error_handler);
|
||||
}
|
||||
|
||||
/// Get the underlying implementation in the native type.
|
||||
@ -378,7 +426,7 @@ public:
|
||||
template <typename Option>
|
||||
void set_option(const Option& option)
|
||||
{
|
||||
service_.set_option(impl_, option, throw_error());
|
||||
service_->set_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Set an option on the acceptor.
|
||||
@ -414,7 +462,7 @@ public:
|
||||
template <typename Option, typename Error_Handler>
|
||||
void set_option(const Option& option, Error_Handler error_handler)
|
||||
{
|
||||
service_.set_option(impl_, option, error_handler);
|
||||
service_->set_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Get an option from the acceptor.
|
||||
@ -442,7 +490,7 @@ public:
|
||||
template <typename Option>
|
||||
void get_option(Option& option)
|
||||
{
|
||||
service_.get_option(impl_, option, throw_error());
|
||||
service_->get_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Get an option from the acceptor.
|
||||
@ -480,7 +528,7 @@ public:
|
||||
template <typename Option, typename Error_Handler>
|
||||
void get_option(Option& option, Error_Handler error_handler)
|
||||
{
|
||||
service_.get_option(impl_, option, error_handler);
|
||||
service_->get_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the acceptor.
|
||||
@ -501,10 +549,9 @@ public:
|
||||
* acceptor.get_local_endpoint(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void get_local_endpoint(Endpoint& endpoint) const
|
||||
void get_local_endpoint(endpoint_type& endpoint) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, throw_error());
|
||||
service_->get_local_endpoint(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the acceptor.
|
||||
@ -535,10 +582,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(Endpoint& endpoint, Error_Handler error_handler) const
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, error_handler);
|
||||
service_->get_local_endpoint(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Accept a new connection.
|
||||
@ -559,10 +607,9 @@ public:
|
||||
* acceptor.accept(socket);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Socket>
|
||||
void accept(Socket& peer)
|
||||
void accept(socket_type& peer)
|
||||
{
|
||||
service_.accept(impl_, to_socket(peer), throw_error());
|
||||
service_->accept(impl_, peer, throw_error());
|
||||
}
|
||||
|
||||
/// Accept a new connection.
|
||||
@ -593,10 +640,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Socket, typename Error_Handler>
|
||||
void accept(Socket& peer, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void accept(socket_type& peer, Error_Handler error_handler)
|
||||
{
|
||||
service_.accept(impl_, to_socket(peer), error_handler);
|
||||
service_->accept(impl_, peer, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous accept.
|
||||
@ -637,10 +684,10 @@ public:
|
||||
* acceptor.async_accept(socket, accept_handler);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Socket, typename Handler>
|
||||
void async_accept(Socket& peer, Handler handler)
|
||||
template <typename Handler>
|
||||
void async_accept(socket_type& peer, Handler handler)
|
||||
{
|
||||
service_.async_accept(impl_, to_socket(peer), handler);
|
||||
service_->async_accept(impl_, peer, handler);
|
||||
}
|
||||
|
||||
/// Accept a new connection and obtain the endpoint of the peer
|
||||
@ -666,11 +713,9 @@ public:
|
||||
* acceptor.accept_endpoint(socket, endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Socket, typename Endpoint>
|
||||
void accept_endpoint(Socket& peer, Endpoint& peer_endpoint)
|
||||
void accept_endpoint(socket_type& peer, endpoint_type& peer_endpoint)
|
||||
{
|
||||
service_.accept_endpoint(impl_, to_socket(peer), peer_endpoint,
|
||||
throw_error());
|
||||
service_->accept_endpoint(impl_, peer, peer_endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Accept a new connection and obtain the endpoint of the peer
|
||||
@ -707,12 +752,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Socket, typename Endpoint, typename Error_Handler>
|
||||
void accept_endpoint(Socket& peer, Endpoint& peer_endpoint,
|
||||
template <typename Error_Handler>
|
||||
void accept_endpoint(socket_type& peer, endpoint_type& peer_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_.accept_endpoint(impl_, to_socket(peer), peer_endpoint,
|
||||
error_handler);
|
||||
service_->accept_endpoint(impl_, peer, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous accept.
|
||||
@ -741,34 +785,33 @@ public:
|
||||
* of the handler will be performed in a manner equivalent to using
|
||||
* asio::io_service::post().
|
||||
*/
|
||||
template <typename Socket, typename Endpoint, typename Handler>
|
||||
void async_accept_endpoint(Socket& peer, Endpoint& peer_endpoint,
|
||||
template <typename Handler>
|
||||
void async_accept_endpoint(socket_type& peer, endpoint_type& peer_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
service_.async_accept_endpoint(impl_, to_socket(peer), peer_endpoint,
|
||||
handler);
|
||||
service_->async_accept_endpoint(impl_, peer, peer_endpoint, handler);
|
||||
}
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
void swap(basic_socket_acceptor<Service>& other)
|
||||
{
|
||||
std::swap(service_, other.service_);
|
||||
std::swap(impl_, other.impl_);
|
||||
}
|
||||
|
||||
private:
|
||||
/// The backend service implementation.
|
||||
service_type& service_;
|
||||
service_type* service_;
|
||||
|
||||
/// The underlying native implementation.
|
||||
impl_type impl_;
|
||||
|
||||
// Helper function to convert a stack of layers into a socket.
|
||||
template <typename Socket>
|
||||
typename Socket::lowest_layer_type& to_socket(Socket& peer)
|
||||
{
|
||||
return peer.lowest_layer();
|
||||
}
|
||||
|
||||
// Helper class to automatically close the implementation on block exit.
|
||||
class close_on_block_exit
|
||||
{
|
||||
public:
|
||||
close_on_block_exit(service_type& service, impl_type& impl)
|
||||
: service_(&service), impl_(impl)
|
||||
close_on_block_exit(service_type* service, impl_type& impl)
|
||||
: service_(service), impl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
@ -791,6 +834,14 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
template <typename Service>
|
||||
inline void swap(basic_socket_acceptor<Service>& a,
|
||||
basic_socket_acceptor<Service>& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <boost/config.hpp>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
@ -35,8 +36,6 @@ namespace asio {
|
||||
* The basic_stream_socket class template provides asynchronous and blocking
|
||||
* stream-oriented socket functionality.
|
||||
*
|
||||
* Most applications will use the asio::stream_socket typedef.
|
||||
*
|
||||
* @par Thread Safety:
|
||||
* @e Distinct @e objects: Safe.@n
|
||||
* @e Shared @e objects: Unsafe.
|
||||
@ -60,6 +59,12 @@ public:
|
||||
/// The io_service type for this type.
|
||||
typedef typename service_type::io_service_type io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef typename service_type::protocol_type protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename service_type::endpoint_type endpoint_type;
|
||||
|
||||
/// The type used for reporting errors.
|
||||
typedef asio::error error_type;
|
||||
|
||||
@ -68,23 +73,88 @@ public:
|
||||
|
||||
/// Construct a basic_stream_socket without opening it.
|
||||
/**
|
||||
* This constructor creates a stream socket without connecting it to a remote
|
||||
* peer. The socket needs to be connected or accepted before data can be sent
|
||||
* This constructor creates a stream socket without opening it. The socket
|
||||
* needs to be opened and then connected or accepted before data can be sent
|
||||
* or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*/
|
||||
explicit basic_stream_socket(io_service_type& io_service)
|
||||
: service_(io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_.null())
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct and open a basic_stream_socket.
|
||||
/**
|
||||
* This constructor creates and opens a stream socket. The socket needs to be
|
||||
* connected or accepted before data can be sent or received on it.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(io_service_type& io_service,
|
||||
const protocol_type& protocol)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket, opening it and binding it to the given
|
||||
/// local endpoint.
|
||||
/**
|
||||
* This constructor creates a stream socket and automatically opens it bound
|
||||
* to the specified endpoint on the local machine. The protocol used is the
|
||||
* protocol associated with the given endpoint.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param endpoint An endpoint on the local machine to which the stream
|
||||
* socket will be bound.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(io_service_type& io_service,
|
||||
const endpoint_type& endpoint)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(service_->null())
|
||||
{
|
||||
service_->open(impl_, endpoint.protocol(), throw_error());
|
||||
close_on_block_exit auto_close(service_, impl_);
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
auto_close.cancel();
|
||||
}
|
||||
|
||||
/// Construct a basic_stream_socket on an existing implementation.
|
||||
/**
|
||||
* This constructor creates a stream socket to hold an existing
|
||||
* implementation.
|
||||
*
|
||||
* @param io_service The io_service object that the stream socket will use to
|
||||
* dispatch handlers for any asynchronous operations performed on the socket.
|
||||
*
|
||||
* @param impl The new underlying socket implementation.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*/
|
||||
basic_stream_socket(io_service_type& io_service, impl_type impl)
|
||||
: service_(&io_service.get_service(service_factory<Service>())),
|
||||
impl_(impl)
|
||||
{
|
||||
service_->assign(impl_, impl);
|
||||
}
|
||||
|
||||
/// Destructor.
|
||||
~basic_stream_socket()
|
||||
{
|
||||
service_.close(impl_, ignore_error());
|
||||
service_->close(impl_, ignore_error());
|
||||
}
|
||||
|
||||
/// Get the io_service associated with the object.
|
||||
@ -97,7 +167,7 @@ public:
|
||||
*/
|
||||
io_service_type& io_service()
|
||||
{
|
||||
return service_.io_service();
|
||||
return service_->io_service();
|
||||
}
|
||||
|
||||
/// Open the socket using the specified protocol.
|
||||
@ -105,7 +175,7 @@ public:
|
||||
* This function opens the stream socket so that it will use the specified
|
||||
* protocol.
|
||||
*
|
||||
* @param protocol An object specifying which protocol is to be used.
|
||||
* @param protocol An object specifying protocol parameters to be used.
|
||||
*
|
||||
* @throws asio::error Thrown on failure.
|
||||
*
|
||||
@ -115,10 +185,9 @@ public:
|
||||
* socket.open(asio::ipv4::tcp());
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol>
|
||||
void open(const Protocol& protocol)
|
||||
void open(const protocol_type& protocol = protocol_type())
|
||||
{
|
||||
service_.open(impl_, protocol, throw_error());
|
||||
service_->open(impl_, protocol, throw_error());
|
||||
}
|
||||
|
||||
/// Open the socket using the specified protocol.
|
||||
@ -146,10 +215,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(const Protocol& protocol, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void open(const protocol_type& protocol, Error_Handler error_handler)
|
||||
{
|
||||
service_.open(impl_, protocol, error_handler);
|
||||
service_->open(impl_, protocol, error_handler);
|
||||
}
|
||||
|
||||
/// Close the socket.
|
||||
@ -161,7 +230,7 @@ public:
|
||||
*/
|
||||
void close()
|
||||
{
|
||||
service_.close(impl_, throw_error());
|
||||
service_->close(impl_, throw_error());
|
||||
}
|
||||
|
||||
/// Close the socket.
|
||||
@ -191,7 +260,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void close(Error_Handler error_handler)
|
||||
{
|
||||
service_.close(impl_, error_handler);
|
||||
service_->close(impl_, error_handler);
|
||||
}
|
||||
|
||||
/// Get a reference to the lowest layer.
|
||||
@ -219,18 +288,6 @@ public:
|
||||
return impl_;
|
||||
}
|
||||
|
||||
/// Set the underlying implementation in the native type.
|
||||
/**
|
||||
* This function is used by the acceptor implementation to set the underlying
|
||||
* implementation associated with the stream socket.
|
||||
*
|
||||
* @param new_impl The new underlying socket implementation.
|
||||
*/
|
||||
void set_impl(impl_type new_impl)
|
||||
{
|
||||
service_.assign(impl_, new_impl);
|
||||
}
|
||||
|
||||
/// Bind the socket to the given local endpoint.
|
||||
/**
|
||||
* This function binds the stream socket to the specified endpoint on the
|
||||
@ -248,10 +305,9 @@ public:
|
||||
* socket.bind(asio::ipv4::tcp::endpoint(12345));
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void bind(const Endpoint& endpoint)
|
||||
void bind(const endpoint_type& endpoint)
|
||||
{
|
||||
service_.bind(impl_, endpoint, throw_error());
|
||||
service_->bind(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Bind the socket to the given local endpoint.
|
||||
@ -282,10 +338,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(const Endpoint& endpoint, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void bind(const endpoint_type& endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_.bind(impl_, endpoint, error_handler);
|
||||
service_->bind(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Connect a stream socket to the specified endpoint.
|
||||
@ -310,10 +366,9 @@ public:
|
||||
* socket.connect(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void connect(const Endpoint& peer_endpoint)
|
||||
void connect(const endpoint_type& peer_endpoint)
|
||||
{
|
||||
service_.connect(impl_, peer_endpoint, throw_error());
|
||||
service_->connect(impl_, peer_endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Connect a stream socket to the specified endpoint.
|
||||
@ -348,10 +403,10 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void connect(const Endpoint& peer_endpoint, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void connect(const endpoint_type& peer_endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_.connect(impl_, peer_endpoint, error_handler);
|
||||
service_->connect(impl_, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
@ -394,10 +449,10 @@ public:
|
||||
* socket.async_connect(endpoint, connect_handler);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_connect(const Endpoint& peer_endpoint, Handler handler)
|
||||
template <typename Handler>
|
||||
void async_connect(const endpoint_type& peer_endpoint, Handler handler)
|
||||
{
|
||||
service_.async_connect(impl_, peer_endpoint, handler);
|
||||
service_->async_connect(impl_, peer_endpoint, handler);
|
||||
}
|
||||
|
||||
/// Set an option on the socket.
|
||||
@ -429,7 +484,7 @@ public:
|
||||
template <typename Socket_Option>
|
||||
void set_option(const Socket_Option& option)
|
||||
{
|
||||
service_.set_option(impl_, option, throw_error());
|
||||
service_->set_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Set an option on the socket.
|
||||
@ -471,7 +526,7 @@ public:
|
||||
template <typename Socket_Option, typename Error_Handler>
|
||||
void set_option(const Socket_Option& option, Error_Handler error_handler)
|
||||
{
|
||||
service_.set_option(impl_, option, error_handler);
|
||||
service_->set_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Get an option from the socket.
|
||||
@ -504,7 +559,7 @@ public:
|
||||
template <typename Socket_Option>
|
||||
void get_option(Socket_Option& option) const
|
||||
{
|
||||
service_.get_option(impl_, option, throw_error());
|
||||
service_->get_option(impl_, option, throw_error());
|
||||
}
|
||||
|
||||
/// Get an option from the socket.
|
||||
@ -547,7 +602,7 @@ public:
|
||||
template <typename Socket_Option, typename Error_Handler>
|
||||
void get_option(Socket_Option& option, Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_option(impl_, option, error_handler);
|
||||
service_->get_option(impl_, option, error_handler);
|
||||
}
|
||||
|
||||
/// Perform an IO control command on the socket.
|
||||
@ -575,7 +630,7 @@ public:
|
||||
template <typename IO_Control_Command>
|
||||
void io_control(IO_Control_Command& command)
|
||||
{
|
||||
service_.io_control(impl_, command, throw_error());
|
||||
service_->io_control(impl_, command, throw_error());
|
||||
}
|
||||
|
||||
/// Perform an IO control command on the socket.
|
||||
@ -613,7 +668,7 @@ public:
|
||||
template <typename IO_Control_Command, typename Error_Handler>
|
||||
void io_control(IO_Control_Command& command, Error_Handler error_handler)
|
||||
{
|
||||
service_.io_control(impl_, command, error_handler);
|
||||
service_->io_control(impl_, command, error_handler);
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the socket.
|
||||
@ -633,10 +688,9 @@ public:
|
||||
* socket.get_local_endpoint(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void get_local_endpoint(Endpoint& endpoint) const
|
||||
void get_local_endpoint(endpoint_type& endpoint) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, throw_error());
|
||||
service_->get_local_endpoint(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Get the local endpoint of the socket.
|
||||
@ -666,11 +720,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_local_endpoint(impl_, endpoint, error_handler);
|
||||
service_->get_local_endpoint(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Get the remote endpoint of the socket.
|
||||
@ -690,10 +744,9 @@ public:
|
||||
* socket.get_remote_endpoint(endpoint);
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint>
|
||||
void get_remote_endpoint(Endpoint& endpoint) const
|
||||
void get_remote_endpoint(endpoint_type& endpoint) const
|
||||
{
|
||||
service_.get_remote_endpoint(impl_, endpoint, throw_error());
|
||||
service_->get_remote_endpoint(impl_, endpoint, throw_error());
|
||||
}
|
||||
|
||||
/// Get the remote endpoint of the socket.
|
||||
@ -723,11 +776,11 @@ public:
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_remote_endpoint(Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_remote_endpoint(endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_.get_remote_endpoint(impl_, endpoint, error_handler);
|
||||
service_->get_remote_endpoint(impl_, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Disable sends or receives on the socket.
|
||||
@ -749,7 +802,7 @@ public:
|
||||
*/
|
||||
void shutdown(shutdown_type what)
|
||||
{
|
||||
service_.shutdown(impl_, what, throw_error());
|
||||
service_->shutdown(impl_, what, throw_error());
|
||||
}
|
||||
|
||||
/// Disable sends or receives on the socket.
|
||||
@ -783,7 +836,7 @@ public:
|
||||
template <typename Error_Handler>
|
||||
void shutdown(shutdown_type what, Error_Handler error_handler)
|
||||
{
|
||||
service_.shutdown(impl_, what, error_handler);
|
||||
service_->shutdown(impl_, what, error_handler);
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
@ -816,7 +869,7 @@ public:
|
||||
template <typename Const_Buffers>
|
||||
std::size_t send(const Const_Buffers& buffers, message_flags flags)
|
||||
{
|
||||
return service_.send(impl_, buffers, flags, throw_error());
|
||||
return service_->send(impl_, buffers, flags, throw_error());
|
||||
}
|
||||
|
||||
/// Send some data on the socket.
|
||||
@ -847,7 +900,7 @@ public:
|
||||
std::size_t send(const Const_Buffers& buffers, message_flags flags,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.send(impl_, buffers, flags, error_handler);
|
||||
return service_->send(impl_, buffers, flags, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
@ -891,7 +944,7 @@ public:
|
||||
void async_send(const Const_Buffers& buffers, message_flags flags,
|
||||
Handler handler)
|
||||
{
|
||||
service_.async_send(impl_, buffers, flags, handler);
|
||||
service_->async_send(impl_, buffers, flags, handler);
|
||||
}
|
||||
|
||||
/// Receive some data on the socket.
|
||||
@ -927,7 +980,7 @@ public:
|
||||
template <typename Mutable_Buffers>
|
||||
std::size_t receive(const Mutable_Buffers& buffers, message_flags flags)
|
||||
{
|
||||
return service_.receive(impl_, buffers, flags, throw_error());
|
||||
return service_->receive(impl_, buffers, flags, throw_error());
|
||||
}
|
||||
|
||||
/// Receive some data on a connected socket.
|
||||
@ -958,7 +1011,7 @@ public:
|
||||
std::size_t receive(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive(impl_, buffers, flags, error_handler);
|
||||
return service_->receive(impl_, buffers, flags, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive.
|
||||
@ -1004,7 +1057,7 @@ public:
|
||||
void async_receive(const Mutable_Buffers& buffers, message_flags flags,
|
||||
Handler handler)
|
||||
{
|
||||
service_.async_receive(impl_, buffers, flags, handler);
|
||||
service_->async_receive(impl_, buffers, flags, handler);
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
@ -1037,7 +1090,7 @@ public:
|
||||
template <typename Const_Buffers>
|
||||
std::size_t write_some(const Const_Buffers& buffers)
|
||||
{
|
||||
return service_.send(impl_, buffers, 0, throw_error());
|
||||
return service_->send(impl_, buffers, 0, throw_error());
|
||||
}
|
||||
|
||||
/// Write some data to the socket.
|
||||
@ -1066,7 +1119,7 @@ public:
|
||||
std::size_t write_some(const Const_Buffers& buffers,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.send(impl_, buffers, 0, error_handler);
|
||||
return service_->send(impl_, buffers, 0, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous write.
|
||||
@ -1107,7 +1160,7 @@ public:
|
||||
template <typename Const_Buffers, typename Handler>
|
||||
void async_write_some(const Const_Buffers& buffers, Handler handler)
|
||||
{
|
||||
service_.async_send(impl_, buffers, 0, handler);
|
||||
service_->async_send(impl_, buffers, 0, handler);
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
@ -1141,7 +1194,7 @@ public:
|
||||
template <typename Mutable_Buffers>
|
||||
std::size_t read_some(const Mutable_Buffers& buffers)
|
||||
{
|
||||
return service_.receive(impl_, buffers, 0, throw_error());
|
||||
return service_->receive(impl_, buffers, 0, throw_error());
|
||||
}
|
||||
|
||||
/// Read some data from the socket.
|
||||
@ -1171,7 +1224,7 @@ public:
|
||||
std::size_t read_some(const Mutable_Buffers& buffers,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive(impl_, buffers, 0, error_handler);
|
||||
return service_->receive(impl_, buffers, 0, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous read.
|
||||
@ -1213,7 +1266,7 @@ public:
|
||||
template <typename Mutable_Buffers, typename Handler>
|
||||
void async_read_some(const Mutable_Buffers& buffers, Handler handler)
|
||||
{
|
||||
service_.async_receive(impl_, buffers, 0, handler);
|
||||
service_->async_receive(impl_, buffers, 0, handler);
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream socket.
|
||||
@ -1239,7 +1292,7 @@ public:
|
||||
template <typename Mutable_Buffers>
|
||||
std::size_t peek(const Mutable_Buffers& buffers)
|
||||
{
|
||||
return service_.receive(impl_, buffers, message_peek, throw_error());
|
||||
return service_->receive(impl_, buffers, message_peek, throw_error());
|
||||
}
|
||||
|
||||
/// Peek at the incoming data on the stream socket.
|
||||
@ -1263,7 +1316,7 @@ public:
|
||||
template <typename Mutable_Buffers, typename Error_Handler>
|
||||
std::size_t peek(const Mutable_Buffers& buffers, Error_Handler error_handler)
|
||||
{
|
||||
return service_.receive(impl_, buffers, message_peek, error_handler);
|
||||
return service_->receive(impl_, buffers, message_peek, error_handler);
|
||||
}
|
||||
|
||||
/// Determine the amount of data that may be read without blocking.
|
||||
@ -1278,7 +1331,7 @@ public:
|
||||
std::size_t in_avail()
|
||||
{
|
||||
bytes_readable command;
|
||||
service_.io_control(impl_, command, throw_error());
|
||||
service_->io_control(impl_, command, throw_error());
|
||||
return command.get();
|
||||
}
|
||||
|
||||
@ -1300,18 +1353,60 @@ public:
|
||||
std::size_t in_avail(Error_Handler error_handler)
|
||||
{
|
||||
bytes_readable command;
|
||||
service_.io_control(impl_, command, error_handler);
|
||||
service_->io_control(impl_, command, error_handler);
|
||||
return command.get();
|
||||
}
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
void swap(basic_stream_socket<Service>& other)
|
||||
{
|
||||
std::swap(service_, other.service_);
|
||||
std::swap(impl_, other.impl_);
|
||||
}
|
||||
|
||||
private:
|
||||
/// The backend service implementation.
|
||||
service_type& service_;
|
||||
service_type* service_;
|
||||
|
||||
/// The underlying native implementation.
|
||||
impl_type impl_;
|
||||
|
||||
// Helper class to automatically close the implementation on block exit.
|
||||
class close_on_block_exit
|
||||
{
|
||||
public:
|
||||
close_on_block_exit(service_type* service, impl_type& impl)
|
||||
: service_(service), impl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
~close_on_block_exit()
|
||||
{
|
||||
if (service_)
|
||||
{
|
||||
service_->close(impl_, ignore_error());
|
||||
}
|
||||
}
|
||||
|
||||
void cancel()
|
||||
{
|
||||
service_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
service_type* service_;
|
||||
impl_type& impl_;
|
||||
};
|
||||
};
|
||||
|
||||
/// Swap implementation of socket with another.
|
||||
template <typename Service>
|
||||
inline void swap(basic_stream_socket<Service>& a,
|
||||
basic_stream_socket<Service>& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// datagram_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_DATAGRAM_SOCKET_HPP
|
||||
#define ASIO_DATAGRAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/basic_datagram_socket.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Typedef for the typical usage of datagram_socket.
|
||||
typedef basic_datagram_socket<datagram_socket_service<> > datagram_socket;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_DATAGRAM_SOCKET_HPP
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <boost/config.hpp>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
@ -34,7 +33,7 @@
|
||||
namespace asio {
|
||||
|
||||
/// Default service implementation for a datagram socket.
|
||||
template <typename Allocator = std::allocator<void> >
|
||||
template <typename Protocol, typename Allocator>
|
||||
class datagram_socket_service
|
||||
: private noncopyable
|
||||
{
|
||||
@ -42,6 +41,12 @@ public:
|
||||
/// The io_service type.
|
||||
typedef basic_io_service<Allocator> io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
private:
|
||||
// The type of the platform-specific implementation.
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
@ -85,8 +90,8 @@ public:
|
||||
}
|
||||
|
||||
// Open a new datagram socket implementation.
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(impl_type& impl, const Protocol& protocol,
|
||||
template <typename Error_Handler>
|
||||
void open(impl_type& impl, const protocol_type& protocol,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
if (protocol.type() == SOCK_DGRAM)
|
||||
@ -109,24 +114,24 @@ public:
|
||||
}
|
||||
|
||||
// Bind the datagram socket to the specified local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(impl_type& impl, const Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void bind(impl_type& impl, const endpoint_type& endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.bind(impl, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Connect the datagram socket to the specified endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Error_Handler>
|
||||
void connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.connect(impl, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Handler>
|
||||
void async_connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_connect(impl, peer_endpoint, handler);
|
||||
@ -157,16 +162,16 @@ public:
|
||||
}
|
||||
|
||||
/// Get the local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_impl_.get_local_endpoint(impl, endpoint, error_handler);
|
||||
}
|
||||
|
||||
// Get the remote endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_impl_.get_remote_endpoint(impl, endpoint, error_handler);
|
||||
@ -197,9 +202,9 @@ public:
|
||||
}
|
||||
|
||||
/// Send a datagram to the specified endpoint.
|
||||
template <typename Const_Buffers, typename Endpoint, typename Error_Handler>
|
||||
template <typename Const_Buffers, typename Error_Handler>
|
||||
std::size_t send_to(impl_type& impl, const Const_Buffers& buffers,
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
socket_base::message_flags flags, const endpoint_type& destination,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_impl_.send_to(impl, buffers, flags, destination,
|
||||
@ -207,9 +212,9 @@ public:
|
||||
}
|
||||
|
||||
/// Start an asynchronous send.
|
||||
template <typename Const_Buffers, typename Endpoint, typename Handler>
|
||||
template <typename Const_Buffers, typename Handler>
|
||||
void async_send_to(impl_type& impl, const Const_Buffers& buffers,
|
||||
socket_base::message_flags flags, const Endpoint& destination,
|
||||
socket_base::message_flags flags, const endpoint_type& destination,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_send_to(impl, buffers, flags, destination, handler);
|
||||
@ -232,9 +237,9 @@ public:
|
||||
}
|
||||
|
||||
/// Receive a datagram with the endpoint of the sender.
|
||||
template <typename Mutable_Buffers, typename Endpoint, typename Error_Handler>
|
||||
template <typename Mutable_Buffers, typename Error_Handler>
|
||||
std::size_t receive_from(impl_type& impl, const Mutable_Buffers& buffers,
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
socket_base::message_flags flags, endpoint_type& sender_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
return service_impl_.receive_from(impl, buffers, flags, sender_endpoint,
|
||||
@ -242,9 +247,9 @@ public:
|
||||
}
|
||||
|
||||
/// Start an asynchronous receive that will get the endpoint of the sender.
|
||||
template <typename Mutable_Buffers, typename Endpoint, typename Handler>
|
||||
template <typename Mutable_Buffers, typename Handler>
|
||||
void async_receive_from(impl_type& impl, const Mutable_Buffers& buffers,
|
||||
socket_base::message_flags flags, Endpoint& sender_endpoint,
|
||||
socket_base::message_flags flags, endpoint_type& sender_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_receive_from(impl, buffers, flags, sender_endpoint,
|
||||
|
@ -920,7 +920,8 @@ public:
|
||||
if (new_socket >= 0)
|
||||
{
|
||||
impl_type new_impl(new_socket);
|
||||
peer.set_impl(new_impl);
|
||||
Socket tmp(peer.io_service(), new_impl);
|
||||
tmp.swap(peer);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -975,7 +976,8 @@ public:
|
||||
{
|
||||
peer_endpoint.size(addr_len);
|
||||
impl_type new_impl(new_socket);
|
||||
peer.set_impl(new_impl);
|
||||
Socket tmp(peer.io_service(), new_impl);
|
||||
tmp.swap(peer);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1033,7 +1035,8 @@ public:
|
||||
return false;
|
||||
|
||||
impl_type new_impl(new_socket);
|
||||
peer_.set_impl(new_impl);
|
||||
Socket tmp(peer_.io_service(), new_impl);
|
||||
tmp.swap(peer_);
|
||||
io_service_.post(bind_handler(handler_, error));
|
||||
return true;
|
||||
}
|
||||
@ -1120,7 +1123,8 @@ public:
|
||||
|
||||
peer_endpoint_.size(addr_len);
|
||||
impl_type new_impl(new_socket);
|
||||
peer_.set_impl(new_impl);
|
||||
Socket tmp(peer_.io_service(), new_impl);
|
||||
tmp.swap(peer_);
|
||||
io_service_.post(bind_handler(handler_, error));
|
||||
return true;
|
||||
}
|
||||
|
@ -23,9 +23,14 @@
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# include <iostream>
|
||||
#endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#include <memory>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/basic_socket_acceptor.hpp"
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/socket_acceptor_service.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
#include "asio/ipv4/address.hpp"
|
||||
#include "asio/detail/socket_ops.hpp"
|
||||
#include "asio/detail/socket_option.hpp"
|
||||
@ -68,6 +73,29 @@ public:
|
||||
return PF_INET;
|
||||
}
|
||||
|
||||
/// Template typedefs for acceptor and socket types.
|
||||
template <typename Allocator>
|
||||
struct types
|
||||
{
|
||||
/// The service type for IPv4 TCP sockets.
|
||||
typedef stream_socket_service<tcp, Allocator> socket_service;
|
||||
|
||||
/// The IPv4 TCP socket type.
|
||||
typedef basic_stream_socket<socket_service> socket;
|
||||
|
||||
/// The service type for IPv4 TCP acceptors.
|
||||
typedef socket_acceptor_service<tcp, socket, Allocator> acceptor_service;
|
||||
|
||||
/// The IPv4 TCP acceptor type.
|
||||
typedef basic_socket_acceptor<acceptor_service> acceptor;
|
||||
};
|
||||
|
||||
/// The IPv4 TCP socket type.
|
||||
typedef types<std::allocator<void> >::socket socket;
|
||||
|
||||
/// The IPv4 TCP acceptor type.
|
||||
typedef types<std::allocator<void> >::acceptor acceptor;
|
||||
|
||||
/// Socket option for disabling the Nagle algorithm.
|
||||
/**
|
||||
* Implements the IPPROTO_TCP/TCP_NODELAY socket option.
|
||||
|
@ -23,8 +23,11 @@
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
# include <iostream>
|
||||
#endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#include <memory>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/basic_datagram_socket.hpp"
|
||||
#include "asio/datagram_socket_service.hpp"
|
||||
#include "asio/error.hpp"
|
||||
#include "asio/ipv4/address.hpp"
|
||||
#include "asio/detail/socket_types.hpp"
|
||||
@ -66,6 +69,20 @@ public:
|
||||
{
|
||||
return PF_INET;
|
||||
}
|
||||
|
||||
/// Template typedefs for socket types.
|
||||
template <typename Allocator>
|
||||
struct types
|
||||
{
|
||||
/// The service type for IPv4 UDP sockets.
|
||||
typedef datagram_socket_service<udp, Allocator> socket_service;
|
||||
|
||||
/// The IPv4 UDP socket type.
|
||||
typedef basic_datagram_socket<socket_service> socket;
|
||||
};
|
||||
|
||||
/// The IPv4 UDP socket type.
|
||||
typedef types<std::allocator<void> >::socket socket;
|
||||
};
|
||||
|
||||
/// Describes an endpoint for a UDP socket.
|
||||
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// socket_acceptor.hpp
|
||||
// ~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_SOCKET_ACCEPTOR_HPP
|
||||
#define ASIO_SOCKET_ACCEPTOR_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/basic_socket_acceptor.hpp"
|
||||
#include "asio/socket_acceptor_service.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Typedef for the typical usage of socket_acceptor.
|
||||
typedef basic_socket_acceptor<socket_acceptor_service<> > socket_acceptor;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_SOCKET_ACCEPTOR_HPP
|
@ -17,10 +17,6 @@
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <memory>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#include "asio/basic_io_service.hpp"
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/detail/epoll_reactor.hpp"
|
||||
@ -33,7 +29,7 @@
|
||||
namespace asio {
|
||||
|
||||
/// Default service implementation for a socket acceptor.
|
||||
template <typename Allocator = std::allocator<void> >
|
||||
template <typename Protocol, typename Socket, typename Allocator>
|
||||
class socket_acceptor_service
|
||||
: private noncopyable
|
||||
{
|
||||
@ -41,6 +37,15 @@ public:
|
||||
/// The io_service type.
|
||||
typedef basic_io_service<Allocator> io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename protocol_type::endpoint endpoint_type;
|
||||
|
||||
/// The socket type to be accepted.
|
||||
typedef Socket socket_type;
|
||||
|
||||
private:
|
||||
// The type of the platform-specific implementation.
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
@ -84,16 +89,22 @@ public:
|
||||
}
|
||||
|
||||
/// Open a new socket acceptor implementation.
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(impl_type& impl, const Protocol& protocol,
|
||||
template <typename Error_Handler>
|
||||
void open(impl_type& impl, const protocol_type& protocol,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.open(impl, protocol, error_handler);
|
||||
}
|
||||
|
||||
/// Assign a new datagram socket implementation.
|
||||
void assign(impl_type& impl, impl_type new_impl)
|
||||
{
|
||||
service_impl_.assign(impl, new_impl);
|
||||
}
|
||||
|
||||
/// Bind the socket acceptor to the specified local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(impl_type& impl, const Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void bind(impl_type& impl, const endpoint_type& endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.bind(impl, endpoint, error_handler);
|
||||
@ -130,39 +141,39 @@ public:
|
||||
}
|
||||
|
||||
/// Get the local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_impl_.get_local_endpoint(impl, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Accept a new connection.
|
||||
template <typename Socket, typename Error_Handler>
|
||||
void accept(impl_type& impl, Socket& peer, Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void accept(impl_type& impl, socket_type& peer, Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.accept(impl, peer, error_handler);
|
||||
}
|
||||
|
||||
/// Accept a new connection.
|
||||
template <typename Socket, typename Endpoint, typename Error_Handler>
|
||||
void accept_endpoint(impl_type& impl, Socket& peer, Endpoint& peer_endpoint,
|
||||
Error_Handler error_handler)
|
||||
template <typename Error_Handler>
|
||||
void accept_endpoint(impl_type& impl, socket_type& peer,
|
||||
endpoint_type& peer_endpoint, Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.accept_endpoint(impl, peer, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous accept.
|
||||
template <typename Socket, typename Handler>
|
||||
void async_accept(impl_type& impl, Socket& peer, Handler handler)
|
||||
template <typename Handler>
|
||||
void async_accept(impl_type& impl, socket_type& peer, Handler handler)
|
||||
{
|
||||
service_impl_.async_accept(impl, peer, handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous accept.
|
||||
template <typename Socket, typename Endpoint, typename Handler>
|
||||
void async_accept_endpoint(impl_type& impl, Socket& peer,
|
||||
Endpoint& peer_endpoint, Handler handler)
|
||||
template <typename Handler>
|
||||
void async_accept_endpoint(impl_type& impl, socket_type& peer,
|
||||
endpoint_type& peer_endpoint, Handler handler)
|
||||
{
|
||||
service_impl_.async_accept_endpoint(impl, peer, peer_endpoint, handler);
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// stream_socket.hpp
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef ASIO_STREAM_SOCKET_HPP
|
||||
#define ASIO_STREAM_SOCKET_HPP
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
# pragma once
|
||||
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
|
||||
#include "asio/basic_stream_socket.hpp"
|
||||
#include "asio/stream_socket_service.hpp"
|
||||
|
||||
namespace asio {
|
||||
|
||||
/// Typedef for the typical usage of stream_socket.
|
||||
typedef basic_stream_socket<stream_socket_service<> > stream_socket;
|
||||
|
||||
} // namespace asio
|
||||
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
#endif // ASIO_STREAM_SOCKET_HPP
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "asio/detail/push_options.hpp"
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <boost/config.hpp>
|
||||
#include "asio/detail/pop_options.hpp"
|
||||
|
||||
@ -34,7 +33,7 @@
|
||||
namespace asio {
|
||||
|
||||
/// Default service implementation for a stream socket.
|
||||
template <typename Allocator = std::allocator<void> >
|
||||
template <typename Protocol, typename Allocator>
|
||||
class stream_socket_service
|
||||
: private noncopyable
|
||||
{
|
||||
@ -42,6 +41,12 @@ public:
|
||||
/// The io_service type.
|
||||
typedef basic_io_service<Allocator> io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
private:
|
||||
// The type of the platform-specific implementation.
|
||||
#if defined(ASIO_HAS_IOCP)
|
||||
@ -81,12 +86,12 @@ public:
|
||||
/// Return a null stream socket implementation.
|
||||
impl_type null() const
|
||||
{
|
||||
return service_impl_.null();
|
||||
return service_impl_type::null();
|
||||
}
|
||||
|
||||
/// Open a new stream socket implementation.
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(impl_type& impl, const Protocol& protocol,
|
||||
template <typename Error_Handler>
|
||||
void open(impl_type& impl, const protocol_type& protocol,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
if (protocol.type() == SOCK_STREAM)
|
||||
@ -109,24 +114,24 @@ public:
|
||||
}
|
||||
|
||||
/// Bind the stream socket to the specified local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(impl_type& impl, const Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void bind(impl_type& impl, const endpoint_type& endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.bind(impl, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Connect the stream socket to the specified endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Error_Handler>
|
||||
void connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
service_impl_.connect(impl, peer_endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Handler>
|
||||
void async_connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
service_impl_.async_connect(impl, peer_endpoint, handler);
|
||||
@ -157,16 +162,16 @@ public:
|
||||
}
|
||||
|
||||
/// Get the local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_impl_.get_local_endpoint(impl, endpoint, error_handler);
|
||||
}
|
||||
|
||||
/// Get the remote endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
service_impl_.get_remote_endpoint(impl, endpoint, error_handler);
|
||||
|
@ -17,7 +17,6 @@ noinst_PROGRAMS = \
|
||||
tests/unit/buffer_test \
|
||||
tests/unit/completion_condition_test \
|
||||
tests/unit/datagram_socket_service_test \
|
||||
tests/unit/datagram_socket_test \
|
||||
tests/unit/deadline_timer_service_test \
|
||||
tests/unit/deadline_timer_test \
|
||||
tests/unit/error_handler_test \
|
||||
@ -38,10 +37,8 @@ noinst_PROGRAMS = \
|
||||
tests/unit/read_test \
|
||||
tests/unit/service_factory_test \
|
||||
tests/unit/socket_acceptor_service_test \
|
||||
tests/unit/socket_acceptor_test \
|
||||
tests/unit/socket_base_test \
|
||||
tests/unit/stream_socket_service_test \
|
||||
tests/unit/stream_socket_test \
|
||||
tests/unit/thread_test \
|
||||
tests/unit/time_traits_test \
|
||||
tests/unit/write_test \
|
||||
@ -103,7 +100,6 @@ TESTS = \
|
||||
tests/unit/buffer_test \
|
||||
tests/unit/completion_condition_test \
|
||||
tests/unit/datagram_socket_service_test \
|
||||
tests/unit/datagram_socket_test \
|
||||
tests/unit/deadline_timer_service_test \
|
||||
tests/unit/deadline_timer_test \
|
||||
tests/unit/error_handler_test \
|
||||
@ -124,10 +120,8 @@ TESTS = \
|
||||
tests/unit/read_test \
|
||||
tests/unit/service_factory_test \
|
||||
tests/unit/socket_acceptor_service_test \
|
||||
tests/unit/socket_acceptor_test \
|
||||
tests/unit/socket_base_test \
|
||||
tests/unit/stream_socket_service_test \
|
||||
tests/unit/stream_socket_test \
|
||||
tests/unit/thread_test \
|
||||
tests/unit/time_traits_test \
|
||||
tests/unit/write_test
|
||||
@ -169,8 +163,6 @@ tests_unit_ipv4_tcp_test_SOURCES = tests/unit/ipv4/tcp_test.cpp
|
||||
tests_unit_ipv4_udp_test_SOURCES = tests/unit/ipv4/udp_test.cpp
|
||||
tests_unit_locking_dispatcher_test_SOURCES = tests/unit/locking_dispatcher_test.cpp
|
||||
tests_unit_is_read_buffered_test_SOURCES = tests/unit/is_read_buffered_test.cpp
|
||||
tests_unit_socket_acceptor_test_SOURCES = tests/unit/socket_acceptor_test.cpp
|
||||
tests_unit_datagram_socket_test_SOURCES = tests/unit/datagram_socket_test.cpp
|
||||
tests_unit_read_test_SOURCES = tests/unit/read_test.cpp
|
||||
tests_unit_write_test_SOURCES = tests/unit/write_test.cpp
|
||||
tests_unit_is_write_buffered_test_SOURCES = tests/unit/is_write_buffered_test.cpp
|
||||
@ -195,7 +187,6 @@ tests_unit_service_factory_test_SOURCES = tests/unit/service_factory_test.cpp
|
||||
tests_unit_socket_acceptor_service_test_SOURCES = tests/unit/socket_acceptor_service_test.cpp
|
||||
tests_unit_socket_base_test_SOURCES = tests/unit/socket_base_test.cpp
|
||||
tests_unit_stream_socket_service_test_SOURCES = tests/unit/stream_socket_service_test.cpp
|
||||
tests_unit_stream_socket_test_SOURCES = tests/unit/stream_socket_test.cpp
|
||||
tests_unit_thread_test_SOURCES = tests/unit/thread_test.cpp
|
||||
tests_unit_time_traits_test_SOURCES = tests/unit/time_traits_test.cpp
|
||||
examples_chat_chat_client_SOURCES = examples/chat/chat_client.cpp
|
||||
|
@ -59,7 +59,6 @@ Standard exception class.
|
||||
<H2>Classes</H2>
|
||||
|
||||
\li boost::asio::const_buffer
|
||||
\li boost::asio::datagram_socket
|
||||
\li boost::asio::deadline_timer
|
||||
\li boost::asio::error
|
||||
\li boost::asio::io_service
|
||||
@ -67,14 +66,15 @@ Standard exception class.
|
||||
\li boost::asio::ipv4::host
|
||||
\li boost::asio::ipv4::host_resolver
|
||||
\li boost::asio::ipv4::tcp
|
||||
\li boost::asio::ipv4::tcp::acceptor
|
||||
\li boost::asio::ipv4::tcp::endpoint
|
||||
\li boost::asio::ipv4::tcp::socket
|
||||
\li boost::asio::ipv4::udp
|
||||
\li boost::asio::ipv4::udp::endpoint
|
||||
\li boost::asio::ipv4::udp::socket
|
||||
\li boost::asio::locking_dispatcher
|
||||
\li boost::asio::mutable_buffer
|
||||
\li boost::asio::socket_acceptor
|
||||
\li boost::asio::socket_base
|
||||
\li boost::asio::stream_socket
|
||||
\li boost::asio::ssl::context
|
||||
\li boost::asio::ssl::context_base
|
||||
\li boost::asio::ssl::stream_base
|
||||
|
@ -59,7 +59,6 @@ Standard exception class.
|
||||
<H2>Classes</H2>
|
||||
|
||||
\li asio::const_buffer
|
||||
\li asio::datagram_socket
|
||||
\li asio::deadline_timer
|
||||
\li asio::error
|
||||
\li asio::io_service
|
||||
@ -67,14 +66,15 @@ Standard exception class.
|
||||
\li asio::ipv4::host
|
||||
\li asio::ipv4::host_resolver
|
||||
\li asio::ipv4::tcp
|
||||
\li asio::ipv4::tcp::acceptor
|
||||
\li asio::ipv4::tcp::endpoint
|
||||
\li asio::ipv4::tcp::socket
|
||||
\li asio::ipv4::udp
|
||||
\li asio::ipv4::udp::endpoint
|
||||
\li asio::ipv4::udp::socket
|
||||
\li asio::locking_dispatcher
|
||||
\li asio::mutable_buffer
|
||||
\li asio::socket_acceptor
|
||||
\li asio::socket_base
|
||||
\li asio::stream_socket
|
||||
\li asio::ssl::context
|
||||
\li asio::ssl::context_base
|
||||
\li asio::ssl::stream_base
|
||||
|
@ -116,7 +116,7 @@ private:
|
||||
|
||||
private:
|
||||
asio::io_service& io_service_;
|
||||
asio::stream_socket socket_;
|
||||
asio::ipv4::tcp::socket socket_;
|
||||
chat_message read_msg_;
|
||||
chat_message_queue write_msgs_;
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
asio::stream_socket& socket()
|
||||
asio::ipv4::tcp::socket& socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
@ -152,7 +152,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::stream_socket socket_;
|
||||
asio::ipv4::tcp::socket socket_;
|
||||
chat_room& room_;
|
||||
chat_message read_msg_;
|
||||
chat_message_queue write_msgs_;
|
||||
@ -196,7 +196,7 @@ public:
|
||||
|
||||
private:
|
||||
asio::io_service& io_service_;
|
||||
asio::socket_acceptor acceptor_;
|
||||
asio::ipv4::tcp::acceptor acceptor_;
|
||||
chat_room room_;
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
asio::stream_socket& socket()
|
||||
asio::ipv4::tcp::socket& socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::stream_socket socket_;
|
||||
asio::ipv4::tcp::socket socket_;
|
||||
enum { max_length = 1024 };
|
||||
char data_[max_length];
|
||||
};
|
||||
@ -97,7 +97,7 @@ public:
|
||||
|
||||
private:
|
||||
asio::io_service& io_service_;
|
||||
asio::socket_acceptor acceptor_;
|
||||
asio::ipv4::tcp::acceptor acceptor_;
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
|
||||
private:
|
||||
asio::io_service& io_service_;
|
||||
asio::datagram_socket socket_;
|
||||
asio::ipv4::udp::socket socket_;
|
||||
asio::ipv4::udp::endpoint sender_endpoint_;
|
||||
enum { max_length = 1024 };
|
||||
char data_[max_length];
|
||||
|
@ -23,7 +23,7 @@ int main(int argc, char* argv[])
|
||||
hr.get_host_by_name(h, argv[1]);
|
||||
asio::ipv4::tcp::endpoint ep(atoi(argv[2]), h.address(0));
|
||||
|
||||
asio::stream_socket s(io_service);
|
||||
asio::ipv4::tcp::socket s(io_service);
|
||||
s.connect(ep);
|
||||
|
||||
std::cout << "Enter message: ";
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
const int max_length = 1024;
|
||||
|
||||
typedef boost::shared_ptr<asio::stream_socket> stream_socket_ptr;
|
||||
typedef boost::shared_ptr<asio::ipv4::tcp::socket> socket_ptr;
|
||||
|
||||
void session(stream_socket_ptr sock)
|
||||
void session(socket_ptr sock)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -39,11 +39,11 @@ void session(stream_socket_ptr sock)
|
||||
|
||||
void server(asio::io_service& io_service, short port)
|
||||
{
|
||||
asio::socket_acceptor a(io_service,
|
||||
asio::ipv4::tcp::acceptor a(io_service,
|
||||
asio::ipv4::tcp::endpoint(port));
|
||||
for (;;)
|
||||
{
|
||||
stream_socket_ptr sock(new asio::stream_socket(io_service));
|
||||
socket_ptr sock(new asio::ipv4::tcp::socket(io_service));
|
||||
asio::error error;
|
||||
a.accept(*sock, asio::assign_error(error));
|
||||
if (!error)
|
||||
|
@ -17,7 +17,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::datagram_socket s(io_service, asio::ipv4::udp::endpoint(0));
|
||||
asio::ipv4::udp::socket s(io_service,
|
||||
asio::ipv4::udp::endpoint(0));
|
||||
|
||||
asio::ipv4::host_resolver hr(io_service);
|
||||
asio::ipv4::host h;
|
||||
|
@ -6,7 +6,7 @@ enum { max_length = 1024 };
|
||||
|
||||
void server(asio::io_service& io_service, short port)
|
||||
{
|
||||
asio::datagram_socket sock(io_service,
|
||||
asio::ipv4::udp::socket sock(io_service,
|
||||
asio::ipv4::udp::endpoint(port));
|
||||
for (;;)
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ connection::connection(asio::io_service& io_service,
|
||||
{
|
||||
}
|
||||
|
||||
asio::stream_socket& connection::socket()
|
||||
asio::ipv4::tcp::socket& connection::socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
connection_manager& manager, request_handler& handler);
|
||||
|
||||
/// Get the socket associated with the connection.
|
||||
asio::stream_socket& socket();
|
||||
asio::ipv4::tcp::socket& socket();
|
||||
|
||||
/// Start the first asynchronous operation for the connection.
|
||||
void start();
|
||||
@ -43,7 +43,7 @@ private:
|
||||
void handle_write(const asio::error& e);
|
||||
|
||||
/// Socket for the connection.
|
||||
asio::stream_socket socket_;
|
||||
asio::ipv4::tcp::socket socket_;
|
||||
|
||||
/// The manager for this connection.
|
||||
connection_manager& connection_manager_;
|
||||
|
@ -15,7 +15,7 @@ server::server(short port, const std::string& doc_root)
|
||||
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
|
||||
asio::ipv4::tcp::endpoint endpoint(port);
|
||||
acceptor_.open(endpoint.protocol());
|
||||
acceptor_.set_option(asio::socket_acceptor::reuse_address(true));
|
||||
acceptor_.set_option(asio::ipv4::tcp::acceptor::reuse_address(true));
|
||||
acceptor_.bind(endpoint);
|
||||
acceptor_.listen();
|
||||
acceptor_.async_accept(new_connection_->socket(),
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
asio::io_service io_service_;
|
||||
|
||||
/// Acceptor used to listen for incoming connections.
|
||||
asio::socket_acceptor acceptor_;
|
||||
asio::ipv4::tcp::acceptor acceptor_;
|
||||
|
||||
/// The connection manager which owns all live connections.
|
||||
connection_manager connection_manager_;
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
// Constructor.
|
||||
socket_device(short port, const char* hostname)
|
||||
: io_service_(new asio::io_service),
|
||||
socket_(new asio::stream_socket(*io_service_))
|
||||
socket_(new asio::ipv4::tcp::socket(*io_service_))
|
||||
{
|
||||
asio::ipv4::host_resolver host_resolver(*io_service_);
|
||||
asio::ipv4::host host;
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
private:
|
||||
boost::shared_ptr<asio::io_service> io_service_;
|
||||
boost::shared_ptr<asio::stream_socket> socket_;
|
||||
boost::shared_ptr<asio::ipv4::tcp::socket> socket_;
|
||||
};
|
||||
|
||||
// Typedefs for iostreams types.
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
{
|
||||
// Create the socket so that multiple may be bound to the same address.
|
||||
socket_.open(asio::ipv4::udp());
|
||||
socket_.set_option(asio::datagram_socket::reuse_address(true));
|
||||
socket_.set_option(asio::ipv4::udp::socket::reuse_address(true));
|
||||
socket_.bind(asio::ipv4::udp::endpoint(multicast_port));
|
||||
|
||||
// Join the multicast group.
|
||||
@ -44,7 +44,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::datagram_socket socket_;
|
||||
asio::ipv4::udp::socket socket_;
|
||||
asio::ipv4::udp::endpoint sender_endpoint_;
|
||||
enum { max_length = 1024 };
|
||||
char data_[max_length];
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::datagram_socket socket_;
|
||||
asio::ipv4::udp::socket socket_;
|
||||
asio::deadline_timer timer_;
|
||||
int message_count_;
|
||||
std::string message_;
|
||||
|
@ -25,14 +25,14 @@ class connection
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
connection(asio::demuxer& demuxer)
|
||||
: socket_(demuxer)
|
||||
connection(asio::io_service& io_service)
|
||||
: socket_(io_service)
|
||||
{
|
||||
}
|
||||
|
||||
/// Get the underlying socket. Used for making a connection or for accepting
|
||||
/// an incoming connection.
|
||||
asio::stream_socket& socket()
|
||||
asio::ipv4::tcp::socket& socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public:
|
||||
{
|
||||
// Something went wrong, inform the caller.
|
||||
asio::error error(asio::error::invalid_argument);
|
||||
socket_.demuxer().post(boost::bind(handler, error));
|
||||
socket_.io_service().post(boost::bind(handler, error));
|
||||
return;
|
||||
}
|
||||
outbound_header_ = header_stream.str();
|
||||
@ -145,7 +145,7 @@ public:
|
||||
|
||||
private:
|
||||
/// The underlying socket.
|
||||
asio::stream_socket socket_;
|
||||
asio::ipv4::tcp::socket socket_;
|
||||
|
||||
/// The size of a fixed length header.
|
||||
enum { header_length = 8 };
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
|
||||
private:
|
||||
/// The acceptor object used to accept incoming socket connections.
|
||||
asio::socket_acceptor acceptor_;
|
||||
asio::ipv4::tcp::acceptor acceptor_;
|
||||
|
||||
/// The data to be sent to each client.
|
||||
std::vector<stock> stocks_;
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
/**
|
||||
* This constructor creates a logger.
|
||||
*
|
||||
* @param d The io_service object used to locate the logger service.
|
||||
* @param io_service The io_service object used to locate the logger service.
|
||||
*
|
||||
* @param identifier An identifier for this logger.
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "stream_socket_service.hpp"
|
||||
|
||||
typedef asio::basic_stream_socket<
|
||||
services::stream_socket_service<> > debug_stream_socket;
|
||||
services::stream_socket_service<asio::ipv4::tcp> > debug_stream_socket;
|
||||
|
||||
char read_buffer[1024];
|
||||
|
||||
|
@ -8,18 +8,25 @@
|
||||
namespace services {
|
||||
|
||||
/// Debugging stream socket service that wraps the normal stream socket service.
|
||||
template <typename Allocator = std::allocator<void> >
|
||||
template <typename Protocol, typename Allocator = std::allocator<void> >
|
||||
class stream_socket_service
|
||||
: private boost::noncopyable
|
||||
{
|
||||
private:
|
||||
/// The type of the wrapped stream socket service.
|
||||
typedef asio::stream_socket_service<Allocator> service_impl_type;
|
||||
typedef asio::stream_socket_service<
|
||||
Protocol, Allocator> service_impl_type;
|
||||
|
||||
public:
|
||||
/// The io_service type for this service.
|
||||
typedef asio::basic_io_service<Allocator> io_service_type;
|
||||
|
||||
/// The protocol type.
|
||||
typedef Protocol protocol_type;
|
||||
|
||||
/// The endpoint type.
|
||||
typedef typename Protocol::endpoint endpoint_type;
|
||||
|
||||
/// The type of a stream socket.
|
||||
typedef typename service_impl_type::impl_type impl_type;
|
||||
|
||||
@ -44,8 +51,8 @@ public:
|
||||
}
|
||||
|
||||
/// Open a new stream socket implementation.
|
||||
template <typename Protocol, typename Error_Handler>
|
||||
void open(impl_type& impl, const Protocol& protocol,
|
||||
template <typename Error_Handler>
|
||||
void open(impl_type& impl, const protocol_type& protocol,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
logger_.log("Opening new socket");
|
||||
@ -68,8 +75,8 @@ public:
|
||||
}
|
||||
|
||||
/// Bind the stream socket to the specified local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void bind(impl_type& impl, const Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void bind(impl_type& impl, const endpoint_type& endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
logger_.log("Binding socket");
|
||||
@ -77,8 +84,8 @@ public:
|
||||
}
|
||||
|
||||
/// Connect the stream socket to the specified endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Error_Handler>
|
||||
void connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Error_Handler error_handler)
|
||||
{
|
||||
logger_.log("Connecting socket");
|
||||
@ -118,8 +125,8 @@ public:
|
||||
};
|
||||
|
||||
/// Start an asynchronous connect.
|
||||
template <typename Endpoint, typename Handler>
|
||||
void async_connect(impl_type& impl, const Endpoint& peer_endpoint,
|
||||
template <typename Handler>
|
||||
void async_connect(impl_type& impl, const endpoint_type& peer_endpoint,
|
||||
Handler handler)
|
||||
{
|
||||
logger_.log("Starting asynchronous connect");
|
||||
@ -155,8 +162,8 @@ public:
|
||||
}
|
||||
|
||||
/// Get the local endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_local_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
logger_.log("Getting socket's local endpoint");
|
||||
@ -164,8 +171,8 @@ public:
|
||||
}
|
||||
|
||||
/// Get the remote endpoint.
|
||||
template <typename Endpoint, typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, Endpoint& endpoint,
|
||||
template <typename Error_Handler>
|
||||
void get_remote_endpoint(const impl_type& impl, endpoint_type& endpoint,
|
||||
Error_Handler error_handler) const
|
||||
{
|
||||
logger_.log("Getting socket's remote endpoint");
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::ssl::stream<asio::stream_socket> socket_;
|
||||
asio::ssl::stream<asio::ipv4::tcp::socket> socket_;
|
||||
char request_[max_length];
|
||||
char reply_[max_length];
|
||||
};
|
||||
|
@ -12,7 +12,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
asio::stream_socket& socket()
|
||||
asio::ipv4::tcp::socket& socket()
|
||||
{
|
||||
return socket_.lowest_layer();
|
||||
}
|
||||
@ -70,7 +70,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
asio::ssl::stream<asio::stream_socket> socket_;
|
||||
asio::ssl::stream<asio::ipv4::tcp::socket> socket_;
|
||||
enum { max_length = 1024 };
|
||||
char data_[max_length];
|
||||
};
|
||||
@ -121,7 +121,7 @@ public:
|
||||
|
||||
private:
|
||||
asio::io_service& io_service_;
|
||||
asio::socket_acceptor acceptor_;
|
||||
asio::ipv4::tcp::acceptor acceptor_;
|
||||
asio::ssl::context context_;
|
||||
};
|
||||
|
||||
|
@ -42,8 +42,8 @@ public:
|
||||
private:
|
||||
io_service& io_service_;
|
||||
deadline_timer timer_;
|
||||
socket_acceptor acceptor_;
|
||||
stream_socket socket_;
|
||||
ipv4::tcp::acceptor acceptor_;
|
||||
ipv4::tcp::socket socket_;
|
||||
};
|
||||
|
||||
int main()
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
private:
|
||||
io_service& io_service_;
|
||||
deadline_timer timer_;
|
||||
stream_socket socket_;
|
||||
ipv4::tcp::socket socket_;
|
||||
};
|
||||
|
||||
int main()
|
||||
@ -49,7 +49,7 @@ int main()
|
||||
try
|
||||
{
|
||||
io_service ios;
|
||||
socket_acceptor a(ios, ipv4::tcp::endpoint(32123), 1);
|
||||
ipv4::tcp::acceptor a(ios, ipv4::tcp::endpoint(32123), 1);
|
||||
|
||||
// Make lots of connections so that at least some of them will block.
|
||||
connect_handler ch1(ios);
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
private:
|
||||
io_service& io_service_;
|
||||
deadline_timer timer_;
|
||||
datagram_socket socket_;
|
||||
ipv4::udp::socket socket_;
|
||||
ipv4::udp::endpoint sender_endpoint_;
|
||||
enum { max_length = 512 };
|
||||
char data_[max_length];
|
||||
|
@ -57,8 +57,8 @@ public:
|
||||
private:
|
||||
io_service& io_service_;
|
||||
deadline_timer timer_;
|
||||
socket_acceptor acceptor_;
|
||||
stream_socket socket_;
|
||||
ipv4::tcp::acceptor acceptor_;
|
||||
ipv4::tcp::socket socket_;
|
||||
char buf_[1024];
|
||||
};
|
||||
|
||||
@ -75,7 +75,7 @@ int main()
|
||||
|
||||
stream_handler sh(ios);
|
||||
|
||||
stream_socket s(ios);
|
||||
ipv4::tcp::socket s(ios);
|
||||
s.async_connect(ipv4::tcp::endpoint(32123, ipv4::address::loopback()),
|
||||
boost::bind(connect_handler));
|
||||
|
||||
|
@ -18,7 +18,7 @@ int main(int argc, char* argv[])
|
||||
host_resolver.get_host_by_name(host, argv[1]);
|
||||
asio::ipv4::tcp::endpoint remote_endpoint(13, host.address(0));
|
||||
|
||||
asio::stream_socket socket(io_service);
|
||||
asio::ipv4::tcp::socket socket(io_service);
|
||||
socket.connect(remote_endpoint);
|
||||
|
||||
for (;;)
|
||||
|
@ -9,12 +9,12 @@ int main()
|
||||
{
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(13));
|
||||
|
||||
for (;;)
|
||||
{
|
||||
asio::stream_socket socket(io_service);
|
||||
asio::ipv4::tcp::socket socket(io_service);
|
||||
acceptor.accept(socket);
|
||||
|
||||
using namespace std; // For time_t, time and ctime.
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <asio.hpp>
|
||||
|
||||
void handle_write(asio::stream_socket* socket, char* write_buf,
|
||||
void handle_write(asio::ipv4::tcp::socket* socket, char* write_buf,
|
||||
const asio::error& /*error*/, size_t /*bytes_transferred*/)
|
||||
{
|
||||
using namespace std; // For free.
|
||||
@ -11,8 +11,8 @@ void handle_write(asio::stream_socket* socket, char* write_buf,
|
||||
delete socket;
|
||||
}
|
||||
|
||||
void handle_accept(asio::socket_acceptor* acceptor,
|
||||
asio::stream_socket* socket, const asio::error& error)
|
||||
void handle_accept(asio::ipv4::tcp::acceptor* acceptor,
|
||||
asio::ipv4::tcp::socket* socket, const asio::error& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
@ -27,7 +27,7 @@ void handle_accept(asio::socket_acceptor* acceptor,
|
||||
asio::placeholders::error,
|
||||
asio::placeholders::bytes_transferred));
|
||||
|
||||
socket = new asio::stream_socket(acceptor->io_service());
|
||||
socket = new asio::ipv4::tcp::socket(acceptor->io_service());
|
||||
|
||||
acceptor->async_accept(*socket,
|
||||
boost::bind(handle_accept, acceptor, socket,
|
||||
@ -45,11 +45,11 @@ int main()
|
||||
{
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(13));
|
||||
|
||||
asio::stream_socket* socket
|
||||
= new asio::stream_socket(io_service);
|
||||
asio::ipv4::tcp::socket* socket
|
||||
= new asio::ipv4::tcp::socket(io_service);
|
||||
|
||||
acceptor.async_accept(*socket,
|
||||
boost::bind(handle_accept, &acceptor, socket,
|
||||
|
@ -19,7 +19,7 @@ int main(int argc, char* argv[])
|
||||
asio::ipv4::udp::endpoint receiver_endpoint(13, host.address(0));
|
||||
|
||||
char send_buf[1] = { 0 };
|
||||
asio::datagram_socket socket(io_service,
|
||||
asio::ipv4::udp::socket socket(io_service,
|
||||
asio::ipv4::udp::endpoint(0));
|
||||
socket.send_to(
|
||||
asio::buffer(send_buf, sizeof(send_buf)),
|
||||
|
@ -9,7 +9,7 @@ int main()
|
||||
{
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::datagram_socket socket(io_service,
|
||||
asio::ipv4::udp::socket socket(io_service,
|
||||
asio::ipv4::udp::endpoint(13));
|
||||
|
||||
for (;;)
|
||||
|
@ -10,7 +10,7 @@ void handle_send_to(char* send_buf, const asio::error& /*error*/,
|
||||
free(send_buf);
|
||||
}
|
||||
|
||||
void handle_receive_from(asio::datagram_socket* socket, char* recv_buf,
|
||||
void handle_receive_from(asio::ipv4::udp::socket* socket, char* recv_buf,
|
||||
size_t recv_length, asio::ipv4::udp::endpoint* remote_endpoint,
|
||||
const asio::error& error, size_t /*bytes_transferred*/)
|
||||
{
|
||||
@ -44,7 +44,7 @@ int main()
|
||||
size_t recv_length = sizeof(recv_buf);
|
||||
asio::ipv4::udp::endpoint remote_endpoint;
|
||||
|
||||
asio::datagram_socket socket(io_service,
|
||||
asio::ipv4::udp::socket socket(io_service,
|
||||
asio::ipv4::udp::endpoint(13));
|
||||
socket.async_receive_from(
|
||||
asio::buffer(recv_buf, recv_length), 0, remote_endpoint,
|
||||
|
@ -3,15 +3,15 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <asio.hpp>
|
||||
|
||||
void handle_tcp_write(asio::stream_socket* socket, char* write_buf)
|
||||
void handle_tcp_write(asio::ipv4::tcp::socket* socket, char* write_buf)
|
||||
{
|
||||
using namespace std; // For free.
|
||||
free(write_buf);
|
||||
delete socket;
|
||||
}
|
||||
|
||||
void handle_tcp_accept(asio::socket_acceptor* acceptor,
|
||||
asio::stream_socket* socket, const asio::error& error)
|
||||
void handle_tcp_accept(asio::ipv4::tcp::acceptor* acceptor,
|
||||
asio::ipv4::tcp::socket* socket, const asio::error& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
@ -24,7 +24,7 @@ void handle_tcp_accept(asio::socket_acceptor* acceptor,
|
||||
asio::buffer(write_buf, write_length),
|
||||
boost::bind(handle_tcp_write, socket, write_buf));
|
||||
|
||||
socket = new asio::stream_socket(acceptor->io_service());
|
||||
socket = new asio::ipv4::tcp::socket(acceptor->io_service());
|
||||
|
||||
acceptor->async_accept(*socket,
|
||||
boost::bind(handle_tcp_accept, acceptor, socket,
|
||||
@ -42,7 +42,7 @@ void handle_udp_send_to(char* send_buf)
|
||||
free(send_buf);
|
||||
}
|
||||
|
||||
void handle_udp_receive_from(asio::datagram_socket* socket,
|
||||
void handle_udp_receive_from(asio::ipv4::udp::socket* socket,
|
||||
char* recv_buf, size_t recv_length,
|
||||
asio::ipv4::udp::endpoint* remote_endpoint,
|
||||
const asio::error& error)
|
||||
@ -71,17 +71,17 @@ int main()
|
||||
{
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor tcp_acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor tcp_acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(13));
|
||||
|
||||
asio::stream_socket* tcp_socket
|
||||
= new asio::stream_socket(io_service);
|
||||
asio::ipv4::tcp::socket* tcp_socket
|
||||
= new asio::ipv4::tcp::socket(io_service);
|
||||
|
||||
tcp_acceptor.async_accept(*tcp_socket,
|
||||
boost::bind(handle_tcp_accept, &tcp_acceptor, tcp_socket,
|
||||
asio::placeholders::error));
|
||||
|
||||
asio::datagram_socket udp_socket(io_service,
|
||||
asio::ipv4::udp::socket udp_socket(io_service,
|
||||
asio::ipv4::udp::endpoint(13));
|
||||
|
||||
char recv_buf[1];
|
||||
|
@ -43,8 +43,8 @@ Now create and connect the socket.
|
||||
|
||||
The connection is open. All we need to do now is read the
|
||||
response from the daytime service. When the server closes the connection, the
|
||||
asio::stream_socket::read_some() function will exit with the asio::error::eof
|
||||
error, which is how we know to exit the loop.
|
||||
asio::ipv4::tcp::socket::read_some() function will exit with the
|
||||
asio::error::eof error, which is how we know to exit the loop.
|
||||
|
||||
\until }
|
||||
|
||||
@ -75,10 +75,10 @@ with TCP.
|
||||
|
||||
\until asio::io_service
|
||||
|
||||
An asio::socket_acceptor object needs to be created to listen
|
||||
An asio::ipv4::tcp::acceptor object needs to be created to listen
|
||||
for new connections. It is initialised to listen on TCP port 13.
|
||||
|
||||
\until asio::socket_acceptor
|
||||
\until asio::ipv4::tcp::acceptor
|
||||
\until endpoint
|
||||
|
||||
This is an iterative server, which means that it will handle one
|
||||
@ -118,15 +118,15 @@ Return to \ref tutdaytime2
|
||||
|
||||
\dontinclude daytime3/server.cpp
|
||||
\skip int main()
|
||||
\until asio::socket_acceptor acceptor
|
||||
\until asio::ipv4::tcp::acceptor acceptor
|
||||
\until endpoint
|
||||
|
||||
We need to set up the initial socket to hold an accepted client connection.
|
||||
|
||||
\until asio::stream_socket*
|
||||
\until stream_socket
|
||||
\until asio::ipv4::tcp::socket*
|
||||
\until ipv4::tcp::socket
|
||||
|
||||
The function asio::socket_acceptor::async_accept() will cause the
|
||||
The function asio::ipv4::tcp::acceptor::async_accept() will cause the
|
||||
application to listen in the background for a new connection. When such a
|
||||
connection is received, the io_service will invoke the <tt>handle_accept()</tt>
|
||||
function with an asio::error argument.
|
||||
@ -155,7 +155,7 @@ Determine what we are going to send.
|
||||
\until size_t write_length
|
||||
|
||||
We now call \ref async_write to serve the data to the client. Note that we
|
||||
are using \ref async_write, rather than asio::stream_socket::write_some, to
|
||||
are using \ref async_write, rather than asio::ipv4::tcp::socket::write_some, to
|
||||
ensure that the entire block of data is sent.
|
||||
|
||||
\until asio::placeholders::bytes_transferred
|
||||
@ -215,14 +215,14 @@ Create an object for the remote endpoint, UDP port 13 on the server.
|
||||
\until asio::ipv4::udp::endpoint
|
||||
|
||||
Since UDP is datagram-oriented, we will not be using a stream socket. Create an
|
||||
asio::datagram_socket and initiate contact with the remote endpoint.
|
||||
asio::ipv4::udp::socket and initiate contact with the remote endpoint.
|
||||
|
||||
\until asio::buffer(send_buf,
|
||||
\until receiver_endpoint
|
||||
|
||||
Now we need to be ready to accept whatever the server sends back to us. The
|
||||
endpoint on our side that receives the server's response will be initialised by
|
||||
asio::datagram_socket::receive_from().
|
||||
asio::ipv4::udp::socket::receive_from().
|
||||
|
||||
\until }
|
||||
|
||||
@ -253,13 +253,13 @@ with UDP.
|
||||
|
||||
\until asio::io_service
|
||||
|
||||
Create an asio::datagram_socket object to receive requests on UDP port 13.
|
||||
Create an asio::ipv4::udp::socket object to receive requests on UDP port 13.
|
||||
|
||||
\until asio::datagram_socket
|
||||
\until asio::ipv4::udp::socket
|
||||
\until endpoint
|
||||
|
||||
Wait for a client to initiate contact with us. The remote_endpoint object will
|
||||
be populated by asio::datagram_socket::receive_from().
|
||||
be populated by asio::ipv4::udp::socket::receive_from().
|
||||
|
||||
\until throw
|
||||
|
||||
@ -299,12 +299,12 @@ Return to \ref tutdaytime5
|
||||
\skip int main()
|
||||
\until asio::ipv4::udp::endpoint
|
||||
|
||||
Create an asio::datagram_socket object to receive requests on UDP port 13.
|
||||
Create an asio::ipv4::udp::socket object to receive requests on UDP port 13.
|
||||
|
||||
\until asio::datagram_socket
|
||||
\until asio::ipv4::udp::socket
|
||||
\until endpoint
|
||||
|
||||
The function asio::datagram_socket::async_receive_from() will cause the
|
||||
The function asio::ipv4::udp::socket::async_receive_from() will cause the
|
||||
application to listen in the background for a new request. When such a request
|
||||
is received, the io_service will invoke the <tt>handle_receive_from()</tt>
|
||||
function with two arguments: asio::error, and bytes_transferred.
|
||||
@ -335,7 +335,7 @@ Determine what we are going to send.
|
||||
|
||||
\until size_t send_length
|
||||
|
||||
We now call asio::datagram_socket::async_send_to() to serve the data to the
|
||||
We now call asio::ipv4::udp::socket::async_send_to() to serve the data to the
|
||||
client.
|
||||
|
||||
\until asio::placeholders::bytes_transferred
|
||||
@ -387,12 +387,12 @@ have just written, into a single server application.
|
||||
\skip int main()
|
||||
\until asio::io_service
|
||||
|
||||
We will begin by creating an asio::stream_socket object to hold an accepted TCP
|
||||
client connection.
|
||||
We will begin by creating an asio::ipv4::tcp::socket object to hold an accepted
|
||||
TCP client connection.
|
||||
|
||||
\until asio::placeholders::error
|
||||
|
||||
Now we need an asio::datagram_socket object for UDP client requests.
|
||||
Now we need an asio::ipv4::udp::socket object for UDP client requests.
|
||||
|
||||
\until &remote_endpoint, asio::placeholders::error
|
||||
|
||||
|
@ -153,7 +153,7 @@ private:
|
||||
|
||||
private:
|
||||
locking_dispatcher dispatcher_;
|
||||
stream_socket socket_;
|
||||
ipv4::tcp::socket socket_;
|
||||
size_t block_size_;
|
||||
char* read_data_;
|
||||
size_t read_data_length_;
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
delete[] write_data_;
|
||||
}
|
||||
|
||||
stream_socket& socket()
|
||||
ipv4::tcp::socket& socket()
|
||||
{
|
||||
return socket_;
|
||||
}
|
||||
@ -113,7 +113,7 @@ public:
|
||||
private:
|
||||
io_service& io_service_;
|
||||
locking_dispatcher dispatcher_;
|
||||
stream_socket socket_;
|
||||
ipv4::tcp::socket socket_;
|
||||
size_t block_size_;
|
||||
char* read_data_;
|
||||
size_t read_data_length_;
|
||||
@ -132,7 +132,7 @@ public:
|
||||
block_size_(block_size)
|
||||
{
|
||||
acceptor_.open(ipv4::tcp());
|
||||
acceptor_.set_option(stream_socket::reuse_address(1));
|
||||
acceptor_.set_option(ipv4::tcp::acceptor::reuse_address(1));
|
||||
acceptor_.bind(endpoint);
|
||||
acceptor_.listen();
|
||||
|
||||
@ -166,7 +166,7 @@ public:
|
||||
|
||||
private:
|
||||
io_service& io_service_;
|
||||
socket_acceptor acceptor_;
|
||||
ipv4::tcp::acceptor acceptor_;
|
||||
size_t block_size_;
|
||||
};
|
||||
|
||||
|
@ -148,17 +148,6 @@ run datagram_socket_service_test.cpp
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run datagram_socket_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
:
|
||||
: <include>../../..
|
||||
<threading>multi
|
||||
<mingw><*><find-library>ws2_32
|
||||
<mingw><*><find-library>mswsock
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run deadline_timer_service_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
@ -392,17 +381,6 @@ run socket_acceptor_service_test.cpp
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run socket_acceptor_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
:
|
||||
: <include>../../..
|
||||
<threading>multi
|
||||
<mingw><*><find-library>ws2_32
|
||||
<mingw><*><find-library>mswsock
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run socket_base_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
@ -425,17 +403,6 @@ run stream_socket_service_test.cpp
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run stream_socket_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
:
|
||||
: <include>../../..
|
||||
<threading>multi
|
||||
<mingw><*><find-library>ws2_32
|
||||
<mingw><*><find-library>mswsock
|
||||
$(SOCKET_LIBS)
|
||||
;
|
||||
|
||||
run time_traits_test.cpp
|
||||
<lib>@boost/libs/date_time/build/boost_date_time
|
||||
:
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "unit_test.hpp"
|
||||
|
||||
typedef asio::buffered_read_stream<
|
||||
asio::stream_socket> stream_type;
|
||||
asio::ipv4::tcp::socket> stream_type;
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
@ -25,7 +25,7 @@ void test_sync_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -35,7 +35,7 @@ void test_sync_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.accept(server_socket);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
@ -132,7 +132,7 @@ void test_async_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -142,7 +142,7 @@ void test_async_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.async_accept(server_socket, handle_accept);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), handle_accept);
|
||||
io_service.run();
|
||||
io_service.reset();
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
#include "asio.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
typedef asio::buffered_stream<asio::stream_socket> stream_type;
|
||||
typedef asio::buffered_stream<
|
||||
asio::ipv4::tcp::socket> stream_type;
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
@ -24,7 +25,7 @@ void test_sync_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -34,7 +35,7 @@ void test_sync_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.accept(server_socket);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
@ -138,7 +139,7 @@ void test_async_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -148,7 +149,7 @@ void test_async_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.async_accept(server_socket, handle_accept);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), handle_accept);
|
||||
io_service.run();
|
||||
io_service.reset();
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "unit_test.hpp"
|
||||
|
||||
typedef asio::buffered_write_stream<
|
||||
asio::stream_socket> stream_type;
|
||||
asio::ipv4::tcp::socket> stream_type;
|
||||
|
||||
void test_sync_operations()
|
||||
{
|
||||
@ -25,7 +25,7 @@ void test_sync_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -35,7 +35,7 @@ void test_sync_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.accept(server_socket);
|
||||
acceptor.accept(server_socket.lowest_layer());
|
||||
|
||||
const char write_data[]
|
||||
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
@ -139,7 +139,7 @@ void test_async_operations()
|
||||
|
||||
asio::io_service io_service;
|
||||
|
||||
asio::socket_acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::acceptor acceptor(io_service,
|
||||
asio::ipv4::tcp::endpoint(0));
|
||||
asio::ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
@ -149,7 +149,7 @@ void test_async_operations()
|
||||
client_socket.lowest_layer().connect(server_endpoint);
|
||||
|
||||
stream_type server_socket(io_service);
|
||||
acceptor.async_accept(server_socket, handle_accept);
|
||||
acceptor.async_accept(server_socket.lowest_layer(), handle_accept);
|
||||
io_service.run();
|
||||
io_service.reset();
|
||||
|
||||
|
@ -1,80 +0,0 @@
|
||||
//
|
||||
// datagram_socket_test.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/datagram_socket.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstring>
|
||||
#include "asio.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
using namespace asio;
|
||||
|
||||
void handle_send(size_t expected_bytes_sent, const error& err,
|
||||
size_t bytes_sent)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
BOOST_CHECK(expected_bytes_sent == bytes_sent);
|
||||
}
|
||||
|
||||
void handle_recv(size_t expected_bytes_recvd, const error& err,
|
||||
size_t bytes_recvd)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
BOOST_CHECK(expected_bytes_recvd == bytes_recvd);
|
||||
}
|
||||
|
||||
void datagram_socket_test()
|
||||
{
|
||||
using namespace std; // For memcmp and memset.
|
||||
|
||||
io_service ios;
|
||||
|
||||
datagram_socket s1(ios, ipv4::udp::endpoint(0));
|
||||
ipv4::udp::endpoint target_endpoint;
|
||||
s1.get_local_endpoint(target_endpoint);
|
||||
target_endpoint.address(ipv4::address::loopback());
|
||||
|
||||
datagram_socket s2(ios);
|
||||
s2.open(ipv4::udp());
|
||||
s2.bind(ipv4::udp::endpoint(0));
|
||||
char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
s2.send_to(buffer(send_msg, sizeof(send_msg)), 0, target_endpoint);
|
||||
|
||||
char recv_msg[sizeof(send_msg)];
|
||||
ipv4::udp::endpoint sender_endpoint;
|
||||
size_t bytes_recvd = s1.receive_from(buffer(recv_msg, sizeof(recv_msg)), 0,
|
||||
sender_endpoint);
|
||||
|
||||
BOOST_CHECK(bytes_recvd == sizeof(send_msg));
|
||||
BOOST_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
|
||||
memset(recv_msg, 0, sizeof(recv_msg));
|
||||
|
||||
target_endpoint = sender_endpoint;
|
||||
s1.async_send_to(buffer(send_msg, sizeof(send_msg)), 0, target_endpoint,
|
||||
boost::bind(handle_send, sizeof(send_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
s2.async_receive_from(buffer(recv_msg, sizeof(recv_msg)), 0, sender_endpoint,
|
||||
boost::bind(handle_recv, sizeof(recv_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
|
||||
ios.run();
|
||||
|
||||
BOOST_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
}
|
||||
|
||||
test_suite* init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE("datagram_socket");
|
||||
test->add(BOOST_TEST_CASE(&datagram_socket_test));
|
||||
return test;
|
||||
}
|
@ -21,7 +21,7 @@ void error_handler_test()
|
||||
{
|
||||
io_service ios;
|
||||
|
||||
stream_socket s(ios);
|
||||
ipv4::tcp::socket s(ios);
|
||||
ipv4::tcp::endpoint endpoint(321, ipv4::address::any());
|
||||
|
||||
error expected_err;
|
||||
|
@ -11,10 +11,81 @@
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ipv4/tcp.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstring>
|
||||
#include "asio.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
using namespace asio;
|
||||
|
||||
void handle_accept(const error& err)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
}
|
||||
|
||||
void handle_connect(const error& err)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
}
|
||||
|
||||
void ipv4_tcp_acceptor_test()
|
||||
{
|
||||
io_service ios;
|
||||
|
||||
ipv4::tcp::acceptor acceptor(ios, ipv4::tcp::endpoint(0));
|
||||
ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
server_endpoint.address(ipv4::address::loopback());
|
||||
|
||||
ipv4::tcp::socket client_side_socket(ios);
|
||||
ipv4::tcp::socket server_side_socket(ios);
|
||||
|
||||
client_side_socket.connect(server_endpoint);
|
||||
acceptor.accept(server_side_socket);
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
client_side_socket.connect(server_endpoint);
|
||||
ipv4::tcp::endpoint client_endpoint;
|
||||
acceptor.accept_endpoint(server_side_socket, client_endpoint);
|
||||
|
||||
ipv4::tcp::endpoint client_side_local_endpoint;
|
||||
client_side_socket.get_local_endpoint(client_side_local_endpoint);
|
||||
BOOST_CHECK(client_side_local_endpoint.port() == client_endpoint.port());
|
||||
|
||||
ipv4::tcp::endpoint server_side_remote_endpoint;
|
||||
server_side_socket.get_remote_endpoint(server_side_remote_endpoint);
|
||||
BOOST_CHECK(server_side_remote_endpoint.port() == client_endpoint.port());
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
acceptor.async_accept(server_side_socket, handle_accept);
|
||||
client_side_socket.async_connect(server_endpoint, handle_connect);
|
||||
|
||||
ios.run();
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
acceptor.async_accept_endpoint(server_side_socket, client_endpoint,
|
||||
handle_accept);
|
||||
client_side_socket.async_connect(server_endpoint, handle_connect);
|
||||
|
||||
ios.reset();
|
||||
ios.run();
|
||||
|
||||
client_side_socket.get_local_endpoint(client_side_local_endpoint);
|
||||
BOOST_CHECK(client_side_local_endpoint.port() == client_endpoint.port());
|
||||
|
||||
server_side_socket.get_remote_endpoint(server_side_remote_endpoint);
|
||||
BOOST_CHECK(server_side_remote_endpoint.port() == client_endpoint.port());
|
||||
}
|
||||
|
||||
test_suite* init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE("ipv4/tcp");
|
||||
test->add(BOOST_TEST_CASE(&ipv4_tcp_acceptor_test));
|
||||
return test;
|
||||
}
|
||||
|
@ -11,10 +11,70 @@
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/ipv4/udp.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstring>
|
||||
#include "asio.hpp"
|
||||
#include "../unit_test.hpp"
|
||||
|
||||
using namespace asio;
|
||||
|
||||
void handle_send(size_t expected_bytes_sent, const error& err,
|
||||
size_t bytes_sent)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
BOOST_CHECK(expected_bytes_sent == bytes_sent);
|
||||
}
|
||||
|
||||
void handle_recv(size_t expected_bytes_recvd, const error& err,
|
||||
size_t bytes_recvd)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
BOOST_CHECK(expected_bytes_recvd == bytes_recvd);
|
||||
}
|
||||
|
||||
void ipv4_udp_test()
|
||||
{
|
||||
using namespace std; // For memcmp and memset.
|
||||
|
||||
io_service ios;
|
||||
|
||||
ipv4::udp::socket s1(ios, ipv4::udp::endpoint(0));
|
||||
ipv4::udp::endpoint target_endpoint;
|
||||
s1.get_local_endpoint(target_endpoint);
|
||||
target_endpoint.address(ipv4::address::loopback());
|
||||
|
||||
ipv4::udp::socket s2(ios);
|
||||
s2.open(ipv4::udp());
|
||||
s2.bind(ipv4::udp::endpoint(0));
|
||||
char send_msg[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
s2.send_to(buffer(send_msg, sizeof(send_msg)), 0, target_endpoint);
|
||||
|
||||
char recv_msg[sizeof(send_msg)];
|
||||
ipv4::udp::endpoint sender_endpoint;
|
||||
size_t bytes_recvd = s1.receive_from(buffer(recv_msg, sizeof(recv_msg)), 0,
|
||||
sender_endpoint);
|
||||
|
||||
BOOST_CHECK(bytes_recvd == sizeof(send_msg));
|
||||
BOOST_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
|
||||
memset(recv_msg, 0, sizeof(recv_msg));
|
||||
|
||||
target_endpoint = sender_endpoint;
|
||||
s1.async_send_to(buffer(send_msg, sizeof(send_msg)), 0, target_endpoint,
|
||||
boost::bind(handle_send, sizeof(send_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
s2.async_receive_from(buffer(recv_msg, sizeof(recv_msg)), 0, sender_endpoint,
|
||||
boost::bind(handle_recv, sizeof(recv_msg),
|
||||
placeholders::error, placeholders::bytes_transferred));
|
||||
|
||||
ios.run();
|
||||
|
||||
BOOST_CHECK(memcmp(send_msg, recv_msg, sizeof(send_msg)) == 0);
|
||||
}
|
||||
|
||||
test_suite* init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE("ipv4/udp");
|
||||
test->add(BOOST_TEST_CASE(&ipv4_udp_test));
|
||||
return test;
|
||||
}
|
||||
|
@ -86,16 +86,18 @@ private:
|
||||
void is_read_buffered_test()
|
||||
{
|
||||
BOOST_CHECK(!asio::is_read_buffered<
|
||||
asio::stream_socket>::value);
|
||||
asio::ipv4::tcp::socket>::value);
|
||||
|
||||
BOOST_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_read_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_read_stream<
|
||||
asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!asio::is_read_buffered<
|
||||
asio::buffered_write_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_write_stream<
|
||||
asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!!asio::is_read_buffered<
|
||||
asio::buffered_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_stream<asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!asio::is_read_buffered<test_stream>::value);
|
||||
|
||||
|
@ -86,16 +86,18 @@ private:
|
||||
void is_write_buffered_test()
|
||||
{
|
||||
BOOST_CHECK(!asio::is_write_buffered<
|
||||
asio::stream_socket>::value);
|
||||
asio::ipv4::tcp::socket>::value);
|
||||
|
||||
BOOST_CHECK(!asio::is_write_buffered<
|
||||
asio::buffered_read_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_read_stream<
|
||||
asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_write_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_write_stream<
|
||||
asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!!asio::is_write_buffered<
|
||||
asio::buffered_stream<asio::stream_socket> >::value);
|
||||
asio::buffered_stream<asio::ipv4::tcp::socket> >::value);
|
||||
|
||||
BOOST_CHECK(!asio::is_write_buffered<test_stream>::value);
|
||||
|
||||
|
@ -1,91 +0,0 @@
|
||||
//
|
||||
// socket_acceptor_test.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/socket_acceptor.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstring>
|
||||
#include "asio.hpp"
|
||||
#include "unit_test.hpp"
|
||||
|
||||
using namespace asio;
|
||||
|
||||
void handle_accept(const error& err)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
}
|
||||
|
||||
void handle_connect(const error& err)
|
||||
{
|
||||
BOOST_CHECK(!err);
|
||||
}
|
||||
|
||||
void socket_acceptor_test()
|
||||
{
|
||||
io_service ios;
|
||||
|
||||
socket_acceptor acceptor(ios, ipv4::tcp::endpoint(0));
|
||||
ipv4::tcp::endpoint server_endpoint;
|
||||
acceptor.get_local_endpoint(server_endpoint);
|
||||
server_endpoint.address(ipv4::address::loopback());
|
||||
|
||||
stream_socket client_side_socket(ios);
|
||||
stream_socket server_side_socket(ios);
|
||||
|
||||
client_side_socket.connect(server_endpoint);
|
||||
acceptor.accept(server_side_socket);
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
client_side_socket.connect(server_endpoint);
|
||||
ipv4::tcp::endpoint client_endpoint;
|
||||
acceptor.accept_endpoint(server_side_socket, client_endpoint);
|
||||
|
||||
ipv4::tcp::endpoint client_side_local_endpoint;
|
||||
client_side_socket.get_local_endpoint(client_side_local_endpoint);
|
||||
BOOST_CHECK(client_side_local_endpoint.port() == client_endpoint.port());
|
||||
|
||||
ipv4::tcp::endpoint server_side_remote_endpoint;
|
||||
server_side_socket.get_remote_endpoint(server_side_remote_endpoint);
|
||||
BOOST_CHECK(server_side_remote_endpoint.port() == client_endpoint.port());
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
acceptor.async_accept(server_side_socket, handle_accept);
|
||||
client_side_socket.async_connect(server_endpoint, handle_connect);
|
||||
|
||||
ios.run();
|
||||
|
||||
client_side_socket.close();
|
||||
server_side_socket.close();
|
||||
|
||||
acceptor.async_accept_endpoint(server_side_socket, client_endpoint,
|
||||
handle_accept);
|
||||
client_side_socket.async_connect(server_endpoint, handle_connect);
|
||||
|
||||
ios.reset();
|
||||
ios.run();
|
||||
|
||||
client_side_socket.get_local_endpoint(client_side_local_endpoint);
|
||||
BOOST_CHECK(client_side_local_endpoint.port() == client_endpoint.port());
|
||||
|
||||
server_side_socket.get_remote_endpoint(server_side_remote_endpoint);
|
||||
BOOST_CHECK(server_side_remote_endpoint.port() == client_endpoint.port());
|
||||
}
|
||||
|
||||
test_suite* init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE("socket_acceptor");
|
||||
test->add(BOOST_TEST_CASE(&socket_acceptor_test));
|
||||
return test;
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
//
|
||||
// stream_socket_test.cpp
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~
|
||||
//
|
||||
// Copyright (c) 2003-2005 Christopher M. Kohlhoff (chris at kohlhoff dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include "asio/stream_socket.hpp"
|
||||
|
||||
#include "unit_test.hpp"
|
||||
|
||||
test_suite* init_unit_test_suite(int argc, char* argv[])
|
||||
{
|
||||
test_suite* test = BOOST_TEST_SUITE("stream_socket");
|
||||
return test;
|
||||
}
|
Loading…
Reference in New Issue
Block a user