| Home | Libraries | People | FAQ | More

# boost::asio::basic_stream_socket< Protocol, Service > Class Template Reference

Inherits boost::asio::basic_socket< Protocol, Service >< Protocol, Service >.

Inheritance diagram for boost::asio::basic_stream_socket< Protocol, Service >:

List of all members.

## Detailed Description

### template<typename Protocol, typename Service = stream_socket_service<Protocol>>
class boost::asio::basic_stream_socket< Protocol, Service >

Provides stream-oriented socket functionality.

The basic_stream_socket class template provides asynchronous and blocking stream-oriented socket functionality.

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

Concepts:
  Async_Read_Stream, Async_Write_Stream, Error_Source, IO_Object, Stream, Sync_Read_Stream, Sync_Write_Stream.

## Public Types

typedef Service::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 boost::asio::error | error_type
| The type used for reporting errors.
typedef basic_socket< Protocol, Service > | lowest_layer_type
| A basic_socket is always the lowest layer.
typedef Service | 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.
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 | 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.
| shutdown_receive = implementation_defined
| Shutdown the receive side of the socket.
| shutdown_send = implementation_defined
| Shutdown the send side of the socket.
| shutdown_both = implementation_defined
| Shutdown both send and receive on the socket.
enum | shutdown_type { shutdown_receive = implementation_defined, shutdown_send = implementation_defined, shutdown_both = implementation_defined }
| Different ways a socket may be shutdown. More...

## Public Member Functions

| basic_stream_socket (boost::asio::io_service &io_service)
| Construct a basic_stream_socket without opening it.
| basic_stream_socket (boost::asio::io_service &io_service, const protocol_type &protocol)
| Construct and open a basic_stream_socket.
| basic_stream_socket (boost::asio::io_service &io_service, const endpoint_type &endpoint)
| Construct a basic_stream_socket, opening it and binding it to the given local endpoint.
| basic_stream_socket (boost::asio::io_service &io_service, const protocol_type &protocol, const native_type &native_socket)
| Construct a basic_stream_socket on an existing native socket.
template<typename Const_Buffers>
std::size_t | send (const Const_Buffers &buffers)
| Send some data on the socket.
template<typename Const_Buffers>
std::size_t | send (const Const_Buffers &buffers, socket_base::message_flags flags)
| Send some data on the socket.
template<typename Const_Buffers, typename Error_Handler>
std::size_t | send (const Const_Buffers &buffers, socket_base::message_flags flags, Error_Handler error_handler)
| Send some data on the socket.
template<typename Const_Buffers, typename Handler>
void | async_send (const Const_Buffers &buffers, Handler handler)
| Start an asynchronous send.
template<typename Const_Buffers, typename Handler>
void | async_send (const Const_Buffers &buffers, socket_base::message_flags flags, Handler handler)
| Start an asynchronous send.
template<typename Mutable_Buffers>
std::size_t | receive (const Mutable_Buffers &buffers)
| Receive some data on the socket.
template<typename Mutable_Buffers>
std::size_t | receive (const Mutable_Buffers &buffers, socket_base::message_flags flags)
| Receive some data on the socket.
template<typename Mutable_Buffers, typename Error_Handler>
std::size_t | receive (const Mutable_Buffers &buffers, socket_base::message_flags flags, Error_Handler error_handler)
| Receive some data on a connected socket.
template<typename Mutable_Buffers, typename Handler>
void | async_receive (const Mutable_Buffers &buffers, Handler handler)
| Start an asynchronous receive.
template<typename Mutable_Buffers, typename Handler>
void | async_receive (const Mutable_Buffers &buffers, socket_base::message_flags flags, Handler handler)
| Start an asynchronous receive.
template<typename Const_Buffers>
std::size_t | write_some (const Const_Buffers &buffers)
| Write some data to the socket.
template<typename Const_Buffers, typename Error_Handler>
std::size_t | write_some (const Const_Buffers &buffers, Error_Handler error_handler)
| Write some data to the socket.
template<typename Const_Buffers, typename Handler>
void | async_write_some (const Const_Buffers &buffers, Handler handler)
| Start an asynchronous write.
template<typename Mutable_Buffers>
std::size_t | read_some (const Mutable_Buffers &buffers)
| Read some data from the socket.
template<typename Mutable_Buffers, typename Error_Handler>
std::size_t | read_some (const Mutable_Buffers &buffers, Error_Handler error_handler)
| Read some data from the socket.
template<typename Mutable_Buffers, typename Handler>
void | async_read_some (const Mutable_Buffers &buffers, Handler handler)
| Start an asynchronous read.
template<typename Mutable_Buffers>
std::size_t | peek (const Mutable_Buffers &buffers)
| Peek at the incoming data on the stream socket.
template<typename Mutable_Buffers, typename Error_Handler>
std::size_t | peek (const Mutable_Buffers &buffers, Error_Handler error_handler)
| Peek at the incoming data on the stream socket.
std::size_t | in_avail ()
| Determine the amount of data that may be read without blocking.
template<typename Error_Handler>
std::size_t | in_avail (Error_Handler error_handler)
| Determine the amount of data that may be read without blocking.
lowest_layer_type & | lowest_layer ()
| Get a reference to the lowest layer.
void | open (const protocol_type &protocol=protocol_type())
| Open the socket using the specified protocol.
template<typename Error_Handler>
void | open (const protocol_type &protocol, Error_Handler error_handler)
| 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.
template<typename Error_Handler>
void | assign (const protocol_type &protocol, const native_type &native_socket, Error_Handler error_handler)
| Assign an existing native socket to the socket.
void | close ()
| Close the socket.
template<typename Error_Handler>
void | close (Error_Handler error_handler)
| Close the socket.
native_type | native ()
| Get the native socket representation.
void | bind (const endpoint_type &endpoint)
| Bind the socket to the given local endpoint.
template<typename Error_Handler>
void | bind (const endpoint_type &endpoint, Error_Handler error_handler)
| Bind the socket to the given local endpoint.
void | connect (const endpoint_type &peer_endpoint)
| Connect the socket to the specified endpoint.
template<typename Error_Handler>
void | connect (const endpoint_type &peer_endpoint, Error_Handler error_handler)
| Connect the socket to the specified endpoint.
template<typename Handler>
void | async_connect (const endpoint_type &peer_endpoint, Handler handler)
| Start an asynchronous connect.
template<typename Socket_Option>
void | set_option (const Socket_Option &option)
| Set an option on the socket.
template<typename Socket_Option, typename Error_Handler>
void | set_option (const Socket_Option &option, Error_Handler error_handler)
| Set an option on the socket.
template<typename Socket_Option>
void | get_option (Socket_Option &option) const
| Get an option from the socket.
template<typename Socket_Option, typename Error_Handler>
void | get_option (Socket_Option &option, Error_Handler error_handler) const
| Get an option from the socket.
template<typename IO_Control_Command>
void | io_control (IO_Control_Command &command)
| Perform an IO control command on the socket.
template<typename IO_Control_Command, typename Error_Handler>
void | io_control (IO_Control_Command &command, Error_Handler error_handler)
| Perform an IO control command on the socket.
endpoint_type | local_endpoint () const
| Get the local endpoint of the socket.
template<typename Error_Handler>
endpoint_type | local_endpoint (Error_Handler error_handler) const
| Get the local endpoint of the socket.
endpoint_type | remote_endpoint () const
| Get the remote endpoint of the socket.
template<typename Error_Handler>
endpoint_type | remote_endpoint (Error_Handler error_handler) const
| Get the remote endpoint of the socket.
void | shutdown (shutdown_type what)
| Disable sends or receives on the socket.
template<typename Error_Handler>
void | shutdown (shutdown_type what, Error_Handler error_handler)
| Disable sends or receives on the socket.
boost::asio::io_service & | io_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.

## Member Typedef Documentation

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

typedef Service::native_type boost::asio::basic_stream_socket< Protocol, Service >::native_type

The native representation of a socket.

Reimplemented from boost::asio::basic_socket< Protocol, Service >.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

typedef Protocol boost::asio::basic_stream_socket< Protocol, Service >::protocol_type

The protocol type.

Reimplemented from boost::asio::basic_socket< Protocol, Service >.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

typedef Protocol::endpoint boost::asio::basic_stream_socket< Protocol, Service >::endpoint_type

The endpoint type.

Reimplemented from boost::asio::basic_socket< Protocol, Service >.

template<typename Protocol, typename Service>

typedef boost::asio::error boost::asio::basic_socket< Protocol, Service >::error_type `[inherited]`

The type used for reporting errors.

template<typename Protocol, typename Service>

typedef basic_socket<Protocol, Service> boost::asio::basic_socket< Protocol, Service >::lowest_layer_type `[inherited]`

A basic_socket is always the lowest layer.

template<typename Service>

typedef Service boost::asio::basic_io_object< Service >::service_type `[inherited]`

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

template<typename Service>

typedef service_type::implementation_type boost::asio::basic_io_object< Service >::implementation_type `[inherited]`

The underlying implementation type of I/O object.

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

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

typedef implementation_defined boost::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:

       boost::asio::ip::udp::socket socket(io_service);
       ...
       boost::asio::socket_base::broadcast option(true);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::udp::socket socket(io_service);
       ...
       boost::asio::socket_base::broadcast option;
       socket.get_option(option);
       bool is_set = option.get();

Concepts:
  Socket_Option, Boolean_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::udp::socket socket(io_service);
       ...
       boost::asio::socket_base::do_not_route option(true);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::udp::socket socket(io_service);
       ...
       boost::asio::socket_base::do_not_route option;
       socket.get_option(option);
       bool is_set = option.get();

Concepts:
  Socket_Option, Boolean_Socket_Option.

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

Socket option to send keep-alives.

Implements the SOL_SOCKET/SO_KEEPALIVE socket option.

Examples:
  Setting the option:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::keep_alive option(true);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::keep_alive option;
       socket.get_option(option);
       bool is_set = option.get();

Concepts:
  Socket_Option, Boolean_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::send_buffer_size option(8192);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::send_buffer_size option;
       socket.get_option(option);
       int size = option.get();

Concepts:
  Socket_Option, Integer_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::send_low_watermark option(1024);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::send_low_watermark option;
       socket.get_option(option);
       int size = option.get();

Concepts:
  Socket_Option, Integer_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::receive_buffer_size option(8192);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::receive_buffer_size option;
       socket.get_option(option);
       int size = option.get();

Concepts:
  Socket_Option, Integer_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::receive_low_watermark option(1024);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::receive_low_watermark option;
       socket.get_option(option);
       int size = option.get();

Concepts:
  Socket_Option, Integer_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::acceptor acceptor(io_service);
       ...
       boost::asio::socket_base::reuse_address option(true);
       acceptor.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::acceptor acceptor(io_service);
       ...
       boost::asio::socket_base::reuse_address option;
       acceptor.get_option(option);
       bool is_set = option.get();

Concepts:
  Socket_Option, Boolean_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::linger option(true, 30);
       socket.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::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 boost::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 boost::asio::error::connection_aborted. By default the option is false.

Examples:
  Setting the option:

       boost::asio::ip::tcp::acceptor acceptor(io_service);
       ...
       boost::asio::socket_base::enable_connection_aborted option(true);
       acceptor.set_option(option);

  Getting the current option value:

       boost::asio::ip::tcp::acceptor acceptor(io_service);
       ...
       boost::asio::socket_base::enable_connection_aborted option;
       acceptor.get_option(option);
       bool is_set = option.get();

Concepts:
  Socket_Option, Boolean_Socket_Option.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::socket_base::non_blocking_io command(true);
       socket.io_control(command);

Concepts:
  IO_Control_Command, Boolean_IO_Control_Command.

typedef implementation_defined boost::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:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::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 boost::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 Service = stream_socket_service<Protocol>>

boost::asio::basic_stream_socket< Protocol, Service >::basic_stream_socket | ( | boost::asio::io_service & | io_service | ) | `[explicit]`

Construct a basic_stream_socket without opening it.

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.

Parameters:

  | io_service | The io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

boost::asio::basic_stream_socket< Protocol, Service >::basic_stream_socket | ( | boost::asio::io_service & | io_service,
|  | const protocol_type & | protocol |
| ) |  |  |

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.

Parameters:

  | io_service | The io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
  | protocol | An object specifying protocol parameters to be used.

Exceptions:

  | boost::asio::error | Thrown on failure.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

boost::asio::basic_stream_socket< Protocol, Service >::basic_stream_socket | ( | boost::asio::io_service & | io_service,
|  | const endpoint_type & | endpoint |
| ) |  |  |

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.

Parameters:

  | io_service | The io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
  | endpoint | An endpoint on the local machine to which the stream socket will be bound.

Exceptions:

  | boost::asio::error | Thrown on failure.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

boost::asio::basic_stream_socket< Protocol, Service >::basic_stream_socket | ( | boost::asio::io_service & | io_service,
|  | const protocol_type & | protocol,
|  | const native_type & | native_socket |
| ) |  |  |

Construct a basic_stream_socket on an existing native socket.

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

Parameters:

  | io_service | The io_service object that the stream 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:

  | boost::asio::error | Thrown on failure.

## Member Function Documentation

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Const_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::send | ( | const Const_Buffers & | buffers | ) |

Send some data on the socket.

This function is used to send data on the stream socket. The function call will block until one or more bytes of the data has been sent successfully, or an until error occurs.

Parameters:

  | buffers | One or more data buffers to be sent on the socket.

Returns:
  The number of bytes sent.

Exceptions:

  | boost::asio::error | Thrown on failure.

Note:
  The send operation may not transmit all of the data to the peer. Consider using the boost::asio::write function if you need to ensure that all data is written before the blocking operation completes.

Example:
  To send a single data buffer use the boost::asio::buffer function as follows:

       socket.send(boost::asio::buffer(data, size));

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Const_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::send | ( | const Const_Buffers & | buffers,
|  | socket_base::message_flags | flags |
| ) |  |  |

Send some data on the socket.

This function is used to send data on the stream socket. The function call will block until one or more bytes of the data has been sent successfully, or an until 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.

Returns:
  The number of bytes sent.

Exceptions:

  | boost::asio::error | Thrown on failure.

Note:
  The send operation may not transmit all of the data to the peer. Consider using the boost::asio::write function if you need to ensure that all data is written before the blocking operation completes.

Example:
  To send a single data buffer use the boost::asio::buffer function as follows:

       socket.send(boost::asio::buffer(data, size), 0);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Const_Buffers, typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::send | ( | const Const_Buffers & | buffers,
|  | socket_base::message_flags | flags,
|  | Error_Handler | error_handler |
| ) |  |  |

Send some data on the socket.

This function is used to send data on the stream socket. The function call will block until one or more bytes of the data has been sent successfully, or an until 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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation.
       );

Returns:
  The number of bytes sent. Returns 0 if an error occurred and the error handler did not throw an exception.

Note:
  The send operation may not transmit all of the data to the peer. Consider using the boost::asio::write function if you need to ensure that all data is written before the blocking operation completes.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Const_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_send | ( | const Const_Buffers & | buffers,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous send.

This function is used to asynchronously send data on the stream socket. The function call always returns immediately.

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 boost::asio::error& 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 boost::asio::io_service::post().

Note:
  The send operation may not transmit all of the data to the peer. Consider using the boost::asio::async_write function if you need to ensure that all data is written before the asynchronous operation completes.

Example:
  To send a single data buffer use the boost::asio::buffer function as follows:

       socket.async_send(boost::asio::buffer(data, size), handler);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Const_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_send | ( | const Const_Buffers & | buffers,
|  | socket_base::message_flags | flags,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous send.

This function is used to asynchronously send data on the stream socket. The function call always returns immediately.

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 boost::asio::error& 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 boost::asio::io_service::post().

Note:
  The send operation may not transmit all of the data to the peer. Consider using the boost::asio::async_write function if you need to ensure that all data is written before the asynchronous operation completes.

Example:
  To send a single data buffer use the boost::asio::buffer function as follows:

       socket.async_send(boost::asio::buffer(data, size), 0, handler);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::receive | ( | const Mutable_Buffers & | buffers | ) |

Receive some data on the socket.

This function is used to receive data on the stream socket. The function call will block until one or more bytes of data has been received successfully, or until an error occurs.

Parameters:

  | buffers | One or more buffers into which the data will be received.

Returns:
  The number of bytes received.

Exceptions:

  | boost::asio::error | Thrown on failure. An error code of boost::asio::error::eof indicates that the connection was closed by the peer.

Note:
  The receive operation may not receive all of the requested number of bytes. Consider using the boost::asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

Example:
  To receive into a single data buffer use the boost::asio::buffer function as follows:

       socket.receive(boost::asio::buffer(data, size));

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::receive | ( | const Mutable_Buffers & | buffers,
|  | socket_base::message_flags | flags |
| ) |  |  |

Receive some data on the socket.

This function is used to receive data on the stream socket. The function call will block until one or more bytes of data has been received successfully, or until 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:

  | boost::asio::error | Thrown on failure. An error code of boost::asio::error::eof indicates that the connection was closed by the peer.

Note:
  The receive operation may not receive all of the requested number of bytes. Consider using the boost::asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

Example:
  To receive into a single data buffer use the boost::asio::buffer function as follows:

       socket.receive(boost::asio::buffer(data, size), 0);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::receive | ( | const Mutable_Buffers & | buffers,
|  | socket_base::message_flags | flags,
|  | Error_Handler | error_handler |
| ) |  |  |

Receive some data on a connected socket.

This function is used to receive data on the stream socket. The function call will block until one or more bytes of data has been received successfully, or until 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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Returns:
  The number of bytes received. Returns 0 if an error occurred and the error handler did not throw an exception.

Note:
  The receive operation may not receive all of the requested number of bytes. Consider using the boost::asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_receive | ( | const Mutable_Buffers & | buffers,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous receive.

This function is used to asynchronously receive data from the stream 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 boost::asio::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 boost::asio::io_service::post().

Note:
  The receive operation may not receive all of the requested number of bytes. Consider using the boost::asio::async_read function if you need to ensure that the requested amount of data is received before the asynchronous operation completes.

Example:
  To receive into a single data buffer use the boost::asio::buffer function as follows:

       socket.async_receive(boost::asio::buffer(data, size), handler);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_receive | ( | const Mutable_Buffers & | buffers,
|  | socket_base::message_flags | flags,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous receive.

This function is used to asynchronously receive data from the stream 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 boost::asio::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 boost::asio::io_service::post().

Note:
  The receive operation may not receive all of the requested number of bytes. Consider using the boost::asio::async_read function if you need to ensure that the requested amount of data is received before the asynchronous operation completes.

Example:
  To receive into a single data buffer use the boost::asio::buffer function as follows:

       socket.async_receive(boost::asio::buffer(data, size), 0, handler);

  See the boost::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 Service = stream_socket_service<Protocol>>
template<typename Const_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::write_some | ( | const Const_Buffers & | buffers | ) |

Write some data to the socket.

This function is used to write data to the stream socket. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.

Parameters:

  | buffers | One or more data buffers to be written to the socket.

Returns:
  The number of bytes written.

Exceptions:

  | boost::asio::error | Thrown on failure. An error code of boost::asio::error::eof indicates that the connection was closed by the peer.

Note:
  The write_some operation may not transmit all of the data to the peer. Consider using the boost::asio::write function if you need to ensure that all data is written before the blocking operation completes.

Example:
  To write a single data buffer use the boost::asio::buffer function as follows:

       socket.write_some(boost::asio::buffer(data, size));

  See the boost::asio::buffer documentation for information on writing multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Const_Buffers, typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::write_some | ( | const Const_Buffers & | buffers,
|  | Error_Handler | error_handler |
| ) |  |  |

Write some data to the socket.

This function is used to write data to the stream socket. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.

Parameters:

  | buffers | One or more data buffers to be written to the socket.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation.
       );

Returns:
  The number of bytes written. Returns 0 if an error occurred and the error handler did not throw an exception.

Note:
  The write_some operation may not transmit all of the data to the peer. Consider using the boost::asio::write function if you need to ensure that all data is written before the blocking operation completes.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Const_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_write_some | ( | const Const_Buffers & | buffers,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous write.

This function is used to asynchronously write data to the stream socket. The function call always returns immediately.

Parameters:

  | buffers | One or more data buffers to be written to 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 write operation completes. Copies will be made of the handler as required. The function signature of the handler must be:

       void handler(
         const boost::asio::error& error,     // Result of operation.
         std::size_t bytes_transferred // Number of bytes written.
       );

  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 boost::asio::io_service::post().

Note:
  The write operation may not transmit all of the data to the peer. Consider using the boost::asio::async_write function if you need to ensure that all data is written before the asynchronous operation completes.

Example:
  To write a single data buffer use the boost::asio::buffer function as follows:

       socket.async_write_some(boost::asio::buffer(data, size), handler);

  See the boost::asio::buffer documentation for information on writing multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::read_some | ( | const Mutable_Buffers & | buffers | ) |

Read some data from the socket.

This function is used to read data from the stream socket. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters:

  | buffers | One or more buffers into which the data will be read.

Returns:
  The number of bytes read.

Exceptions:

  | boost::asio::error | Thrown on failure. An error code of boost::asio::error::eof indicates that the connection was closed by the peer.

Note:
  The read_some operation may not read all of the requested number of bytes. Consider using the boost::asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

Example:
  To read into a single data buffer use the boost::asio::buffer function as follows:

       socket.read_some(boost::asio::buffer(data, size));

  See the boost::asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::read_some | ( | const Mutable_Buffers & | buffers,
|  | Error_Handler | error_handler |
| ) |  |  |

Read some data from the socket.

This function is used to read data from the stream socket. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.

Parameters:

  | buffers | One or more buffers into which the data will be read.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation.
       );

Returns:
  The number of bytes read. Returns 0 if an error occurred and the error handler did not throw an exception.

Note:
  The read_some operation may not read all of the requested number of bytes. Consider using the boost::asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Handler>

void boost::asio::basic_stream_socket< Protocol, Service >::async_read_some | ( | const Mutable_Buffers & | buffers,
|  | Handler | handler |
| ) |  |  |

Start an asynchronous read.

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

Parameters:

  | buffers | One or more buffers into which the data will be read. 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 read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:

       void handler(
         const boost::asio::error& error,     // Result of operation.
         std::size_t bytes_transferred // Number of bytes read.
       );

  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 boost::asio::io_service::post().

Note:
  The read operation may not read all of the requested number of bytes. Consider using the boost::asio::async_read function if you need to ensure that the requested amount of data is read before the asynchronous operation completes.

Example:
  To read into a single data buffer use the boost::asio::buffer function as follows:

       socket.async_read_some(boost::asio::buffer(data, size), handler);

  See the boost::asio::buffer documentation for information on reading into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::peek | ( | const Mutable_Buffers & | buffers | ) |

Peek at the incoming data on the stream socket.

This function is used to peek at the incoming data on the stream socket, without removing it from the input queue. The function call will block until data has been read successfully or an error occurs.

Parameters:

  | buffers | One or more buffers into which the data will be read.

Returns:
  The number of bytes read.

Exceptions:

  | boost::asio::error | Thrown on failure.

Example:
  To peek using a single data buffer use the boost::asio::buffer function as follows:

       socket.peek(boost::asio::buffer(data, size));

  See the boost::asio::buffer documentation for information on using multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Mutable_Buffers, typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::peek | ( | const Mutable_Buffers & | buffers,
|  | Error_Handler | error_handler |
| ) |  |  |

Peek at the incoming data on the stream socket.

This function is used to peek at the incoming data on the stream socket, without removing it from the input queue. The function call will block until data has been read successfully or an error occurs.

Parameters:

  | buffers | One or more buffers into which the data will be read.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation.
       );

Returns:
  The number of bytes read. Returns 0 if an error occurred and the error handler did not throw an exception.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::in_avail | ( |  | ) |

Determine the amount of data that may be read without blocking.

This function is used to determine the amount of data, in bytes, that may be read from the stream socket without blocking.

Returns:
  The number of bytes of data that can be read without blocking.

Exceptions:

  | boost::asio::error | Thrown on failure.

template<typename Protocol, typename Service = stream_socket_service<Protocol>>
template<typename Error_Handler>

std::size_t boost::asio::basic_stream_socket< Protocol, Service >::in_avail | ( | Error_Handler | error_handler | ) |

Determine the amount of data that may be read without blocking.

This function is used to determine the amount of data, in bytes, that may be read from the stream socket without blocking.

Parameters:

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Returns:
  The number of bytes of data that can be read without blocking.

template<typename Protocol, typename Service>

lowest_layer_type& boost::asio::basic_socket< Protocol, Service >::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.

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       socket.open(boost::asio::ip::tcp::v4());

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::open | ( | const protocol_type & | protocol,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       boost::asio::error error;
       socket.open(boost::asio::ip::tcp::v4(), boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::assign | ( | const protocol_type & | protocol,
|  | const native_type & | native_socket |
| ) |  |  | `[inherited]`

Assign an existing native socket to the socket.

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::assign | ( | const protocol_type & | protocol,
|  | const native_type & | native_socket,
|  | Error_Handler | error_handler |
| ) |  |  | `[inherited]`

Assign an existing native socket to the socket.

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::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 boost::asio::error::operation_aborted error.

Exceptions:

  | boost::asio::error | Thrown on failure.

Reimplemented in boost::asio::basic_socketbuf< Protocol, Service >.

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::close | ( | Error_Handler | error_handler | ) | `[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 boost::asio::error::operation_aborted error.

Parameters:

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::error error;
       socket.close(boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>

native_type boost::asio::basic_socket< Protocol, Service >::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.

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       socket.open(boost::asio::ip::tcp::v4());
       socket.bind(boost::asio::ip::tcp::endpoint(
             boost::asio::ip::tcp::v4(), 12345));

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::bind | ( | const endpoint_type & | endpoint,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       socket.open(boost::asio::ip::tcp::v4());
       boost::asio::error error;
       socket.bind(boost::asio::ip::tcp::endpoint(
             boost::asio::ip::tcp::v4(), 12345),
           boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:

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

Reimplemented in boost::asio::basic_socketbuf< Protocol, Service >.

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::connect | ( | const endpoint_type & | peer_endpoint,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       boost::asio::ip::tcp::endpoint endpoint(
           boost::asio::ip::address::from_string("1.2.3.4"), 12345);
       boost::asio::error error;
       socket.connect(endpoint, boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>
template<typename Handler>

void boost::asio::basic_socket< Protocol, Service >::async_connect | ( | const endpoint_type & | peer_endpoint,
|  | Handler | 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 boost::asio::error& 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 boost::asio::io_service::post().

Example:

       void connect_handler(const boost::asio::error& error)
       {
         if (!error)
         {
           // Connect succeeded.
         }
       }

       ...

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

template<typename Protocol, typename Service>
template<typename Socket_Option>

void boost::asio::basic_socket< Protocol, Service >::set_option | ( | const Socket_Option & | 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:

  | boost::asio::error | Thrown on failure.

See also:
  Socket_Option
  boost::asio::socket_base::broadcast
  boost::asio::socket_base::do_not_route
  boost::asio::socket_base::keep_alive
  boost::asio::socket_base::linger
  boost::asio::socket_base::receive_buffer_size
  boost::asio::socket_base::receive_low_watermark
  boost::asio::socket_base::reuse_address
  boost::asio::socket_base::send_buffer_size
  boost::asio::socket_base::send_low_watermark
  boost::asio::ip::multicast::join_group
  boost::asio::ip::multicast::leave_group
  boost::asio::ip::multicast::enable_loopback
  boost::asio::ip::multicast::outbound_interface
  boost::asio::ip::multicast::hops
  boost::asio::ip::tcp::no_delay

Example:
  Setting the IPPROTO_TCP/TCP_NODELAY option:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::no_delay option(true);
       socket.set_option(option);

template<typename Protocol, typename Service>
template<typename Socket_Option, typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::set_option | ( | const Socket_Option & | option,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

See also:
  Socket_Option
  boost::asio::socket_base::broadcast
  boost::asio::socket_base::do_not_route
  boost::asio::socket_base::keep_alive
  boost::asio::socket_base::linger
  boost::asio::socket_base::receive_buffer_size
  boost::asio::socket_base::receive_low_watermark
  boost::asio::socket_base::reuse_address
  boost::asio::socket_base::send_buffer_size
  boost::asio::socket_base::send_low_watermark
  boost::asio::ip::multicast::join_group
  boost::asio::ip::multicast::leave_group
  boost::asio::ip::multicast::enable_loopback
  boost::asio::ip::multicast::outbound_interface
  boost::asio::ip::multicast::hops
  boost::asio::ip::tcp::no_delay

Example:
  Setting the IPPROTO_TCP/TCP_NODELAY option:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::no_delay option(true);
       boost::asio::error error;
       socket.set_option(option, boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>
template<typename Socket_Option>

void boost::asio::basic_socket< Protocol, Service >::get_option | ( | Socket_Option & | 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:

  | boost::asio::error | Thrown on failure.

See also:
  Socket_Option
  boost::asio::socket_base::broadcast
  boost::asio::socket_base::do_not_route
  boost::asio::socket_base::keep_alive
  boost::asio::socket_base::linger
  boost::asio::socket_base::receive_buffer_size
  boost::asio::socket_base::receive_low_watermark
  boost::asio::socket_base::reuse_address
  boost::asio::socket_base::send_buffer_size
  boost::asio::socket_base::send_low_watermark
  boost::asio::ip::multicast::join_group
  boost::asio::ip::multicast::leave_group
  boost::asio::ip::multicast::enable_loopback
  boost::asio::ip::multicast::outbound_interface
  boost::asio::ip::multicast::hops
  boost::asio::ip::tcp::no_delay

Example:
  Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::socket::keep_alive option;
       socket.get_option(option);
       bool is_set = option.get();

template<typename Protocol, typename Service>
template<typename Socket_Option, typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::get_option | ( | Socket_Option & | option,
|  | Error_Handler | error_handler |
| ) |  |  | 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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

See also:
  Socket_Option
  boost::asio::socket_base::broadcast
  boost::asio::socket_base::do_not_route
  boost::asio::socket_base::keep_alive
  boost::asio::socket_base::linger
  boost::asio::socket_base::receive_buffer_size
  boost::asio::socket_base::receive_low_watermark
  boost::asio::socket_base::reuse_address
  boost::asio::socket_base::send_buffer_size
  boost::asio::socket_base::send_low_watermark
  boost::asio::ip::multicast::join_group
  boost::asio::ip::multicast::leave_group
  boost::asio::ip::multicast::enable_loopback
  boost::asio::ip::multicast::outbound_interface
  boost::asio::ip::multicast::hops
  boost::asio::ip::tcp::no_delay

Example:
  Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::socket::keep_alive option;
       boost::asio::error error;
       socket.get_option(option, boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }
       bool is_set = option.get();

template<typename Protocol, typename Service>
template<typename IO_Control_Command>

void boost::asio::basic_socket< Protocol, Service >::io_control | ( | IO_Control_Command & | 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:

  | boost::asio::error | Thrown on failure.

See also:
  IO_Control_Command
  boost::asio::socket_base::bytes_readable
  boost::asio::socket_base::non_blocking_io

Example:
  Getting the number of bytes ready to read:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::socket::bytes_readable command;
       socket.io_control(command);
       std::size_t bytes_readable = command.get();

template<typename Protocol, typename Service>
template<typename IO_Control_Command, typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::io_control | ( | IO_Control_Command & | command,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

See also:
  IO_Control_Command
  boost::asio::socket_base::bytes_readable
  boost::asio::socket_base::non_blocking_io

Example:
  Getting the number of bytes ready to read:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::socket::bytes_readable command;
       boost::asio::error error;
       socket.io_control(command, boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }
       std::size_t bytes_readable = command.get();

template<typename Protocol, typename Service>

endpoint_type boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();

template<typename Protocol, typename Service>
template<typename Error_Handler>

endpoint_type boost::asio::basic_socket< Protocol, Service >::local_endpoint | ( | Error_Handler | error_handler | ) | const`[inherited]`

Get the local endpoint of the socket.

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

Parameters:

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Returns:
  An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred and the error handler did not throw an exception.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::error error;
       boost::asio::ip::tcp::endpoint endpoint
         = socket.local_endpoint(boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>

endpoint_type boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();

template<typename Protocol, typename Service>
template<typename Error_Handler>

endpoint_type boost::asio::basic_socket< Protocol, Service >::remote_endpoint | ( | Error_Handler | error_handler | ) | const`[inherited]`

Get the remote endpoint of the socket.

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

Parameters:

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Returns:
  An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred and the error handler did not throw an exception.

Example:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::error error;
       boost::asio::ip::tcp::endpoint endpoint
         = socket.remote_endpoint(boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Protocol, typename Service>

void boost::asio::basic_socket< Protocol, Service >::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:

  | boost::asio::error | Thrown on failure.

Example:
  Shutting down the send side of the socket:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);

template<typename Protocol, typename Service>
template<typename Error_Handler>

void boost::asio::basic_socket< Protocol, Service >::shutdown | ( | shutdown_type | what,
|  | Error_Handler | error_handler |
| ) |  |  | `[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.

  error_handler

  A handler to be called when the operation completes, to indicate whether or not an error has occurred. Copies will be made of the handler as required. The function signature of the handler must be:

       void error_handler(
         const boost::asio::error& error // Result of operation
       );

Example:
  Shutting down the send side of the socket:

       boost::asio::ip::tcp::socket socket(io_service);
       ...
       boost::asio::error error;
       socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send,
           boost::asio::assign_error(error));
       if (error)
       {
         // An error occurred.
       }

template<typename Service>

boost::asio::io_service& boost::asio::basic_io_object< Service >::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 boost::asio::socket_base::message_peek = implementation_defined`[static, inherited]`

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

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

Process out-of-band data.

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

Specify that the data should not be subject to routing.

| Copyright © 2003 - 2006 Christopher M. Kohlhoff