Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::asio::basic_stream_socket< Protocol, StreamSocketService > Class Template Reference

Provides stream-oriented socket functionality. More...

#include <basic_stream_socket.hpp>

Inheritance diagram for boost::asio::basic_stream_socket< Protocol, StreamSocketService >:
Collaboration diagram for boost::asio::basic_stream_socket< Protocol, StreamSocketService >:

Public Types

typedef
StreamSocketService::native_handle_type 
native_type
 (Deprecated: Use native_handle_type.) The native representation of a socket. More...
 
typedef
StreamSocketService::native_handle_type 
native_handle_type
 The native representation of a socket. More...
 
typedef Protocol protocol_type
 The protocol type. More...
 
typedef Protocol::endpoint endpoint_type
 The endpoint type. More...
 
typedef basic_socket< Protocol,
StreamSocketService > 
lowest_layer_type
 A basic_socket is always the lowest layer. More...
 
typedef StreamSocketService service_type
 The type of the service that will be used to provide I/O operations. More...
 
typedef
service_type::implementation_type 
implementation_type
 The underlying implementation type of I/O object. More...
 
enum  shutdown_type {
  shutdown_receive = BOOST_ASIO_OS_DEF(SHUT_RD),
  shutdown_send = BOOST_ASIO_OS_DEF(SHUT_WR),
  shutdown_both = BOOST_ASIO_OS_DEF(SHUT_RDWR)
}
 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. More...
 
typedef
boost::asio::detail::socket_option::boolean
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_BROADCAST)> 
broadcast
 Socket option to permit sending of broadcast messages. More...
 
typedef
boost::asio::detail::socket_option::boolean
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_DEBUG)> 
debug
 Socket option to enable socket-level debugging. More...
 
typedef
boost::asio::detail::socket_option::boolean
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_DONTROUTE)> 
do_not_route
 Socket option to prevent routing, use local interfaces only. More...
 
typedef
boost::asio::detail::socket_option::boolean
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_KEEPALIVE)> 
keep_alive
 Socket option to send keep-alives. More...
 
typedef
boost::asio::detail::socket_option::integer
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_SNDBUF)> 
send_buffer_size
 Socket option for the send buffer size of a socket. More...
 
typedef
boost::asio::detail::socket_option::integer
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_SNDLOWAT)> 
send_low_watermark
 Socket option for the send low watermark. More...
 
typedef
boost::asio::detail::socket_option::integer
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_RCVBUF)> 
receive_buffer_size
 Socket option for the receive buffer size of a socket. More...
 
typedef
boost::asio::detail::socket_option::integer
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_RCVLOWAT)> 
receive_low_watermark
 Socket option for the receive low watermark. More...
 
typedef
boost::asio::detail::socket_option::boolean
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_REUSEADDR)> 
reuse_address
 Socket option to allow the socket to be bound to an address that is already in use. More...
 
typedef
boost::asio::detail::socket_option::linger
< BOOST_ASIO_OS_DEF(SOL_SOCKET),
BOOST_ASIO_OS_DEF(SO_LINGER)> 
linger
 Socket option to specify whether the socket lingers on close if unsent data is present. More...
 
typedef
boost::asio::detail::socket_option::boolean
< boost::asio::detail::custom_socket_option_level,
boost::asio::detail::enable_connection_aborted_option > 
enable_connection_aborted
 Socket option to report aborted connections on accept. More...
 
typedef
boost::asio::detail::io_control::non_blocking_io 
non_blocking_io
 (Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. More...
 
typedef
boost::asio::detail::io_control::bytes_readable 
bytes_readable
 IO control command to get the amount of data that can be read without blocking. More...
 

Public Member Functions

 basic_stream_socket (boost::asio::io_service &io_service)
 Construct a basic_stream_socket without opening it. More...
 
 basic_stream_socket (boost::asio::io_service &io_service, const protocol_type &protocol)
 Construct and open a basic_stream_socket. More...
 
 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. More...
 
 basic_stream_socket (boost::asio::io_service &io_service, const protocol_type &protocol, const native_handle_type &native_socket)
 Construct a basic_stream_socket on an existing native socket. More...
 
template<typename ConstBufferSequence >
std::size_t send (const ConstBufferSequence &buffers)
 Send some data on the socket. More...
 
template<typename ConstBufferSequence >
std::size_t send (const ConstBufferSequence &buffers, socket_base::message_flags flags)
 Send some data on the socket. More...
 
template<typename ConstBufferSequence >
std::size_t send (const ConstBufferSequence &buffers, socket_base::message_flags flags, boost::system::error_code &ec)
 Send some data on the socket. More...
 
template<typename ConstBufferSequence , typename WriteHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (WriteHandler, void(boost::system::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
 Start an asynchronous send. More...
 
 BOOST_ASIO_MOVE_ARG (WriteHandler) handler)
 
template<typename ConstBufferSequence , typename WriteHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (WriteHandler, void(boost::system::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
 Start an asynchronous send. More...
 
socket_base::message_flags BOOST_ASIO_MOVE_ARG (WriteHandler) handler)
 
template<typename MutableBufferSequence >
std::size_t receive (const MutableBufferSequence &buffers)
 Receive some data on the socket. More...
 
template<typename MutableBufferSequence >
std::size_t receive (const MutableBufferSequence &buffers, socket_base::message_flags flags)
 Receive some data on the socket. More...
 
template<typename MutableBufferSequence >
std::size_t receive (const MutableBufferSequence &buffers, socket_base::message_flags flags, boost::system::error_code &ec)
 Receive some data on a connected socket. More...
 
template<typename MutableBufferSequence , typename ReadHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (ReadHandler, void(boost::system::error_code, std::size_t)) async_receive(const MutableBufferSequence &buffers
 Start an asynchronous receive. More...
 
 BOOST_ASIO_MOVE_ARG (ReadHandler) handler)
 
template<typename MutableBufferSequence , typename ReadHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (ReadHandler, void(boost::system::error_code, std::size_t)) async_receive(const MutableBufferSequence &buffers
 Start an asynchronous receive. More...
 
socket_base::message_flags BOOST_ASIO_MOVE_ARG (ReadHandler) handler)
 
template<typename ConstBufferSequence >
std::size_t write_some (const ConstBufferSequence &buffers)
 Write some data to the socket. More...
 
template<typename ConstBufferSequence >
std::size_t write_some (const ConstBufferSequence &buffers, boost::system::error_code &ec)
 Write some data to the socket. More...
 
template<typename ConstBufferSequence , typename WriteHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (WriteHandler, void(boost::system::error_code, std::size_t)) async_write_some(const ConstBufferSequence &buffers
 Start an asynchronous write. More...
 
 BOOST_ASIO_MOVE_ARG (WriteHandler) handler)
 
template<typename MutableBufferSequence >
std::size_t read_some (const MutableBufferSequence &buffers)
 Read some data from the socket. More...
 
template<typename MutableBufferSequence >
std::size_t read_some (const MutableBufferSequence &buffers, boost::system::error_code &ec)
 Read some data from the socket. More...
 
template<typename MutableBufferSequence , typename ReadHandler >
 BOOST_ASIO_INITFN_RESULT_TYPE (ReadHandler, void(boost::system::error_code, std::size_t)) async_read_some(const MutableBufferSequence &buffers
 Start an asynchronous read. More...
 
 BOOST_ASIO_MOVE_ARG (ReadHandler) handler)
 
lowest_layer_typelowest_layer ()
 Get a reference to the lowest layer. More...
 
const lowest_layer_typelowest_layer () const
 Get a const reference to the lowest layer. More...
 
void open (const protocol_type &protocol=protocol_type())
 Open the socket using the specified protocol. More...
 
boost::system::error_code open (const protocol_type &protocol, boost::system::error_code &ec)
 Open the socket using the specified protocol. More...
 
void assign (const protocol_type &protocol, const native_handle_type &native_socket)
 Assign an existing native socket to the socket. More...
 
boost::system::error_code assign (const protocol_type &protocol, const native_handle_type &native_socket, boost::system::error_code &ec)
 Assign an existing native socket to the socket. More...
 
bool is_open () const
 Determine whether the socket is open. More...
 
void close ()
 Close the socket. More...
 
boost::system::error_code close (boost::system::error_code &ec)
 Close the socket. More...
 
native_type native ()
 (Deprecated: Use native_handle().) Get the native socket representation. More...
 
native_handle_type native_handle ()
 Get the native socket representation. More...
 
void cancel ()
 Cancel all asynchronous operations associated with the socket. More...
 
boost::system::error_code cancel (boost::system::error_code &ec)
 Cancel all asynchronous operations associated with the socket. More...
 
bool at_mark () const
 Determine whether the socket is at the out-of-band data mark. More...
 
bool at_mark (boost::system::error_code &ec) const
 Determine whether the socket is at the out-of-band data mark. More...
 
std::size_t available () const
 Determine the number of bytes available for reading. More...
 
std::size_t available (boost::system::error_code &ec) const
 Determine the number of bytes available for reading. More...
 
void bind (const endpoint_type &endpoint)
 Bind the socket to the given local endpoint. More...
 
boost::system::error_code bind (const endpoint_type &endpoint, boost::system::error_code &ec)
 Bind the socket to the given local endpoint. More...
 
void connect (const endpoint_type &peer_endpoint)
 Connect the socket to the specified endpoint. More...
 
boost::system::error_code connect (const endpoint_type &peer_endpoint, boost::system::error_code &ec)
 Connect the socket to the specified endpoint. More...
 
 BOOST_ASIO_INITFN_RESULT_TYPE (ConnectHandler, void(boost::system::error_code)) async_connect(const endpoint_type &peer_endpoint
 Start an asynchronous connect. More...
 
 BOOST_ASIO_MOVE_ARG (ConnectHandler) handler)
 
void set_option (const SettableSocketOption &option)
 Set an option on the socket. More...
 
boost::system::error_code set_option (const SettableSocketOption &option, boost::system::error_code &ec)
 Set an option on the socket. More...
 
void get_option (GettableSocketOption &option) const
 Get an option from the socket. More...
 
boost::system::error_code get_option (GettableSocketOption &option, boost::system::error_code &ec) const
 Get an option from the socket. More...
 
void io_control (IoControlCommand &command)
 Perform an IO control command on the socket. More...
 
boost::system::error_code io_control (IoControlCommand &command, boost::system::error_code &ec)
 Perform an IO control command on the socket. More...
 
bool non_blocking () const
 Gets the non-blocking mode of the socket. More...
 
void non_blocking (bool mode)
 Sets the non-blocking mode of the socket. More...
 
boost::system::error_code non_blocking (bool mode, boost::system::error_code &ec)
 Sets the non-blocking mode of the socket. More...
 
bool native_non_blocking () const
 Gets the non-blocking mode of the native socket implementation. More...
 
void native_non_blocking (bool mode)
 Sets the non-blocking mode of the native socket implementation. More...
 
boost::system::error_code native_non_blocking (bool mode, boost::system::error_code &ec)
 Sets the non-blocking mode of the native socket implementation. More...
 
endpoint_type local_endpoint () const
 Get the local endpoint of the socket. More...
 
endpoint_type local_endpoint (boost::system::error_code &ec) const
 Get the local endpoint of the socket. More...
 
endpoint_type remote_endpoint () const
 Get the remote endpoint of the socket. More...
 
endpoint_type remote_endpoint (boost::system::error_code &ec) const
 Get the remote endpoint of the socket. More...
 
void shutdown (shutdown_type what)
 Disable sends or receives on the socket. More...
 
boost::system::error_code shutdown (shutdown_type what, boost::system::error_code &ec)
 Disable sends or receives on the socket. More...
 
boost::asio::io_serviceget_io_service ()
 Get the io_service associated with the object. More...
 
 BOOST_ASIO_STATIC_CONSTANT (int, message_peek=BOOST_ASIO_OS_DEF(MSG_PEEK))
 
 BOOST_ASIO_STATIC_CONSTANT (int, message_out_of_band=BOOST_ASIO_OS_DEF(MSG_OOB))
 
 BOOST_ASIO_STATIC_CONSTANT (int, message_do_not_route=BOOST_ASIO_OS_DEF(MSG_DONTROUTE))
 
 BOOST_ASIO_STATIC_CONSTANT (int, message_end_of_record=BOOST_ASIO_OS_DEF(MSG_EOR))
 
 BOOST_ASIO_STATIC_CONSTANT (int, max_connections=BOOST_ASIO_OS_DEF(SOMAXCONN))
 The maximum length of the queue of pending incoming connections. More...
 

Public Attributes

socket_base::message_flags flags
 

Protected Member Functions

service_typeget_service ()
 Get the service associated with the I/O object. More...
 
const service_typeget_service () const
 Get the service associated with the I/O object. More...
 
implementation_typeget_implementation ()
 Get the underlying implementation of the I/O object. More...
 
const implementation_typeget_implementation () const
 Get the underlying implementation of the I/O object. More...
 

Protected Attributes

service_typeservice
 (Deprecated: Use get_service().) The service associated with the I/O object. More...
 
implementation_type implementation
 (Deprecated: Use get_implementation().) The underlying implementation of the I/O object. More...
 

Detailed Description

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

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:
AsyncReadStream, AsyncWriteStream, Stream, SyncReadStream, SyncWriteStream.

Member Typedef Documentation

typedef boost::asio::detail::socket_option::boolean< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_BROADCAST)> 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.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
typedef boost::asio::detail::io_control::bytes_readable 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.
typedef boost::asio::detail::socket_option::boolean< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DEBUG)> boost::asio::socket_base::debug
inherited

Socket option to enable socket-level debugging.

Implements the SOL_SOCKET/SO_DEBUG socket option.

Examples
Setting the option:
boost::asio::ip::tcp::socket socket(io_service);
...
boost::asio::socket_base::debug option(true);
socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service);
...
boost::asio::socket_base::debug option;
socket.get_option(option);
bool is_set = option.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
typedef boost::asio::detail::socket_option::boolean< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_DONTROUTE)> 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.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
typedef boost::asio::detail::socket_option::boolean< boost::asio::detail::custom_socket_option_level, boost::asio::detail::enable_connection_aborted_option> 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.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
typedef Protocol::endpoint boost::asio::basic_stream_socket< Protocol, StreamSocketService >::endpoint_type

The endpoint type.

typedef service_type::implementation_type boost::asio::basic_io_object< StreamSocketService >::implementation_type
inherited

The underlying implementation type of I/O object.

typedef boost::asio::detail::socket_option::boolean< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_KEEPALIVE)> 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.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
typedef boost::asio::detail::socket_option::linger< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_LINGER)> 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 basic_socket<Protocol, StreamSocketService > boost::asio::basic_socket< Protocol, StreamSocketService >::lowest_layer_type
inherited

A basic_socket is always the lowest layer.

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

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
typedef StreamSocketService::native_handle_type boost::asio::basic_stream_socket< Protocol, StreamSocketService >::native_handle_type

The native representation of a socket.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
typedef StreamSocketService::native_handle_type boost::asio::basic_stream_socket< Protocol, StreamSocketService >::native_type

(Deprecated: Use native_handle_type.) The native representation of a socket.

typedef boost::asio::detail::io_control::non_blocking_io boost::asio::socket_base::non_blocking_io
inherited

(Deprecated: Use non_blocking().) 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.
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
typedef Protocol boost::asio::basic_stream_socket< Protocol, StreamSocketService >::protocol_type

The protocol type.

typedef boost::asio::detail::socket_option::integer< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVBUF)> 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.value();
Concepts:
Socket_Option, Integer_Socket_Option.
typedef boost::asio::detail::socket_option::integer< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_RCVLOWAT)> 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.value();
Concepts:
Socket_Option, Integer_Socket_Option.
typedef boost::asio::detail::socket_option::boolean< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_REUSEADDR)> 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.value();
Concepts:
Socket_Option, Boolean_Socket_Option.
typedef boost::asio::detail::socket_option::integer< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDBUF)> 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.value();
Concepts:
Socket_Option, Integer_Socket_Option.
typedef boost::asio::detail::socket_option::integer< BOOST_ASIO_OS_DEF(SOL_SOCKET), BOOST_ASIO_OS_DEF(SO_SNDLOWAT)> 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.value();
Concepts:
Socket_Option, Integer_Socket_Option.
typedef StreamSocketService boost::asio::basic_io_object< StreamSocketService >::service_type
inherited

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

Member Enumeration Documentation

Different ways a socket may be shutdown.

Enumerator
shutdown_receive 
shutdown_send 
shutdown_both 

Constructor & Destructor Documentation

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::basic_stream_socket ( boost::asio::io_service io_service)
inlineexplicit

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_serviceThe io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::basic_stream_socket ( boost::asio::io_service io_service,
const protocol_type protocol 
)
inline

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_serviceThe io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
protocolAn object specifying protocol parameters to be used.
Exceptions
boost::system::system_errorThrown on failure.
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::basic_stream_socket ( boost::asio::io_service io_service,
const endpoint_type endpoint 
)
inline

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_serviceThe io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
endpointAn endpoint on the local machine to which the stream socket will be bound.
Exceptions
boost::system::system_errorThrown on failure.
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::basic_stream_socket ( boost::asio::io_service io_service,
const protocol_type protocol,
const native_handle_type native_socket 
)
inline

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_serviceThe io_service object that the stream socket will use to dispatch handlers for any asynchronous operations performed on the socket.
protocolAn object specifying protocol parameters to be used.
native_socketThe new underlying socket implementation.
Exceptions
boost::system::system_errorThrown on failure.

Member Function Documentation

void boost::asio::basic_socket< Protocol, StreamSocketService >::assign ( const protocol_type protocol,
const native_handle_type native_socket 
)
inlineinherited
boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::assign ( const protocol_type protocol,
const native_handle_type native_socket,
boost::system::error_code ec 
)
inlineinherited
bool boost::asio::basic_socket< Protocol, StreamSocketService >::at_mark ( ) const
inlineinherited

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
boost::system::system_errorThrown on failure.

References boost::asio::b, boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

bool boost::asio::basic_socket< Protocol, StreamSocketService >::at_mark ( boost::system::error_code ec) const
inlineinherited

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
ecSet to indicate what error occurred, if any.
Returns
A bool indicating whether the socket is at the out-of-band data mark.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

std::size_t boost::asio::basic_socket< Protocol, StreamSocketService >::available ( ) const
inlineinherited

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
boost::system::system_errorThrown on failure.

References boost::asio::basic_io_object< SocketService >::get_implementation(), boost::asio::basic_io_object< SocketService >::get_service(), and boost::asio::s.

std::size_t boost::asio::basic_socket< Protocol, StreamSocketService >::available ( boost::system::error_code ec) const
inlineinherited

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
ecSet to indicate what error occurred, if any.
Returns
The number of bytes that may be read without blocking, or 0 if an error occurs.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::bind ( const endpoint_type endpoint)
inlineinherited

Bind the socket to the given local endpoint.

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

Parameters
endpointAn endpoint on the local machine to which the socket will be bound.
Exceptions
boost::system::system_errorThrown on failure.
Example

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::bind ( const endpoint_type endpoint,
boost::system::error_code ec 
)
inlineinherited

Bind the socket to the given local endpoint.

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

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

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence , typename WriteHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( WriteHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous send.

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

Parameters
buffersOne 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.
handlerThe 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::system::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 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 StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence , typename WriteHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( WriteHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous send.

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

Parameters
buffersOne 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.
flagsFlags specifying how the send call is to be made.
handlerThe 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::system::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 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 StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence , typename ReadHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( ReadHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous receive.

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

Parameters
buffersOne 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.
handlerThe 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::system::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 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 StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence , typename ReadHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( ReadHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous receive.

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

Parameters
buffersOne 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.
flagsFlags specifying how the receive call is to be made.
handlerThe 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::system::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 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 StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence , typename WriteHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( WriteHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous write.

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

Parameters
buffersOne 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.
handlerThe 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::system::error_code& 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.
boost::asio::basic_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( ConnectHandler  ,
void(boost::system::error_code  
) const
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 not returned to the closed state.

Parameters
peer_endpointThe remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
handlerThe 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::system::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 boost::asio::io_service::post().
Example
void connect_handler(const boost::system::error_code& error)
{
if (!error)
{
// Connect succeeded.
}
}
...
boost::asio::ip::tcp::socket socket(io_service);
socket.async_connect(endpoint, connect_handler);
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence , typename ReadHandler >
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_INITFN_RESULT_TYPE ( ReadHandler  ,
void(boost::system::error_code, std::size_t)   
) const

Start an asynchronous read.

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

Parameters
buffersOne 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.
handlerThe 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::system::error_code& 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 StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( WriteHandler  )
inline
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
socket_base::message_flags boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( WriteHandler  )
inline
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( ReadHandler  )
inline
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
socket_base::message_flags boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( ReadHandler  )
inline
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( WriteHandler  )
inline
template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
boost::asio::basic_stream_socket< Protocol, StreamSocketService >::BOOST_ASIO_MOVE_ARG ( ReadHandler  )
inline
boost::asio::socket_base::BOOST_ASIO_STATIC_CONSTANT ( int  ,
message_peek  = BOOST_ASIO_OS_DEF(MSG_PEEK) 
)
inherited
boost::asio::socket_base::BOOST_ASIO_STATIC_CONSTANT ( int  ,
message_out_of_band  = BOOST_ASIO_OS_DEF(MSG_OOB) 
)
inherited
boost::asio::socket_base::BOOST_ASIO_STATIC_CONSTANT ( int  ,
message_do_not_route  = BOOST_ASIO_OS_DEF(MSG_DONTROUTE) 
)
inherited
boost::asio::socket_base::BOOST_ASIO_STATIC_CONSTANT ( int  ,
message_end_of_record  = BOOST_ASIO_OS_DEF(MSG_EOR) 
)
inherited
boost::asio::socket_base::BOOST_ASIO_STATIC_CONSTANT ( int  ,
max_connections  = BOOST_ASIO_OS_DEF(SOMAXCONN) 
)
inherited

The maximum length of the queue of pending incoming connections.

void boost::asio::basic_socket< Protocol, StreamSocketService >::cancel ( )
inlineinherited

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 boost::asio::error::operation_aborted error.

Exceptions
boost::system::system_errorThrown on failure.
Note
Calls to cancel() will always fail with boost::asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo function has two issues that should be considered before enabling its use:
  • It will only cancel asynchronous operations that were initiated in the current thread.
  • It can appear to complete without error, but the request to cancel the unfinished operations may be silently ignored by the operating system. Whether it works or not seems to depend on the drivers that are installed.

For portable cancellation, consider using one of the following alternatives:

  • Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
  • Use the close() function to simultaneously cancel the outstanding operations and close the socket.

When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::cancel ( boost::system::error_code ec)
inlineinherited

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 boost::asio::error::operation_aborted error.

Parameters
ecSet to indicate what error occurred, if any.
Note
Calls to cancel() will always fail with boost::asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo function has two issues that should be considered before enabling its use:
  • It will only cancel asynchronous operations that were initiated in the current thread.
  • It can appear to complete without error, but the request to cancel the unfinished operations may be silently ignored by the operating system. Whether it works or not seems to depend on the drivers that are installed.

For portable cancellation, consider using one of the following alternatives:

  • Disable asio's I/O completion port backend by defining BOOST_ASIO_DISABLE_IOCP.
  • Use the close() function to simultaneously cancel the outstanding operations and close the socket.

When running on Windows Vista, Windows Server 2008, and later, the CancelIoEx function is always used. This function does not have the problems described above.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::close ( )
inlineinherited

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::system::system_errorThrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
Note
For portable behaviour with respect to graceful closure of a connected socket, call shutdown() before closing the socket.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::close ( boost::system::error_code ec)
inlineinherited

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
ecSet to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
Example
boost::asio::ip::tcp::socket socket(io_service);
...
boost::system::error_code ec;
socket.close(ec);
if (ec)
{
// An error occurred.
}
Note
For portable behaviour with respect to graceful closure of a connected socket, call shutdown() before closing the socket.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::connect ( const endpoint_type peer_endpoint)
inlineinherited

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 not returned to the closed state.

Parameters
peer_endpointThe remote endpoint to which the socket will be connected.
Exceptions
boost::system::system_errorThrown on failure.
Example
boost::asio::ip::tcp::socket socket(io_service);
socket.connect(endpoint);

References boost::asio::basic_io_object< SocketService >::get_implementation(), boost::asio::basic_io_object< SocketService >::get_service(), and boost::asio::basic_socket< Protocol, SocketService >::is_open().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::connect ( const endpoint_type peer_endpoint,
boost::system::error_code ec 
)
inlineinherited

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 not returned to the closed state.

Parameters
peer_endpointThe remote endpoint to which the socket will be connected.
ecSet to indicate what error occurred, if any.
Example
boost::asio::ip::tcp::socket socket(io_service);
socket.connect(endpoint, ec);
if (ec)
{
// An error occurred.
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), boost::asio::basic_io_object< SocketService >::get_service(), boost::asio::basic_socket< Protocol, SocketService >::is_open(), and boost::asio::basic_socket< Protocol, SocketService >::open().

const implementation_type& boost::asio::basic_io_object< StreamSocketService >::get_implementation ( ) const
inlineprotectedinherited

Get the underlying implementation of the I/O object.

boost::asio::io_service& boost::asio::basic_io_object< StreamSocketService >::get_io_service ( )
inlineinherited

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.
void boost::asio::basic_socket< Protocol, StreamSocketService >::get_option ( GettableSocketOption &  option) const
inlineinherited
boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::get_option ( GettableSocketOption &  option,
boost::system::error_code ec 
) const
inlineinherited
const service_type& boost::asio::basic_io_object< StreamSocketService >::get_service ( ) const
inlineprotectedinherited

Get the service associated with the I/O object.

void boost::asio::basic_socket< Protocol, StreamSocketService >::io_control ( IoControlCommand &  command)
inlineinherited

Perform an IO control command on the socket.

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

Parameters
commandThe IO control command to be performed on the socket.
Exceptions
boost::system::system_errorThrown on failure.
See also
IoControlCommand
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();

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::io_control ( IoControlCommand &  command,
boost::system::error_code ec 
)
inlineinherited

Perform an IO control command on the socket.

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

Parameters
commandThe IO control command to be performed on the socket.
ecSet to indicate what error occurred, if any.
See also
IoControlCommand
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, ec);
if (ec)
{
// An error occurred.
}
std::size_t bytes_readable = command.get();

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

bool boost::asio::basic_socket< Protocol, StreamSocketService >::is_open ( ) const
inlineinherited
endpoint_type boost::asio::basic_socket< Protocol, StreamSocketService >::local_endpoint ( ) const
inlineinherited

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::system::system_errorThrown on failure.
Example
boost::asio::ip::tcp::socket socket(io_service);
...
boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

endpoint_type boost::asio::basic_socket< Protocol, StreamSocketService >::local_endpoint ( boost::system::error_code ec) const
inlineinherited

Get the local endpoint of the socket.

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

Parameters
ecSet 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
boost::asio::ip::tcp::socket socket(io_service);
...
boost::system::error_code ec;
boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec);
if (ec)
{
// An error occurred.
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

lowest_layer_type& boost::asio::basic_socket< Protocol, StreamSocketService >::lowest_layer ( )
inlineinherited

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.
const lowest_layer_type& boost::asio::basic_socket< Protocol, StreamSocketService >::lowest_layer ( ) const
inlineinherited

Get a const reference to the lowest layer.

This function returns a const 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 const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
native_type boost::asio::basic_socket< Protocol, StreamSocketService >::native ( )
inlineinherited

(Deprecated: Use native_handle().) 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.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

native_handle_type boost::asio::basic_socket< Protocol, StreamSocketService >::native_handle ( )
inlineinherited

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.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

bool boost::asio::basic_socket< Protocol, StreamSocketService >::native_non_blocking ( ) const
inlineinherited

Gets the non-blocking mode of the native socket implementation.

This function is used to retrieve the non-blocking mode of the underlying native socket. This mode has no effect on the behaviour of the socket object's synchronous operations.

Returns
true if the underlying socket is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block (or the equivalent system error).
Note
The current non-blocking mode is cached by the socket object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native socket.
Example
This function is intended to allow the encapsulation of arbitrary non-blocking system calls as asynchronous operations, in a way that is transparent to the user of the socket object. The following example illustrates how Linux's sendfile system call might be encapsulated:
template <typename Handler>
struct sendfile_op
{
tcp::socket& sock_;
int fd_;
Handler handler_;
off_t offset_;
std::size_t total_bytes_transferred_;
// Function call operator meeting WriteHandler requirements.
// Used as the handler for the async_write_some operation.
void operator()(boost::system::error_code ec, std::size_t)
{
// Put the underlying socket into non-blocking mode.
if (!ec)
if (!sock_.native_non_blocking())
sock_.native_non_blocking(true, ec);
if (!ec)
{
for (;;)
{
// Try the system call.
errno = 0;
int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536);
ec = boost::system::error_code(n < 0 ? errno : 0,
total_bytes_transferred_ += ec ? 0 : n;
// Retry operation immediately if interrupted by signal.
continue;
// Check if we need to run the operation again.
{
// We have to wait for the socket to become ready again.
sock_.async_write_some(boost::asio::null_buffers(), *this);
return;
}
if (ec || n == 0)
{
// An error occurred, or we have reached the end of the file.
// Either way we must exit the loop so we can call the handler.
break;
}
// Loop around to try calling sendfile again.
}
}
// Pass result back to user's handler.
handler_(ec, total_bytes_transferred_);
}
};
template <typename Handler>
void async_sendfile(tcp::socket& sock, int fd, Handler h)
{
sendfile_op<Handler> op = { sock, fd, h, 0, 0 };
sock.async_write_some(boost::asio::null_buffers(), op);
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::native_non_blocking ( bool  mode)
inlineinherited

Sets the non-blocking mode of the native socket implementation.

This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.

Parameters
modeIf true, the underlying socket is put into non-blocking mode and direct system calls may fail with boost::asio::error::would_block (or the equivalent system error).
Exceptions
boost::system::system_errorThrown on failure. If the mode is false, but the current value of non_blocking() is true, this function fails with boost::asio::error::invalid_argument, as the combination does not make sense.
Example
This function is intended to allow the encapsulation of arbitrary non-blocking system calls as asynchronous operations, in a way that is transparent to the user of the socket object. The following example illustrates how Linux's sendfile system call might be encapsulated:
template <typename Handler>
struct sendfile_op
{
tcp::socket& sock_;
int fd_;
Handler handler_;
off_t offset_;
std::size_t total_bytes_transferred_;
// Function call operator meeting WriteHandler requirements.
// Used as the handler for the async_write_some operation.
void operator()(boost::system::error_code ec, std::size_t)
{
// Put the underlying socket into non-blocking mode.
if (!ec)
if (!sock_.native_non_blocking())
sock_.native_non_blocking(true, ec);
if (!ec)
{
for (;;)
{
// Try the system call.
errno = 0;
int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536);
ec = boost::system::error_code(n < 0 ? errno : 0,
total_bytes_transferred_ += ec ? 0 : n;
// Retry operation immediately if interrupted by signal.
continue;
// Check if we need to run the operation again.
{
// We have to wait for the socket to become ready again.
sock_.async_write_some(boost::asio::null_buffers(), *this);
return;
}
if (ec || n == 0)
{
// An error occurred, or we have reached the end of the file.
// Either way we must exit the loop so we can call the handler.
break;
}
// Loop around to try calling sendfile again.
}
}
// Pass result back to user's handler.
handler_(ec, total_bytes_transferred_);
}
};
template <typename Handler>
void async_sendfile(tcp::socket& sock, int fd, Handler h)
{
sendfile_op<Handler> op = { sock, fd, h, 0, 0 };
sock.async_write_some(boost::asio::null_buffers(), op);
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::native_non_blocking ( bool  mode,
boost::system::error_code ec 
)
inlineinherited

Sets the non-blocking mode of the native socket implementation.

This function is used to modify the non-blocking mode of the underlying native socket. It has no effect on the behaviour of the socket object's synchronous operations.

Parameters
modeIf true, the underlying socket is put into non-blocking mode and direct system calls may fail with boost::asio::error::would_block (or the equivalent system error).
ecSet to indicate what error occurred, if any. If the mode is false, but the current value of non_blocking() is true, this function fails with boost::asio::error::invalid_argument, as the combination does not make sense.
Example
This function is intended to allow the encapsulation of arbitrary non-blocking system calls as asynchronous operations, in a way that is transparent to the user of the socket object. The following example illustrates how Linux's sendfile system call might be encapsulated:
template <typename Handler>
struct sendfile_op
{
tcp::socket& sock_;
int fd_;
Handler handler_;
off_t offset_;
std::size_t total_bytes_transferred_;
// Function call operator meeting WriteHandler requirements.
// Used as the handler for the async_write_some operation.
void operator()(boost::system::error_code ec, std::size_t)
{
// Put the underlying socket into non-blocking mode.
if (!ec)
if (!sock_.native_non_blocking())
sock_.native_non_blocking(true, ec);
if (!ec)
{
for (;;)
{
// Try the system call.
errno = 0;
int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536);
ec = boost::system::error_code(n < 0 ? errno : 0,
total_bytes_transferred_ += ec ? 0 : n;
// Retry operation immediately if interrupted by signal.
continue;
// Check if we need to run the operation again.
{
// We have to wait for the socket to become ready again.
sock_.async_write_some(boost::asio::null_buffers(), *this);
return;
}
if (ec || n == 0)
{
// An error occurred, or we have reached the end of the file.
// Either way we must exit the loop so we can call the handler.
break;
}
// Loop around to try calling sendfile again.
}
}
// Pass result back to user's handler.
handler_(ec, total_bytes_transferred_);
}
};
template <typename Handler>
void async_sendfile(tcp::socket& sock, int fd, Handler h)
{
sendfile_op<Handler> op = { sock, fd, h, 0, 0 };
sock.async_write_some(boost::asio::null_buffers(), op);
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

bool boost::asio::basic_socket< Protocol, StreamSocketService >::non_blocking ( ) const
inlineinherited

Gets the non-blocking mode of the socket.

Returns
true if the socket's synchronous operations will fail with boost::asio::error::would_block if they are unable to perform the requested operation immediately. If false, synchronous operations will block until complete.
Note
The non-blocking mode has no effect on the behaviour of asynchronous operations. Asynchronous operations will never fail with the error boost::asio::error::would_block.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::non_blocking ( bool  mode)
inlineinherited

Sets the non-blocking mode of the socket.

Parameters
modeIf true, the socket's synchronous operations will fail with boost::asio::error::would_block if they are unable to perform the requested operation immediately. If false, synchronous operations will block until complete.
Exceptions
boost::system::system_errorThrown on failure.
Note
The non-blocking mode has no effect on the behaviour of asynchronous operations. Asynchronous operations will never fail with the error boost::asio::error::would_block.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::non_blocking ( bool  mode,
boost::system::error_code ec 
)
inlineinherited

Sets the non-blocking mode of the socket.

Parameters
modeIf true, the socket's synchronous operations will fail with boost::asio::error::would_block if they are unable to perform the requested operation immediately. If false, synchronous operations will block until complete.
ecSet to indicate what error occurred, if any.
Note
The non-blocking mode has no effect on the behaviour of asynchronous operations. Asynchronous operations will never fail with the error boost::asio::error::would_block.

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::open ( const protocol_type protocol = protocol_type())
inlineinherited

Open the socket using the specified protocol.

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

Parameters
protocolAn object specifying protocol parameters to be used.
Exceptions
boost::system::system_errorThrown on failure.
Example
boost::asio::ip::tcp::socket socket(io_service);
socket.open(boost::asio::ip::tcp::v4());

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::open ( const protocol_type protocol,
boost::system::error_code ec 
)
inlineinherited

Open the socket using the specified protocol.

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

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

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::read_some ( const MutableBufferSequence &  buffers)
inline

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
buffersOne or more buffers into which the data will be read.
Returns
The number of bytes read.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::read_some ( const MutableBufferSequence &  buffers,
boost::system::error_code ec 
)
inline

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
buffersOne or more buffers into which the data will be read.
ecSet to indicate what error occurred, if any.
Returns
The number of bytes read. Returns 0 if an error occurred.
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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), and boost::asio::basic_io_object< StreamSocketService >::get_service().

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::receive ( const MutableBufferSequence &  buffers)
inline

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
buffersOne or more buffers into which the data will be received.
Returns
The number of bytes received.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags 
)
inline

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
buffersOne or more buffers into which the data will be received.
flagsFlags specifying how the receive call is to be made.
Returns
The number of bytes received.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename MutableBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags,
boost::system::error_code ec 
)
inline

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
buffersOne or more buffers into which the data will be received.
flagsFlags specifying how the receive call is to be made.
ecSet to indicate what error occurred, if any.
Returns
The number of bytes received. Returns 0 if an error occurred.
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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), and boost::asio::basic_io_object< StreamSocketService >::get_service().

endpoint_type boost::asio::basic_socket< Protocol, StreamSocketService >::remote_endpoint ( ) const
inlineinherited

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::system::system_errorThrown on failure.
Example
boost::asio::ip::tcp::socket socket(io_service);
...
boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

endpoint_type boost::asio::basic_socket< Protocol, StreamSocketService >::remote_endpoint ( boost::system::error_code ec) const
inlineinherited

Get the remote endpoint of the socket.

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

Parameters
ecSet 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
boost::asio::ip::tcp::socket socket(io_service);
...
boost::system::error_code ec;
boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec);
if (ec)
{
// An error occurred.
}

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::send ( const ConstBufferSequence &  buffers)
inline

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
buffersOne or more data buffers to be sent on the socket.
Returns
The number of bytes sent.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags 
)
inline

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
buffersOne or more data buffers to be sent on the socket.
flagsFlags specifying how the send call is to be made.
Returns
The number of bytes sent.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags,
boost::system::error_code ec 
)
inline

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
buffersOne or more data buffers to be sent on the socket.
flagsFlags specifying how the send call is to be made.
ecSet to indicate what error occurred, if any.
Returns
The number of bytes sent. Returns 0 if an error occurred.
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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), and boost::asio::basic_io_object< StreamSocketService >::get_service().

void boost::asio::basic_socket< Protocol, StreamSocketService >::shutdown ( shutdown_type  what)
inlineinherited

Disable sends or receives on the socket.

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

Parameters
whatDetermines what types of operation will no longer be allowed.
Exceptions
boost::system::system_errorThrown on failure.
Example
Shutting down the send side of the socket:

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

boost::system::error_code boost::asio::basic_socket< Protocol, StreamSocketService >::shutdown ( shutdown_type  what,
boost::system::error_code ec 
)
inlineinherited

Disable sends or receives on the socket.

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

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

References boost::asio::basic_io_object< SocketService >::get_implementation(), and boost::asio::basic_io_object< SocketService >::get_service().

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::write_some ( const ConstBufferSequence &  buffers)
inline

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
buffersOne or more data buffers to be written to the socket.
Returns
The number of bytes written.
Exceptions
boost::system::system_errorThrown 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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), boost::asio::basic_io_object< StreamSocketService >::get_service(), and boost::asio::s.

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
template<typename ConstBufferSequence >
std::size_t boost::asio::basic_stream_socket< Protocol, StreamSocketService >::write_some ( const ConstBufferSequence &  buffers,
boost::system::error_code ec 
)
inline

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
buffersOne or more data buffers to be written to the socket.
ecSet to indicate what error occurred, if any.
Returns
The number of bytes written. Returns 0 if an error occurred.
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.

References boost::asio::basic_io_object< StreamSocketService >::get_implementation(), and boost::asio::basic_io_object< StreamSocketService >::get_service().

Member Data Documentation

template<typename Protocol , typename StreamSocketService = stream_socket_service<Protocol>>
socket_base::message_flags boost::asio::basic_stream_socket< Protocol, StreamSocketService >::flags
implementation_type boost::asio::basic_io_object< StreamSocketService >::implementation
protectedinherited

(Deprecated: Use get_implementation().) The underlying implementation of the I/O object.

service_type& boost::asio::basic_io_object< StreamSocketService >::service
protectedinherited

(Deprecated: Use get_service().) The service associated with the I/O object.

Note
Available only for services that do not support movability.

The documentation for this class was generated from the following file: