Clementine
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
asio::basic_stream_socket< Protocol, Executor > Class Template Reference

Provides stream-oriented socket functionality. More...

#include <basic_stream_socket.hpp>

Inheritance diagram for asio::basic_stream_socket< Protocol, Executor >:
Inheritance graph
[legend]
Collaboration diagram for asio::basic_stream_socket< Protocol, Executor >:
Collaboration graph
[legend]

Classes

struct  rebind_executor
 Rebinds the socket type to another executor. More...
 

Public Types

typedef Executor executor_type
 The type of the executor associated with the object.
 
typedef basic_socket< Protocol, Executor >::native_handle_type native_handle_type
 The native representation of a socket.
 
typedef Protocol protocol_type
 The protocol type.
 
typedef Protocol::endpoint endpoint_type
 The endpoint type.
 
- Public Types inherited from asio::basic_socket< Protocol, Executor >
typedef Executor executor_type
 The type of the executor associated with the object.
 
typedef detail::reactive_socket_service< Protocol >::native_handle_type native_handle_type
 The native representation of a socket.
 
typedef Protocol protocol_type
 The protocol type.
 
typedef Protocol::endpoint endpoint_type
 The endpoint type.
 
typedef basic_socket< Protocol, Executor > lowest_layer_type
 A basic_socket is always the lowest layer.
 
- Public Types inherited from asio::socket_base
enum  shutdown_type { shutdown_receive = ASIO_OS_DEF(SHUT_RD), shutdown_send = ASIO_OS_DEF(SHUT_WR), shutdown_both = ASIO_OS_DEF(SHUT_RDWR) }
 Different ways a socket may be shutdown.
 
enum  wait_type { wait_read, wait_write, wait_error }
 Wait types. More...
 
typedef int message_flags
 Bitmask type for flags that can be passed to send and receive operations.
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_BROADCAST)> broadcast
 Socket option to permit sending of broadcast messages. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DEBUG)> debug
 Socket option to enable socket-level debugging. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DONTROUTE)> do_not_route
 Socket option to prevent routing, use local interfaces only. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_KEEPALIVE)> keep_alive
 Socket option to send keep-alives. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDBUF)> send_buffer_size
 Socket option for the send buffer size of a socket. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDLOWAT)> send_low_watermark
 Socket option for the send low watermark. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVBUF)> receive_buffer_size
 Socket option for the receive buffer size of a socket. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVLOWAT)> receive_low_watermark
 Socket option for the receive low watermark. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), 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 asio::detail::socket_option::linger< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_LINGER)> linger
 Socket option to specify whether the socket lingers on close if unsent data is present. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_OOBINLINE)> out_of_band_inline
 Socket option for putting received out-of-band data inline. More...
 
typedef asio::detail::socket_option::boolean< asio::detail::custom_socket_option_level, asio::detail::enable_connection_aborted_option > enable_connection_aborted
 Socket option to report aborted connections on accept. More...
 
typedef 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 (const executor_type &ex)
 Construct a basic_stream_socket without opening it. More...
 
template<typename ExecutionContext >
 basic_stream_socket (ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_stream_socket without opening it. More...
 
 basic_stream_socket (const executor_type &ex, const protocol_type &protocol)
 Construct and open a basic_stream_socket. More...
 
template<typename ExecutionContext >
 basic_stream_socket (ExecutionContext &context, const protocol_type &protocol, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct and open a basic_stream_socket. More...
 
 basic_stream_socket (const executor_type &ex, const endpoint_type &endpoint)
 Construct a basic_stream_socket, opening it and binding it to the given local endpoint. More...
 
template<typename ExecutionContext >
 basic_stream_socket (ExecutionContext &context, const endpoint_type &endpoint, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_stream_socket, opening it and binding it to the given local endpoint. More...
 
 basic_stream_socket (const executor_type &ex, const protocol_type &protocol, const native_handle_type &native_socket)
 Construct a basic_stream_socket on an existing native socket. More...
 
template<typename ExecutionContext >
 basic_stream_socket (ExecutionContext &context, const protocol_type &protocol, const native_handle_type &native_socket, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_stream_socket on an existing native socket. More...
 
 ~basic_stream_socket ()
 Destroys the 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, asio::error_code &ec)
 Send some data on the socket. More...
 
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (WriteHandler, void(asio::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
 Start an asynchronous send. More...
 
 ASIO_MOVE_ARG (WriteHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (WriteHandler, void(asio::error_code, std::size_t)) async_send(const ConstBufferSequence &buffers
 Start an asynchronous send. More...
 
socket_base::message_flags ASIO_MOVE_ARG (WriteHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
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, asio::error_code &ec)
 Receive some data on a connected socket. More...
 
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (ReadHandler, void(asio::error_code, std::size_t)) async_receive(const MutableBufferSequence &buffers
 Start an asynchronous receive. More...
 
 ASIO_MOVE_ARG (ReadHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (ReadHandler, void(asio::error_code, std::size_t)) async_receive(const MutableBufferSequence &buffers
 Start an asynchronous receive. More...
 
socket_base::message_flags ASIO_MOVE_ARG (ReadHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
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, asio::error_code &ec)
 Write some data to the socket. More...
 
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (WriteHandler, void(asio::error_code, std::size_t)) async_write_some(const ConstBufferSequence &buffers
 Start an asynchronous write. More...
 
 ASIO_MOVE_ARG (WriteHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
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, asio::error_code &ec)
 Read some data from the socket. More...
 
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
 ASIO_INITFN_AUTO_RESULT_TYPE (ReadHandler, void(asio::error_code, std::size_t)) async_read_some(const MutableBufferSequence &buffers
 Start an asynchronous read. More...
 
 ASIO_MOVE_ARG (ReadHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
- Public Member Functions inherited from asio::basic_socket< Protocol, Executor >
 basic_socket (const executor_type &ex)
 Construct a basic_socket without opening it. More...
 
template<typename ExecutionContext >
 basic_socket (ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_socket without opening it. More...
 
 basic_socket (const executor_type &ex, const protocol_type &protocol)
 Construct and open a basic_socket. More...
 
template<typename ExecutionContext >
 basic_socket (ExecutionContext &context, const protocol_type &protocol, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct and open a basic_socket. More...
 
 basic_socket (const executor_type &ex, const endpoint_type &endpoint)
 Construct a basic_socket, opening it and binding it to the given local endpoint. More...
 
template<typename ExecutionContext >
 basic_socket (ExecutionContext &context, const endpoint_type &endpoint, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_socket, opening it and binding it to the given local endpoint. More...
 
 basic_socket (const executor_type &ex, const protocol_type &protocol, const native_handle_type &native_socket)
 Construct a basic_socket on an existing native socket. More...
 
template<typename ExecutionContext >
 basic_socket (ExecutionContext &context, const protocol_type &protocol, const native_handle_type &native_socket, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_socket on an existing native socket. More...
 
executor_type get_executor () ASIO_NOEXCEPT
 Get the executor associated with the object.
 
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...
 
ASIO_SYNC_OP_VOID open (const protocol_type &protocol, asio::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.
 
ASIO_SYNC_OP_VOID assign (const protocol_type &protocol, const native_handle_type &native_socket, asio::error_code &ec)
 Assign an existing native socket to the socket.
 
bool is_open () const
 Determine whether the socket is open.
 
void close ()
 Close the socket. More...
 
ASIO_SYNC_OP_VOID close (asio::error_code &ec)
 Close the socket. More...
 
native_handle_type release ()
 Release ownership of the underlying native socket. More...
 
native_handle_type release (asio::error_code &ec)
 Release ownership of the underlying native socket. More...
 
native_handle_type native_handle ()
 Get the native socket representation. More...
 
void cancel ()
 Cancel all asynchronous operations associated with the socket. More...
 
ASIO_SYNC_OP_VOID cancel (asio::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 (asio::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 (asio::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...
 
ASIO_SYNC_OP_VOID bind (const endpoint_type &endpoint, asio::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...
 
ASIO_SYNC_OP_VOID connect (const endpoint_type &peer_endpoint, asio::error_code &ec)
 Connect the socket to the specified endpoint. More...
 
template<ConnectHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
 ASIO_INITFN_AUTO_RESULT_TYPE (ConnectHandler, void(asio::error_code)) async_connect(const endpoint_type &peer_endpoint
 Start an asynchronous connect. More...
 
 ASIO_MOVE_ARG (ConnectHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
template<typename SettableSocketOption >
void set_option (const SettableSocketOption &option)
 Set an option on the socket. More...
 
template<typename SettableSocketOption >
ASIO_SYNC_OP_VOID set_option (const SettableSocketOption &option, asio::error_code &ec)
 Set an option on the socket. More...
 
template<typename GettableSocketOption >
void get_option (GettableSocketOption &option) const
 Get an option from the socket. More...
 
template<typename GettableSocketOption >
ASIO_SYNC_OP_VOID get_option (GettableSocketOption &option, asio::error_code &ec) const
 Get an option from the socket. More...
 
template<typename IoControlCommand >
void io_control (IoControlCommand &command)
 Perform an IO control command on the socket. More...
 
template<typename IoControlCommand >
ASIO_SYNC_OP_VOID io_control (IoControlCommand &command, asio::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...
 
ASIO_SYNC_OP_VOID non_blocking (bool mode, asio::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...
 
ASIO_SYNC_OP_VOID native_non_blocking (bool mode, asio::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 (asio::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 (asio::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...
 
ASIO_SYNC_OP_VOID shutdown (shutdown_type what, asio::error_code &ec)
 Disable sends or receives on the socket. More...
 
void wait (wait_type w)
 Wait for the socket to become ready to read, ready to write, or to have pending error conditions. More...
 
ASIO_SYNC_OP_VOID wait (wait_type w, asio::error_code &ec)
 Wait for the socket to become ready to read, ready to write, or to have pending error conditions. More...
 
template<WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
 ASIO_INITFN_AUTO_RESULT_TYPE (WaitHandler, void(asio::error_code)) async_wait(wait_type w
 Asynchronously wait for the socket to become ready to read, ready to write, or to have pending error conditions. More...
 
 ASIO_MOVE_ARG (WaitHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
- Public Member Functions inherited from asio::socket_base
 ASIO_STATIC_CONSTANT (int, message_peek=ASIO_OS_DEF(MSG_PEEK))
 
 ASIO_STATIC_CONSTANT (int, message_out_of_band=ASIO_OS_DEF(MSG_OOB))
 
 ASIO_STATIC_CONSTANT (int, message_do_not_route=ASIO_OS_DEF(MSG_DONTROUTE))
 
 ASIO_STATIC_CONSTANT (int, message_end_of_record=ASIO_OS_DEF(MSG_EOR))
 
 ASIO_STATIC_CONSTANT (int, max_listen_connections=ASIO_OS_DEF(SOMAXCONN))
 The maximum length of the queue of pending incoming connections.
 
 ASIO_STATIC_CONSTANT (int, max_connections=ASIO_OS_DEF(SOMAXCONN))
 (Deprecated: Use max_listen_connections.) The maximum length of the queue of pending incoming connections. More...
 

Public Attributes

socket_base::message_flags flags
 

Additional Inherited Members

- Protected Member Functions inherited from asio::basic_socket< Protocol, Executor >
 ~basic_socket ()
 Protected destructor to prevent deletion through this type. More...
 
- Protected Member Functions inherited from asio::socket_base
 ~socket_base ()
 Protected destructor to prevent deletion through this type.
 
- Protected Attributes inherited from asio::basic_socket< Protocol, Executor >
detail::io_object_impl< detail::reactive_socket_service< Protocol >, Executor > impl_
 

Detailed Description

template<typename Protocol, typename Executor>
class asio::basic_stream_socket< Protocol, Executor >

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.

Constructor & Destructor Documentation

◆ basic_stream_socket() [1/8]

template<typename Protocol, typename Executor>
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( const executor_type ex)
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
exThe I/O executor that the socket will use, by default, to dispatch handlers for any asynchronous operations performed on the socket.

◆ basic_stream_socket() [2/8]

template<typename Protocol, typename Executor>
template<typename ExecutionContext >
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( ExecutionContext &  context,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
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
contextAn execution context which provides the I/O executor that the socket will use, by default, to dispatch handlers for any asynchronous operations performed on the socket.

◆ basic_stream_socket() [3/8]

template<typename Protocol, typename Executor>
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( const executor_type ex,
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
exThe I/O executor that the socket will use, by default, to dispatch handlers for any asynchronous operations performed on the socket.
protocolAn object specifying protocol parameters to be used.
Exceptions
asio::system_errorThrown on failure.

◆ basic_stream_socket() [4/8]

template<typename Protocol, typename Executor>
template<typename ExecutionContext >
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( ExecutionContext &  context,
const protocol_type protocol,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
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
contextAn execution context which provides the I/O executor that the socket will use, by default, to dispatch handlers for any asynchronous operations performed on the socket.
protocolAn object specifying protocol parameters to be used.
Exceptions
asio::system_errorThrown on failure.

◆ basic_stream_socket() [5/8]

template<typename Protocol, typename Executor>
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( const executor_type ex,
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
exThe I/O executor that the socket will use, by default, 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
asio::system_errorThrown on failure.

◆ basic_stream_socket() [6/8]

template<typename Protocol, typename Executor>
template<typename ExecutionContext >
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( ExecutionContext &  context,
const endpoint_type endpoint,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
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
contextAn execution context which provides the I/O executor that the socket will use, by default, 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
asio::system_errorThrown on failure.

◆ basic_stream_socket() [7/8]

template<typename Protocol, typename Executor>
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( const executor_type ex,
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
exThe I/O executor that the socket will use, by default, 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
asio::system_errorThrown on failure.

◆ basic_stream_socket() [8/8]

template<typename Protocol, typename Executor>
template<typename ExecutionContext >
asio::basic_stream_socket< Protocol, Executor >::basic_stream_socket ( ExecutionContext &  context,
const protocol_type protocol,
const native_handle_type native_socket,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
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
contextAn execution context which provides the I/O executor that the socket will use, by default, 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
asio::system_errorThrown on failure.

◆ ~basic_stream_socket()

template<typename Protocol, typename Executor>
asio::basic_stream_socket< Protocol, Executor >::~basic_stream_socket ( )
inline

Destroys the socket.

This function destroys the socket, cancelling any outstanding asynchronous operations associated with the socket as if by calling cancel.

Member Function Documentation

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [1/6]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( WriteHandler  ,
void(asio::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 asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes sent.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The send operation may not transmit all of the data to the peer. Consider using the 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 asio::buffer function as follows:
socket.async_send(asio::buffer(data, size), handler);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [2/6]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( WriteHandler  ,
void(asio::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 asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes sent.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The send operation may not transmit all of the data to the peer. Consider using the 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 asio::buffer function as follows:
socket.async_send(asio::buffer(data, size), 0, handler);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [3/6]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( ReadHandler  ,
void(asio::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 asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes received.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The receive operation may not receive all of the requested number of bytes. Consider using the 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 asio::buffer function as follows:
socket.async_receive(asio::buffer(data, size), handler);
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [4/6]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( ReadHandler  ,
void(asio::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 asio::error_code& error, // Result of operation.
std::size_t bytes_transferred // Number of bytes received.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The receive operation may not receive all of the requested number of bytes. Consider using the 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 asio::buffer function as follows:
socket.async_receive(asio::buffer(data, size), 0, handler);
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [5/6]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) WriteHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( WriteHandler  ,
void(asio::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 asio::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. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The write operation may not transmit all of the data to the peer. Consider using the 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 asio::buffer function as follows:
socket.async_write_some(asio::buffer(data, size), handler);
See the asio::buffer documentation for information on writing multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [6/6]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence , ASIO_COMPLETION_TOKEN_FOR(void(asio::error_code, std::size_t)) ReadHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE(executor_type) >
asio::basic_stream_socket< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( ReadHandler  ,
void(asio::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 asio::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. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Note
The read operation may not read all of the requested number of bytes. Consider using the 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 asio::buffer function as follows:
socket.async_read_some(asio::buffer(data, size), handler);
See the 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.

◆ read_some() [1/2]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure. An error code of 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 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 asio::buffer function as follows:
socket.read_some(asio::buffer(data, size));
See the 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.

◆ read_some() [2/2]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::read_some ( const MutableBufferSequence &  buffers,
asio::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 asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

◆ receive() [1/3]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure. An error code of 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 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 asio::buffer function as follows:
socket.receive(asio::buffer(data, size));
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ receive() [2/3]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure. An error code of 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 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 asio::buffer function as follows:
socket.receive(asio::buffer(data, size), 0);
See the asio::buffer documentation for information on receiving into multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ receive() [3/3]

template<typename Protocol, typename Executor>
template<typename MutableBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::receive ( const MutableBufferSequence &  buffers,
socket_base::message_flags  flags,
asio::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 asio::read function if you need to ensure that the requested amount of data is read before the blocking operation completes.

◆ send() [1/3]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure.
Note
The send operation may not transmit all of the data to the peer. Consider using the 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 asio::buffer function as follows:
socket.send(asio::buffer(data, size));
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ send() [2/3]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure.
Note
The send operation may not transmit all of the data to the peer. Consider using the 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 asio::buffer function as follows:
socket.send(asio::buffer(data, size), 0);
See the asio::buffer documentation for information on sending multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ send() [3/3]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::send ( const ConstBufferSequence &  buffers,
socket_base::message_flags  flags,
asio::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 asio::write function if you need to ensure that all data is written before the blocking operation completes.

◆ write_some() [1/2]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::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
asio::system_errorThrown on failure. An error code of 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 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 asio::buffer function as follows:
socket.write_some(asio::buffer(data, size));
See the asio::buffer documentation for information on writing multiple buffers in one go, and how to use it with arrays, boost::array or std::vector.

◆ write_some() [2/2]

template<typename Protocol, typename Executor>
template<typename ConstBufferSequence >
std::size_t asio::basic_stream_socket< Protocol, Executor >::write_some ( const ConstBufferSequence &  buffers,
asio::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 asio::write function if you need to ensure that all data is written before the blocking operation completes.

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