asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design
Reference Class Hierarchy | Class Index | Member Index

asio::basic_datagram_socket< Protocol, DatagramSocketService > Class Template Reference

Inherits asio::basic_socket< Protocol, DatagramSocketService >.

Inheritance diagram for asio::basic_datagram_socket< Protocol, DatagramSocketService >:

Inheritance graph
List of all members.

Detailed Description

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
class asio::basic_datagram_socket< Protocol, DatagramSocketService >

Provides datagram-oriented socket functionality.

The basic_datagram_socket class template provides asynchronous and blocking datagram-oriented socket functionality.

Thread Safety
Distinct objects: Safe.
Shared objects: Unsafe.


Public Types

typedef DatagramSocketService::native_type native_type
 The native representation of a socket.
typedef Protocol protocol_type
 The protocol type.
typedef Protocol::endpoint endpoint_type
 The endpoint type.
typedef basic_socket< Protocol,
DatagramSocketService > 
lowest_layer_type
 A basic_socket is always the lowest layer.
typedef DatagramSocketService service_type
 The type of the service that will be used to provide I/O operations.
typedef service_type::implementation_type implementation_type
 The underlying implementation type of I/O object.
enum  shutdown_type {
  shutdown_receive = implementation_defined,
  shutdown_send = implementation_defined,
  shutdown_both = implementation_defined
}
 Different ways a socket may be shutdown. More...
typedef int message_flags
 Bitmask type for flags that can be passed to send and receive operations.
typedef implementation_defined broadcast
 Socket option to permit sending of broadcast messages.
typedef implementation_defined debug
 Socket option to enable socket-level debugging.
typedef implementation_defined do_not_route
 Socket option to prevent routing, use local interfaces only.
typedef implementation_defined keep_alive
 Socket option to send keep-alives.
typedef implementation_defined send_buffer_size
 Socket option for the send buffer size of a socket.
typedef implementation_defined send_low_watermark
 Socket option for the send low watermark.
typedef implementation_defined receive_buffer_size
 Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_low_watermark
 Socket option for the receive low watermark.
typedef implementation_defined reuse_address
 Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined linger
 Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined enable_connection_aborted
 Socket option to report aborted connections on accept.
typedef implementation_defined non_blocking_io
 IO control command to set the blocking mode of the socket.
typedef implementation_defined bytes_readable
 IO control command to get the amount of data that can be read without blocking.

Public Member Functions

 basic_datagram_socket (asio::io_service &io_service)
 Construct a basic_datagram_socket without opening it.
 basic_datagram_socket (asio::io_service &io_service, const protocol_type &protocol)
 Construct and open a basic_datagram_socket.
 basic_datagram_socket (asio::io_service &io_service, const endpoint_type &endpoint)
 Construct a basic_datagram_socket, opening it and binding it to the given local endpoint.
 basic_datagram_socket (asio::io_service &io_service, const protocol_type &protocol, const native_type &native_socket)
 Construct a basic_datagram_socket on an existing native socket.
template<typename ConstBufferSequence>
std::size_t send (const ConstBufferSequence &buffers)
 Send some data on a connected socket.
template<typename ConstBufferSequence>
std::size_t send (const ConstBufferSequence &buffers, socket_base::message_flags flags)
 Send some data on a connected socket.
template<typename ConstBufferSequence>
std::size_t send (const ConstBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
 Send some data on a connected socket.
template<typename ConstBufferSequence, typename WriteHandler>
void async_send (const ConstBufferSequence &buffers, WriteHandler handler)
 Start an asynchronous send on a connected socket.
template<typename ConstBufferSequence, typename WriteHandler>
void async_send (const ConstBufferSequence &buffers, socket_base::message_flags flags, WriteHandler handler)
 Start an asynchronous send on a connected socket.
template<typename ConstBufferSequence>
std::size_t send_to (const ConstBufferSequence &buffers, const endpoint_type &destination)
 Send a datagram to the specified endpoint.
template<typename ConstBufferSequence>
std::size_t send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags)
 Send a datagram to the specified endpoint.
template<typename ConstBufferSequence>
std::size_t send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, asio::error_code &ec)
 Send a datagram to the specified endpoint.
template<typename ConstBufferSequence, typename WriteHandler>
void async_send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, WriteHandler handler)
 Start an asynchronous send.
template<typename ConstBufferSequence, typename WriteHandler>
void async_send_to (const ConstBufferSequence &buffers, const endpoint_type &destination, socket_base::message_flags flags, WriteHandler handler)
 Start an asynchronous send.
template<typename MutableBufferSequence>
std::size_t receive (const MutableBufferSequence &buffers)
 Receive some data on a connected socket.
template<typename MutableBufferSequence>
std::size_t receive (const MutableBufferSequence &buffers, socket_base::message_flags flags)
 Receive some data on a connected socket.
template<typename MutableBufferSequence>
std::size_t receive (const MutableBufferSequence &buffers, socket_base::message_flags flags, asio::error_code &ec)
 Receive some data on a connected socket.
template<typename MutableBufferSequence, typename ReadHandler>
void async_receive (const MutableBufferSequence &buffers, ReadHandler handler)
 Start an asynchronous receive on a connected socket.
template<typename MutableBufferSequence, typename ReadHandler>
void async_receive (const MutableBufferSequence &buffers, socket_base::message_flags flags, ReadHandler handler)
 Start an asynchronous receive on a connected socket.
template<typename MutableBufferSequence>
std::size_t receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint)
 Receive a datagram with the endpoint of the sender.
template<typename MutableBufferSequence>
std::size_t receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags)
 Receive a datagram with the endpoint of the sender.
template<typename MutableBufferSequence>
std::size_t receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, asio::error_code &ec)
 Receive a datagram with the endpoint of the sender.
template<typename MutableBufferSequence, typename ReadHandler>
void async_receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, ReadHandler handler)
 Start an asynchronous receive.
template<typename MutableBufferSequence, typename ReadHandler>
void async_receive_from (const MutableBufferSequence &buffers, endpoint_type &sender_endpoint, socket_base::message_flags flags, ReadHandler handler)
 Start an asynchronous receive.
lowest_layer_typelowest_layer ()
 Get a reference to the lowest layer.
void open (const protocol_type &protocol=protocol_type())
 Open the socket using the specified protocol.
asio::error_code open (const protocol_type &protocol, asio::error_code &ec)
 Open the socket using the specified protocol.
void assign (const protocol_type &protocol, const native_type &native_socket)
 Assign an existing native socket to the socket.
asio::error_code assign (const protocol_type &protocol, const native_type &native_socket, asio::error_code &ec)
 Assign an existing native socket to the socket.
bool is_open () const
 Determine whether the socket is open.
void close ()
 Close the socket.
asio::error_code close (asio::error_code &ec)
 Close the socket.
native_type native ()
 Get the native socket representation.
void cancel ()
 Cancel all asynchronous operations associated with the socket.
asio::error_code cancel (asio::error_code &ec)
 Cancel all asynchronous operations associated with the socket.
bool at_mark () const
 Determine whether the socket is at the out-of-band data mark.
bool at_mark (asio::error_code &ec) const
 Determine whether the socket is at the out-of-band data mark.
std::size_t available () const
 Determine the number of bytes available for reading.
std::size_t available (asio::error_code &ec) const
 Determine the number of bytes available for reading.
void bind (const endpoint_type &endpoint)
 Bind the socket to the given local endpoint.
asio::error_code bind (const endpoint_type &endpoint, asio::error_code &ec)
 Bind the socket to the given local endpoint.
void connect (const endpoint_type &peer_endpoint)
 Connect the socket to the specified endpoint.
asio::error_code connect (const endpoint_type &peer_endpoint, asio::error_code &ec)
 Connect the socket to the specified endpoint.
void async_connect (const endpoint_type &peer_endpoint, ConnectHandler handler)
 Start an asynchronous connect.
void set_option (const SettableSocketOption &option)
 Set an option on the socket.
asio::error_code set_option (const SettableSocketOption &option, asio::error_code &ec)
 Set an option on the socket.
void get_option (GettableSocketOption &option) const
 Get an option from the socket.
asio::error_code get_option (GettableSocketOption &option, asio::error_code &ec) const
 Get an option from the socket.
void io_control (IoControlCommand &command)
 Perform an IO control command on the socket.
asio::error_code io_control (IoControlCommand &command, asio::error_code &ec)
 Perform an IO control command on the socket.
endpoint_type local_endpoint () const
 Get the local endpoint of the socket.
endpoint_type local_endpoint (asio::error_code &ec) const
 Get the local endpoint of the socket.
endpoint_type remote_endpoint () const
 Get the remote endpoint of the socket.
endpoint_type remote_endpoint (asio::error_code &ec) const
 Get the remote endpoint of the socket.
void shutdown (shutdown_type what)
 Disable sends or receives on the socket.
asio::error_code shutdown (shutdown_type what, asio::error_code &ec)
 Disable sends or receives on the socket.
asio::io_serviceio_service ()
 Get the io_service associated with the object.

Static Public Attributes

static const int message_peek = implementation_defined
 Peek at incoming data without removing it from the input queue.
static const int message_out_of_band = implementation_defined
 Process out-of-band data.
static const int message_do_not_route = implementation_defined
 Specify that the data should not be subject to routing.
static const int max_connections = implementation_defined
 The maximum length of the queue of pending incoming connections.


Member Typedef Documentation

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
typedef DatagramSocketService::native_type asio::basic_datagram_socket< Protocol, DatagramSocketService >::native_type

The native representation of a socket.

Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
typedef Protocol asio::basic_datagram_socket< Protocol, DatagramSocketService >::protocol_type

The protocol type.

Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
typedef Protocol::endpoint asio::basic_datagram_socket< Protocol, DatagramSocketService >::endpoint_type

The endpoint type.

Reimplemented from asio::basic_socket< Protocol, DatagramSocketService >.

typedef basic_socket<Protocol , DatagramSocketService > asio::basic_socket< Protocol , DatagramSocketService >::lowest_layer_type [inherited]

A basic_socket is always the lowest layer.

typedef DatagramSocketService asio::basic_io_object< DatagramSocketService >::service_type [inherited]

The type of the service that will be used to provide I/O operations.

typedef service_type::implementation_type asio::basic_io_object< DatagramSocketService >::implementation_type [inherited]

The underlying implementation type of I/O object.

typedef int asio::socket_base::message_flags [inherited]

Bitmask type for flags that can be passed to send and receive operations.

typedef implementation_defined asio::socket_base::broadcast [inherited]

Socket option to permit sending of broadcast messages.

Implements the SOL_SOCKET/SO_BROADCAST socket option.

Examples
Setting the option:
 asio::ip::udp::socket socket(io_service); 
 ...
 asio::socket_base::broadcast option(true);
 socket.set_option(option);
Getting the current option value:
 asio::ip::udp::socket socket(io_service); 
 ...
 asio::socket_base::broadcast option;
 socket.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::debug [inherited]

Socket option to enable socket-level debugging.

Implements the SOL_SOCKET/SO_DEBUG socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::debug option(true);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::debug option;
 socket.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::do_not_route [inherited]

Socket option to prevent routing, use local interfaces only.

Implements the SOL_SOCKET/SO_DONTROUTE socket option.

Examples
Setting the option:
 asio::ip::udp::socket socket(io_service); 
 ...
 asio::socket_base::do_not_route option(true);
 socket.set_option(option);
Getting the current option value:
 asio::ip::udp::socket socket(io_service); 
 ...
 asio::socket_base::do_not_route option;
 socket.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::keep_alive [inherited]

Socket option to send keep-alives.

Implements the SOL_SOCKET/SO_KEEPALIVE socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::keep_alive option(true);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::keep_alive option;
 socket.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::send_buffer_size [inherited]

Socket option for the send buffer size of a socket.

Implements the SOL_SOCKET/SO_SNDBUF socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::send_buffer_size option(8192);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::send_buffer_size option;
 socket.get_option(option);
 int size = option.value();
Concepts:
Socket_Option, Integer_Socket_Option.

typedef implementation_defined asio::socket_base::send_low_watermark [inherited]

Socket option for the send low watermark.

Implements the SOL_SOCKET/SO_SNDLOWAT socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::send_low_watermark option(1024);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::send_low_watermark option;
 socket.get_option(option);
 int size = option.value();
Concepts:
Socket_Option, Integer_Socket_Option.

typedef implementation_defined asio::socket_base::receive_buffer_size [inherited]

Socket option for the receive buffer size of a socket.

Implements the SOL_SOCKET/SO_RCVBUF socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::receive_buffer_size option(8192);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::receive_buffer_size option;
 socket.get_option(option);
 int size = option.value();
Concepts:
Socket_Option, Integer_Socket_Option.

typedef implementation_defined asio::socket_base::receive_low_watermark [inherited]

Socket option for the receive low watermark.

Implements the SOL_SOCKET/SO_RCVLOWAT socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::receive_low_watermark option(1024);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::receive_low_watermark option;
 socket.get_option(option);
 int size = option.value();
Concepts:
Socket_Option, Integer_Socket_Option.

typedef implementation_defined asio::socket_base::reuse_address [inherited]

Socket option to allow the socket to be bound to an address that is already in use.

Implements the SOL_SOCKET/SO_REUSEADDR socket option.

Examples
Setting the option:
 asio::ip::tcp::acceptor acceptor(io_service); 
 ...
 asio::socket_base::reuse_address option(true);
 acceptor.set_option(option);
Getting the current option value:
 asio::ip::tcp::acceptor acceptor(io_service); 
 ...
 asio::socket_base::reuse_address option;
 acceptor.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::linger [inherited]

Socket option to specify whether the socket lingers on close if unsent data is present.

Implements the SOL_SOCKET/SO_LINGER socket option.

Examples
Setting the option:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::linger option(true, 30);
 socket.set_option(option);
Getting the current option value:
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::linger option;
 socket.get_option(option);
 bool is_set = option.enabled();
 unsigned short timeout = option.timeout();
Concepts:
Socket_Option, Linger_Socket_Option.

typedef implementation_defined asio::socket_base::enable_connection_aborted [inherited]

Socket option to report aborted connections on accept.

Implements a custom socket option that determines whether or not an accept operation is permitted to fail with asio::error::connection_aborted. By default the option is false.

Examples
Setting the option:
 asio::ip::tcp::acceptor acceptor(io_service); 
 ...
 asio::socket_base::enable_connection_aborted option(true);
 acceptor.set_option(option);
Getting the current option value:
 asio::ip::tcp::acceptor acceptor(io_service); 
 ...
 asio::socket_base::enable_connection_aborted option;
 acceptor.get_option(option);
 bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.

typedef implementation_defined asio::socket_base::non_blocking_io [inherited]

IO control command to set the blocking mode of the socket.

Implements the FIONBIO IO control command.

Example
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::non_blocking_io command(true);
 socket.io_control(command);
Concepts:
IO_Control_Command, Boolean_IO_Control_Command.

typedef implementation_defined asio::socket_base::bytes_readable [inherited]

IO control command to get the amount of data that can be read without blocking.

Implements the FIONREAD IO control command.

Example
 asio::ip::tcp::socket socket(io_service); 
 ...
 asio::socket_base::bytes_readable command(true);
 socket.io_control(command);
 std::size_t bytes_readable = command.get();
Concepts:
IO_Control_Command, Size_IO_Control_Command.


Member Enumeration Documentation

enum asio::socket_base::shutdown_type [inherited]

Different ways a socket may be shutdown.

Enumerator:
shutdown_receive  Shutdown the receive side of the socket.
shutdown_send  Shutdown the send side of the socket.
shutdown_both  Shutdown both send and receive on the socket.


Constructor & Destructor Documentation

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket ( asio::io_service io_service  )  [explicit]

Construct a basic_datagram_socket without opening it.

This constructor creates a datagram socket without opening it. The open() function must be called before data can be sent or received on the socket.

Parameters:
io_service The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket ( asio::io_service io_service,
const protocol_type protocol 
)

Construct and open a basic_datagram_socket.

This constructor creates and opens a datagram socket.

Parameters:
io_service The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket.
protocol An object specifying protocol parameters to be used.
Exceptions:
asio::system_error Thrown on failure.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket ( asio::io_service io_service,
const endpoint_type endpoint 
)

Construct a basic_datagram_socket, opening it and binding it to the given local endpoint.

This constructor creates a datagram 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.

Parameters:
io_service The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket.
endpoint An endpoint on the local machine to which the datagram socket will be bound.
Exceptions:
asio::system_error Thrown on failure.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
asio::basic_datagram_socket< Protocol, DatagramSocketService >::basic_datagram_socket ( asio::io_service io_service,
const protocol_type protocol,
const native_type native_socket 
)

Construct a basic_datagram_socket on an existing native socket.

This constructor creates a datagram socket object to hold an existing native socket.

Parameters:
io_service The io_service object that the datagram socket will use to dispatch handlers for any asynchronous operations performed on the socket.
protocol An object specifying protocol parameters to be used.
native_socket The new underlying socket implementation.
Exceptions:
asio::system_error Thrown on failure.


Member Function Documentation

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send ( const ConstBufferSequence &  buffers  ) 

Send some data on a connected socket.

This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One ore more data buffers to be sent on the socket.
Returns:
The number of bytes sent.
Exceptions:
asio::system_error Thrown on failure.
Note:
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.
Example
To send a single data buffer use the asio::buffer function as follows:
 socket.send(asio::buffer(data, size)); 
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags 
)

Send some data on a connected socket.

This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One ore more data buffers to be sent on the socket.
flags Flags specifying how the send call is to be made.
Returns:
The number of bytes sent.
Exceptions:
asio::system_error Thrown on failure.
Note:
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags,
asio::error_code ec 
)

Send some data on a connected socket.

This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent on the socket.
flags Flags specifying how the send call is to be made.
ec Set to indicate what error occurred, if any.
Returns:
The number of bytes sent.
Note:
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence, typename WriteHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send ( const ConstBufferSequence &  buffers,
WriteHandler  handler 
)

Start an asynchronous send on a connected socket.

This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent on the socket. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handler The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes sent.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note:
The async_send operation can only be used with a connected socket. Use the async_send_to function to send data on an unconnected datagram socket.
Example
To send a single data buffer use the asio::buffer function as follows:
 socket.async_send(asio::buffer(data, size), handler);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence, typename WriteHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags,
WriteHandler  handler 
)

Start an asynchronous send on a connected socket.

This function is used to send data on the datagram socket. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent on the socket. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
flags Flags specifying how the send call is to be made.
handler The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes sent.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note:
The async_send operation can only be used with a connected socket. Use the async_send_to function to send data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to ( const ConstBufferSequence &  buffers,
const endpoint_type destination 
)

Send a datagram to the specified endpoint.

This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent to the remote endpoint.
destination The remote endpoint to which the data will be sent.
Returns:
The number of bytes sent.
Exceptions:
asio::system_error Thrown on failure.
Example
To send a single data buffer use the asio::buffer function as follows:
 asio::ip::udp::endpoint destination(
     asio::ip::address::from_string("1.2.3.4"), 12345);
 socket.send_to(asio::buffer(data, size), destination);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to ( const ConstBufferSequence &  buffers,
const endpoint_type destination,
socket_base::message_flags  flags 
)

Send a datagram to the specified endpoint.

This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent to the remote endpoint.
destination The remote endpoint to which the data will be sent.
flags Flags specifying how the send call is to be made.
Returns:
The number of bytes sent.
Exceptions:
asio::system_error Thrown on failure.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::send_to ( const ConstBufferSequence &  buffers,
const endpoint_type destination,
socket_base::message_flags  flags,
asio::error_code ec 
)

Send a datagram to the specified endpoint.

This function is used to send a datagram to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.

Parameters:
buffers One or more data buffers to be sent to the remote endpoint.
destination The remote endpoint to which the data will be sent.
flags Flags specifying how the send call is to be made.
ec Set to indicate what error occurred, if any.
Returns:
The number of bytes sent.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence, typename WriteHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send_to ( const ConstBufferSequence &  buffers,
const endpoint_type destination,
WriteHandler  handler 
)

Start an asynchronous send.

This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.

Parameters:
buffers One or more data buffers to be sent to the remote endpoint. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
destination The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
handler The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes sent.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To send a single data buffer use the asio::buffer function as follows:
 asio::ip::udp::endpoint destination(
     asio::ip::address::from_string("1.2.3.4"), 12345);
 socket.async_send_to(
     asio::buffer(data, size), destination, handler);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename ConstBufferSequence, typename WriteHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_send_to ( const ConstBufferSequence &  buffers,
const endpoint_type destination,
socket_base::message_flags  flags,
WriteHandler  handler 
)

Start an asynchronous send.

This function is used to asynchronously send a datagram to the specified remote endpoint. The function call always returns immediately.

Parameters:
buffers One or more data buffers to be sent to the remote endpoint. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
flags Flags specifying how the send call is to be made.
destination The remote endpoint to which the data will be sent. Copies will be made of the endpoint as required.
handler The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes sent.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive ( const MutableBufferSequence &  buffers  ) 

Receive some data on a connected socket.

This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
Returns:
The number of bytes received.
Exceptions:
asio::system_error Thrown on failure.
Note:
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.
Example
To receive into a single data buffer use the asio::buffer function as follows:
 socket.receive(asio::buffer(data, size)); 
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags 
)

Receive some data on a connected socket.

This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
flags Flags specifying how the receive call is to be made.
Returns:
The number of bytes received.
Exceptions:
asio::system_error Thrown on failure.
Note:
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags,
asio::error_code ec 
)

Receive some data on a connected socket.

This function is used to receive data on the datagram socket. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
flags Flags specifying how the receive call is to be made.
ec Set to indicate what error occurred, if any.
Returns:
The number of bytes received.
Note:
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence, typename ReadHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive ( const MutableBufferSequence &  buffers,
ReadHandler  handler 
)

Start an asynchronous receive on a connected socket.

This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.

Parameters:
buffers One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
handler The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes received.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note:
The async_receive operation can only be used with a connected socket. Use the async_receive_from function to receive data on an unconnected datagram socket.
Example
To receive into a single data buffer use the asio::buffer function as follows:
 socket.async_receive(asio::buffer(data, size), handler);
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence, typename ReadHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags,
ReadHandler  handler 
)

Start an asynchronous receive on a connected socket.

This function is used to asynchronously receive data from the datagram socket. The function call always returns immediately.

Parameters:
buffers One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
flags Flags specifying how the receive call is to be made.
handler The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes received.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Note:
The async_receive operation can only be used with a connected socket. Use the async_receive_from function to receive data on an unconnected datagram socket.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from ( const MutableBufferSequence &  buffers,
endpoint_type sender_endpoint 
)

Receive a datagram with the endpoint of the sender.

This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
sender_endpoint An endpoint object that receives the endpoint of the remote sender of the datagram.
Returns:
The number of bytes received.
Exceptions:
asio::system_error Thrown on failure.
Example
To receive into a single data buffer use the asio::buffer function as follows:
 asio::ip::udp::endpoint sender_endpoint;
 socket.receive_from(
     asio::buffer(data, size), sender_endpoint);
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from ( const MutableBufferSequence &  buffers,
endpoint_type sender_endpoint,
socket_base::message_flags  flags 
)

Receive a datagram with the endpoint of the sender.

This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
sender_endpoint An endpoint object that receives the endpoint of the remote sender of the datagram.
flags Flags specifying how the receive call is to be made.
Returns:
The number of bytes received.
Exceptions:
asio::system_error Thrown on failure.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence>
std::size_t asio::basic_datagram_socket< Protocol, DatagramSocketService >::receive_from ( const MutableBufferSequence &  buffers,
endpoint_type sender_endpoint,
socket_base::message_flags  flags,
asio::error_code ec 
)

Receive a datagram with the endpoint of the sender.

This function is used to receive a datagram. The function call will block until data has been received successfully or an error occurs.

Parameters:
buffers One or more buffers into which the data will be received.
sender_endpoint An endpoint object that receives the endpoint of the remote sender of the datagram.
flags Flags specifying how the receive call is to be made.
ec Set to indicate what error occurred, if any.
Returns:
The number of bytes received.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence, typename ReadHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive_from ( const MutableBufferSequence &  buffers,
endpoint_type sender_endpoint,
ReadHandler  handler 
)

Start an asynchronous receive.

This function is used to asynchronously receive a datagram. The function call always returns immediately.

Parameters:
buffers One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
sender_endpoint An endpoint object that receives the endpoint of the remote sender of the datagram. Ownership of the sender_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called.
handler The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::system_error& error, // Result of operation.
   std::size_t bytes_transferred             // Number of bytes received.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
To receive into a single data buffer use the asio::buffer function as follows:
 socket.async_receive_from(
     asio::buffer(data, size), 0, sender_endpoint, handler); 
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename DatagramSocketService = datagram_socket_service<Protocol>>
template<typename MutableBufferSequence, typename ReadHandler>
void asio::basic_datagram_socket< Protocol, DatagramSocketService >::async_receive_from ( const MutableBufferSequence &  buffers,
endpoint_type sender_endpoint,
socket_base::message_flags  flags,
ReadHandler  handler 
)

Start an asynchronous receive.

This function is used to asynchronously receive a datagram. The function call always returns immediately.

Parameters:
buffers One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
sender_endpoint An endpoint object that receives the endpoint of the remote sender of the datagram. Ownership of the sender_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called.
flags Flags specifying how the receive call is to be made.
handler The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error, // Result of operation.
   std::size_t bytes_transferred           // Number of bytes received.
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().

lowest_layer_type& asio::basic_socket< Protocol , DatagramSocketService >::lowest_layer (  )  [inherited]

Get a reference to the lowest layer.

This function returns a reference to the lowest layer in a stack of layers. Since a basic_socket cannot contain any further layers, it simply returns a reference to itself.

Returns:
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.

void asio::basic_socket< Protocol , DatagramSocketService >::open ( const protocol_type protocol = protocol_type()  )  [inherited]

Open the socket using the specified protocol.

This function opens the socket so that it will use the specified protocol.

Parameters:
protocol An object specifying protocol parameters to be used.
Exceptions:
asio::system_error Thrown on failure.
Example

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::open ( const protocol_type protocol,
asio::error_code ec 
) [inherited]

Open the socket using the specified protocol.

This function opens the socket so that it will use the specified protocol.

Parameters:
protocol An object specifying which protocol is to be used.
ec Set to indicate what error occurred, if any.
Example
 asio::ip::tcp::socket socket(io_service);
 asio::error_code ec;
 socket.open(asio::ip::tcp::v4(), ec);
 if (ec)
 {
   // An error occurred.
 }

void asio::basic_socket< Protocol , DatagramSocketService >::assign ( const protocol_type protocol,
const native_type native_socket 
) [inherited]

Assign an existing native socket to the socket.

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::assign ( const protocol_type protocol,
const native_type native_socket,
asio::error_code ec 
) [inherited]

Assign an existing native socket to the socket.

bool asio::basic_socket< Protocol , DatagramSocketService >::is_open (  )  const [inherited]

Determine whether the socket is open.

void asio::basic_socket< Protocol , DatagramSocketService >::close (  )  [inherited]

Close the socket.

This function is used to close the socket. Any asynchronous send, receive or connect operations will be cancelled immediately, and will complete with the asio::error::operation_aborted error.

Exceptions:
asio::system_error Thrown on failure.

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::close ( asio::error_code ec  )  [inherited]

Close the socket.

This function is used to close the socket. Any asynchronous send, receive or connect operations will be cancelled immediately, and will complete with the asio::error::operation_aborted error.

Parameters:
ec Set to indicate what error occurred, if any.
Example
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::error_code ec;
 socket.close(ec);
 if (ec)
 {
   // An error occurred.
 }

native_type asio::basic_socket< Protocol , DatagramSocketService >::native (  )  [inherited]

Get the native socket representation.

This function may be used to obtain the underlying representation of the socket. This is intended to allow access to native socket functionality that is not otherwise provided.

void asio::basic_socket< Protocol , DatagramSocketService >::cancel (  )  [inherited]

Cancel all asynchronous operations associated with the socket.

This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the asio::error::operation_aborted error.

Exceptions:
asio::system_error Thrown on failure.

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::cancel ( asio::error_code ec  )  [inherited]

Cancel all asynchronous operations associated with the socket.

This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the asio::error::operation_aborted error.

Parameters:
ec Set to indicate what error occurred, if any.

bool asio::basic_socket< Protocol , DatagramSocketService >::at_mark (  )  const [inherited]

Determine whether the socket is at the out-of-band data mark.

This function is used to check whether the socket input is currently positioned at the out-of-band data mark.

Returns:
A bool indicating whether the socket is at the out-of-band data mark.
Exceptions:
asio::system_error Thrown on failure.

bool asio::basic_socket< Protocol , DatagramSocketService >::at_mark ( asio::error_code ec  )  const [inherited]

Determine whether the socket is at the out-of-band data mark.

This function is used to check whether the socket input is currently positioned at the out-of-band data mark.

Parameters:
ec Set to indicate what error occurred, if any.
Returns:
A bool indicating whether the socket is at the out-of-band data mark.

std::size_t asio::basic_socket< Protocol , DatagramSocketService >::available (  )  const [inherited]

Determine the number of bytes available for reading.

This function is used to determine the number of bytes that may be read without blocking.

Returns:
The number of bytes that may be read without blocking, or 0 if an error occurs.
Exceptions:
asio::system_error Thrown on failure.

std::size_t asio::basic_socket< Protocol , DatagramSocketService >::available ( asio::error_code ec  )  const [inherited]

Determine the number of bytes available for reading.

This function is used to determine the number of bytes that may be read without blocking.

Parameters:
ec Set to indicate what error occurred, if any.
Returns:
The number of bytes that may be read without blocking, or 0 if an error occurs.

void asio::basic_socket< Protocol , DatagramSocketService >::bind ( const endpoint_type endpoint  )  [inherited]

Bind the socket to the given local endpoint.

This function binds the socket to the specified endpoint on the local machine.

Parameters:
endpoint An endpoint on the local machine to which the socket will be bound.
Exceptions:
asio::system_error Thrown on failure.
Example

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::bind ( const endpoint_type endpoint,
asio::error_code ec 
) [inherited]

Bind the socket to the given local endpoint.

This function binds the socket to the specified endpoint on the local machine.

Parameters:
endpoint An endpoint on the local machine to which the socket will be bound.
ec Set to indicate what error occurred, if any.
Example
 asio::ip::tcp::socket socket(io_service);
 socket.open(asio::ip::tcp::v4());
 asio::error_code ec;
 socket.bind(asio::ip::tcp::endpoint(
       asio::ip::tcp::v4(), 12345), ec);
 if (ec)
 {
   // An error occurred.
 }

void asio::basic_socket< Protocol , DatagramSocketService >::connect ( const endpoint_type peer_endpoint  )  [inherited]

Connect the socket to the specified endpoint.

This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.

The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is returned to the closed state.

Parameters:
peer_endpoint The remote endpoint to which the socket will be connected.
Exceptions:
asio::system_error Thrown on failure.
Example
 asio::ip::tcp::socket socket(io_service);
 asio::ip::tcp::endpoint endpoint(
     asio::ip::address::from_string("1.2.3.4"), 12345);
 socket.connect(endpoint);

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::connect ( const endpoint_type peer_endpoint,
asio::error_code ec 
) [inherited]

Connect the socket to the specified endpoint.

This function is used to connect a socket to the specified remote endpoint. The function call will block until the connection is successfully made or an error occurs.

The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is returned to the closed state.

Parameters:
peer_endpoint The remote endpoint to which the socket will be connected.
ec Set to indicate what error occurred, if any.
Example
 asio::ip::tcp::socket socket(io_service);
 asio::ip::tcp::endpoint endpoint(
     asio::ip::address::from_string("1.2.3.4"), 12345);
 asio::error_code ec;
 socket.connect(endpoint, ec);
 if (ec)
 {
   // An error occurred.
 }

void asio::basic_socket< Protocol , DatagramSocketService >::async_connect ( const endpoint_type peer_endpoint,
ConnectHandler  handler 
) [inherited]

Start an asynchronous connect.

This function is used to asynchronously connect a socket to the specified remote endpoint. The function call always returns immediately.

The socket is automatically opened if it is not already open. If the connect fails, and the socket was automatically opened, the socket is returned to the closed state.

Parameters:
peer_endpoint The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
handler The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
 void handler(
   const asio::error_code& error // Result of operation
 ); 
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
 void connect_handler(const asio::error_code& error)
 {
   if (!error)
   {
     // Connect succeeded.
   }
 }

 ...

 asio::ip::tcp::socket socket(io_service);
 asio::ip::tcp::endpoint endpoint(
     asio::ip::address::from_string("1.2.3.4"), 12345);
 socket.async_connect(endpoint, connect_handler);

void asio::basic_socket< Protocol , DatagramSocketService >::set_option ( const SettableSocketOption &  option  )  [inherited]

Set an option on the socket.

This function is used to set an option on the socket.

Parameters:
option The new option value to be set on the socket.
Exceptions:
asio::system_error Thrown on failure.
See also:
SettableSocketOption
asio::socket_base::broadcast
asio::socket_base::do_not_route
asio::socket_base::keep_alive
asio::socket_base::linger
asio::socket_base::receive_buffer_size
asio::socket_base::receive_low_watermark
asio::socket_base::reuse_address
asio::socket_base::send_buffer_size
asio::socket_base::send_low_watermark
asio::ip::multicast::join_group
asio::ip::multicast::leave_group
asio::ip::multicast::enable_loopback
asio::ip::multicast::outbound_interface
asio::ip::multicast::hops
asio::ip::tcp::no_delay
Example
Setting the IPPROTO_TCP/TCP_NODELAY option:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::no_delay option(true);
 socket.set_option(option);

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::set_option ( const SettableSocketOption &  option,
asio::error_code ec 
) [inherited]

Set an option on the socket.

This function is used to set an option on the socket.

Parameters:
option The new option value to be set on the socket.
ec Set to indicate what error occurred, if any.
See also:
SettableSocketOption
asio::socket_base::broadcast
asio::socket_base::do_not_route
asio::socket_base::keep_alive
asio::socket_base::linger
asio::socket_base::receive_buffer_size
asio::socket_base::receive_low_watermark
asio::socket_base::reuse_address
asio::socket_base::send_buffer_size
asio::socket_base::send_low_watermark
asio::ip::multicast::join_group
asio::ip::multicast::leave_group
asio::ip::multicast::enable_loopback
asio::ip::multicast::outbound_interface
asio::ip::multicast::hops
asio::ip::tcp::no_delay
Example
Setting the IPPROTO_TCP/TCP_NODELAY option:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::no_delay option(true);
 asio::error_code ec;
 socket.set_option(option, ec);
 if (ec)
 {
   // An error occurred.
 }

void asio::basic_socket< Protocol , DatagramSocketService >::get_option ( GettableSocketOption &  option  )  const [inherited]

Get an option from the socket.

This function is used to get the current value of an option on the socket.

Parameters:
option The option value to be obtained from the socket.
Exceptions:
asio::system_error Thrown on failure.
See also:
GettableSocketOption
asio::socket_base::broadcast
asio::socket_base::do_not_route
asio::socket_base::keep_alive
asio::socket_base::linger
asio::socket_base::receive_buffer_size
asio::socket_base::receive_low_watermark
asio::socket_base::reuse_address
asio::socket_base::send_buffer_size
asio::socket_base::send_low_watermark
asio::ip::multicast::join_group
asio::ip::multicast::leave_group
asio::ip::multicast::enable_loopback
asio::ip::multicast::outbound_interface
asio::ip::multicast::hops
asio::ip::tcp::no_delay
Example
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::socket::keep_alive option;
 socket.get_option(option);
 bool is_set = option.get();

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::get_option ( GettableSocketOption &  option,
asio::error_code ec 
) const [inherited]

Get an option from the socket.

This function is used to get the current value of an option on the socket.

Parameters:
option The option value to be obtained from the socket.
ec Set to indicate what error occurred, if any.
See also:
GettableSocketOption
asio::socket_base::broadcast
asio::socket_base::do_not_route
asio::socket_base::keep_alive
asio::socket_base::linger
asio::socket_base::receive_buffer_size
asio::socket_base::receive_low_watermark
asio::socket_base::reuse_address
asio::socket_base::send_buffer_size
asio::socket_base::send_low_watermark
asio::ip::multicast::join_group
asio::ip::multicast::leave_group
asio::ip::multicast::enable_loopback
asio::ip::multicast::outbound_interface
asio::ip::multicast::hops
asio::ip::tcp::no_delay
Example
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::socket::keep_alive option;
 asio::error_code ec;
 socket.get_option(option, ec);
 if (ec)
 {
   // An error occurred.
 }
 bool is_set = option.get();

void asio::basic_socket< Protocol , DatagramSocketService >::io_control ( IoControlCommand &  command  )  [inherited]

Perform an IO control command on the socket.

This function is used to execute an IO control command on the socket.

Parameters:
command The IO control command to be performed on the socket.
Exceptions:
asio::system_error Thrown on failure.
See also:
IoControlCommand
asio::socket_base::bytes_readable
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::socket::bytes_readable command;
 socket.io_control(command);
 std::size_t bytes_readable = command.get();

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::io_control ( IoControlCommand &  command,
asio::error_code ec 
) [inherited]

Perform an IO control command on the socket.

This function is used to execute an IO control command on the socket.

Parameters:
command The IO control command to be performed on the socket.
ec Set to indicate what error occurred, if any.
See also:
IoControlCommand
asio::socket_base::bytes_readable
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::socket::bytes_readable command;
 asio::error_code ec;
 socket.io_control(command, ec);
 if (ec)
 {
   // An error occurred.
 }
 std::size_t bytes_readable = command.get();

endpoint_type asio::basic_socket< Protocol , DatagramSocketService >::local_endpoint (  )  const [inherited]

Get the local endpoint of the socket.

This function is used to obtain the locally bound endpoint of the socket.

Returns:
An object that represents the local endpoint of the socket.
Exceptions:
asio::system_error Thrown on failure.
Example
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::endpoint endpoint = socket.local_endpoint();

endpoint_type asio::basic_socket< Protocol , DatagramSocketService >::local_endpoint ( asio::error_code ec  )  const [inherited]

Get the local endpoint of the socket.

This function is used to obtain the locally bound endpoint of the socket.

Parameters:
ec Set to indicate what error occurred, if any.
Returns:
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
Example
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::error_code ec;
 asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec);
 if (ec)
 {
   // An error occurred.
 }

endpoint_type asio::basic_socket< Protocol , DatagramSocketService >::remote_endpoint (  )  const [inherited]

Get the remote endpoint of the socket.

This function is used to obtain the remote endpoint of the socket.

Returns:
An object that represents the remote endpoint of the socket.
Exceptions:
asio::system_error Thrown on failure.
Example
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();

endpoint_type asio::basic_socket< Protocol , DatagramSocketService >::remote_endpoint ( asio::error_code ec  )  const [inherited]

Get the remote endpoint of the socket.

This function is used to obtain the remote endpoint of the socket.

Parameters:
ec Set to indicate what error occurred, if any.
Returns:
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
Example
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::error_code ec;
 asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec);
 if (ec)
 {
   // An error occurred.
 }

void asio::basic_socket< Protocol , DatagramSocketService >::shutdown ( shutdown_type  what  )  [inherited]

Disable sends or receives on the socket.

This function is used to disable send operations, receive operations, or both.

Parameters:
what Determines what types of operation will no longer be allowed.
Exceptions:
asio::system_error Thrown on failure.
Example
Shutting down the send side of the socket:

asio::error_code asio::basic_socket< Protocol , DatagramSocketService >::shutdown ( shutdown_type  what,
asio::error_code ec 
) [inherited]

Disable sends or receives on the socket.

This function is used to disable send operations, receive operations, or both.

Parameters:
what Determines what types of operation will no longer be allowed.
ec Set to indicate what error occurred, if any.
Example
Shutting down the send side of the socket:
 asio::ip::tcp::socket socket(io_service);
 ...
 asio::error_code ec;
 socket.shutdown(asio::ip::tcp::socket::shutdown_send, ec);
 if (ec)
 {
   // An error occurred.
 }

asio::io_service& asio::basic_io_object< DatagramSocketService >::io_service (  )  [inherited]

Get the io_service associated with the object.

This function may be used to obtain the io_service object that the I/O object uses to dispatch handlers for asynchronous operations.

Returns:
A reference to the io_service object that the I/O object will use to dispatch handlers. Ownership is not transferred to the caller.


Member Data Documentation

const int asio::socket_base::message_peek = implementation_defined [static, inherited]

Peek at incoming data without removing it from the input queue.

const int asio::socket_base::message_out_of_band = implementation_defined [static, inherited]

Process out-of-band data.

const int asio::socket_base::message_do_not_route = implementation_defined [static, inherited]

Specify that the data should not be subject to routing.

const int asio::socket_base::max_connections = implementation_defined [static, inherited]

The maximum length of the queue of pending incoming connections.

asio 0.3.8rc3 Home | Reference | Tutorial | Examples | Design