Realistic 3D camera system
3D camera system components
Public Types | Public Member Functions | Protected Member Functions | List of all members
asio::basic_socket< Protocol, SocketService > Class Template Reference

Provides socket functionality. More...

#include <basic_socket.hpp>

Inheritance diagram for asio::basic_socket< Protocol, SocketService >:
asio::basic_io_object< SocketService > asio::socket_base

Public Types

typedef SocketService::native_handle_type native_type
 
typedef SocketService::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, SocketService > lowest_layer_type
 A basic_socket is always the lowest layer. More...
 
- Public Types inherited from asio::basic_io_object< SocketService >
typedef SocketService 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...
 
- 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. More...
 
typedef int message_flags
 Bitmask type for flags that can be passed to send and receive operations. More...
 
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
 
typedef asio::detail::socket_option::linger< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_LINGER)> linger
 
typedef asio::detail::socket_option::boolean< asio::detail::custom_socket_option_level, asio::detail::enable_connection_aborted_optionenable_connection_aborted
 Socket option to report aborted connections on accept. More...
 
typedef asio::detail::io_control::non_blocking_io non_blocking_io
 
typedef asio::detail::io_control::bytes_readable bytes_readable
 

Public Member Functions

 basic_socket (asio::io_service &io_service)
 Construct a basic_socket without opening it. More...
 
 basic_socket (asio::io_service &io_service, const protocol_type &protocol)
 Construct and open a basic_socket. More...
 
 basic_socket (asio::io_service &io_service, const endpoint_type &endpoint)
 
 basic_socket (asio::io_service &io_service, const protocol_type &protocol, const native_handle_type &native_socket)
 Construct a basic_socket on an existing native socket. More...
 
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::error_code 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. More...
 
asio::error_code assign (const protocol_type &protocol, const native_handle_type &native_socket, asio::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...
 
asio::error_code close (asio::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...
 
asio::error_code 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::error_code 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::error_code connect (const endpoint_type &peer_endpoint, asio::error_code &ec)
 Connect the socket to the specified endpoint. More...
 
template<typename ConnectHandler >
 ASIO_INITFN_RESULT_TYPE (ConnectHandler, void(asio::error_code)) async_connect(const endpoint_type &peer_endpoint
 Start an asynchronous connect. More...
 
 ASIO_MOVE_ARG (ConnectHandler) handler)
 
template<typename SettableSocketOption >
void set_option (const SettableSocketOption &option)
 Set an option on the socket. More...
 
template<typename SettableSocketOption >
asio::error_code 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::error_code 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::error_code 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::error_code 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::error_code 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::error_code shutdown (shutdown_type what, asio::error_code &ec)
 Disable sends or receives on the socket. More...
 
- Public Member Functions inherited from asio::basic_io_object< SocketService >
asio::io_serviceget_io_service ()
 Get the io_service associated with the object. More...
 
- 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_connections=ASIO_OS_DEF(SOMAXCONN))
 The maximum length of the queue of pending incoming connections. More...
 

Protected Member Functions

 ~basic_socket ()
 Protected destructor to prevent deletion through this type. More...
 
- Protected Member Functions inherited from asio::basic_io_object< SocketService >
 basic_io_object (asio::io_service &io_service)
 Construct a basic_io_object. More...
 
 ~basic_io_object ()
 Protected destructor to prevent deletion through this type. More...
 
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 Member Functions inherited from asio::socket_base
 ~socket_base ()
 Protected destructor to prevent deletion through this type. More...
 

Additional Inherited Members

- Protected Attributes inherited from asio::basic_io_object< SocketService >
service_typeservice
 
implementation_type implementation
 

Detailed Description

template<typename Protocol, typename SocketService>
class asio::basic_socket< Protocol, SocketService >

Provides socket functionality.

The basic_socket class template provides functionality that is common to both stream-oriented and datagram-oriented sockets.

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

Definition at line 41 of file basic_socket.hpp.

Member Typedef Documentation

template<typename Protocol, typename SocketService>
typedef Protocol::endpoint asio::basic_socket< Protocol, SocketService >::endpoint_type

The endpoint type.

Definition at line 57 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
typedef basic_socket<Protocol, SocketService> asio::basic_socket< Protocol, SocketService >::lowest_layer_type

A basic_socket is always the lowest layer.

Definition at line 60 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
typedef SocketService::native_handle_type asio::basic_socket< Protocol, SocketService >::native_handle_type

The native representation of a socket.

Definition at line 51 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
typedef SocketService::native_handle_type asio::basic_socket< Protocol, SocketService >::native_type

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

Definition at line 48 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
typedef Protocol asio::basic_socket< Protocol, SocketService >::protocol_type

The protocol type.

Definition at line 54 of file basic_socket.hpp.

Constructor & Destructor Documentation

template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::basic_socket ( asio::io_service io_service)
inlineexplicit

Construct a basic_socket without opening it.

This constructor creates a socket without opening it.

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

Definition at line 69 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::basic_socket ( asio::io_service io_service,
const protocol_type protocol 
)
inline

Construct and open a basic_socket.

This constructor creates and opens a socket.

Parameters
io_serviceThe io_service object that the socket will use 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.

Definition at line 85 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::basic_socket ( asio::io_service io_service,
const endpoint_type endpoint 
)
inline

Construct a basic_socket, opening it and binding it to the given local endpoint. This constructor creates a 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 socket will use to dispatch handlers for any asynchronous operations performed on the socket.
endpointAn endpoint on the local machine to which the socket will be bound.
Exceptions
asio::system_errorThrown on failure.

Definition at line 109 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::basic_socket ( asio::io_service io_service,
const protocol_type protocol,
const native_handle_type native_socket 
)
inline

Construct a basic_socket on an existing native socket.

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

Parameters
io_serviceThe io_service object that the socket will use to dispatch handlers for any asynchronous operations performed on the socket.
protocolAn object specifying protocol parameters to be used.
native_socketA native socket.
Exceptions
asio::system_errorThrown on failure.

Definition at line 134 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::~basic_socket ( )
inlineprotected

Protected destructor to prevent deletion through this type.

Definition at line 1509 of file basic_socket.hpp.

Member Function Documentation

template<typename Protocol, typename SocketService>
template<typename ConnectHandler >
asio::basic_socket< Protocol, SocketService >::ASIO_INITFN_RESULT_TYPE ( ConnectHandler  ,
void(asio::error_code  
) const

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 asio::error_code& error // Result of operation
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. Invocation of the handler will be performed in a manner equivalent to using asio::io_service::post().
Example
{
if (!error)
{
// Connect succeeded.
}
}
...
asio::ip::tcp::socket socket(io_service);
asio::ip::address::from_string("1.2.3.4"), 12345);
socket.async_connect(endpoint, connect_handler);
template<typename Protocol, typename SocketService>
asio::basic_socket< Protocol, SocketService >::ASIO_MOVE_ARG ( ConnectHandler  )
inline

Definition at line 750 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::assign ( const protocol_type protocol,
const native_handle_type native_socket 
)
inline

Assign an existing native socket to the socket.

Definition at line 308 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::assign ( const protocol_type protocol,
const native_handle_type native_socket,
asio::error_code ec 
)
inline

Assign an existing native socket to the socket.

Definition at line 327 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
bool asio::basic_socket< Protocol, SocketService >::at_mark ( ) const
inline

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

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

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

Definition at line 514 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
bool asio::basic_socket< Protocol, SocketService >::at_mark ( asio::error_code ec) const
inline

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.

Definition at line 532 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
std::size_t asio::basic_socket< Protocol, SocketService >::available ( ) const
inline

Determine the number of bytes available for reading.

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

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

Definition at line 547 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
std::size_t asio::basic_socket< Protocol, SocketService >::available ( asio::error_code ec) const
inline

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.

Definition at line 566 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::bind ( const endpoint_type endpoint)
inline

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
asio::system_errorThrown on failure.
Example

Definition at line 589 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::bind ( const endpoint_type endpoint,
asio::error_code ec 
)
inline

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
asio::ip::tcp::v4(), 12345), ec);
if (ec)
{
// An error occurred.
}

Definition at line 619 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::cancel ( )
inline

Cancel all asynchronous operations associated with the socket.

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

Exceptions
asio::system_errorThrown on failure.
Note
Calls to cancel() will always fail with asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless 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 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.

Definition at line 451 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::cancel ( asio::error_code ec)
inline

Cancel all asynchronous operations associated with the socket.

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

Parameters
ecSet to indicate what error occurred, if any.
Note
Calls to cancel() will always fail with asio::error::operation_not_supported when run on Windows XP, Windows Server 2003, and earlier versions of Windows, unless 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 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.

Definition at line 499 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::close ( )
inline

Close the socket.

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

Exceptions
asio::system_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.

Definition at line 352 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::close ( asio::error_code ec)
inline

Close the socket.

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

Parameters
ecSet to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
Example
...
asio::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.

Definition at line 383 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::connect ( const endpoint_type peer_endpoint)
inline

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
asio::system_errorThrown on failure.
Example
asio::ip::address::from_string("1.2.3.4"), 12345);
socket.connect(endpoint);

Definition at line 648 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::connect ( const endpoint_type peer_endpoint,
asio::error_code ec 
)
inline

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
asio::ip::address::from_string("1.2.3.4"), 12345);
socket.connect(endpoint, ec);
if (ec)
{
// An error occurred.
}

Definition at line 689 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename GettableSocketOption >
void asio::basic_socket< Protocol, SocketService >::get_option ( GettableSocketOption &  option) const
inline

Get an option from the socket.

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

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

Definition at line 905 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename GettableSocketOption >
asio::error_code asio::basic_socket< Protocol, SocketService >::get_option ( GettableSocketOption &  option,
asio::error_code ec 
) const
inline

Get an option from the socket.

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

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

Definition at line 953 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename IoControlCommand >
void asio::basic_socket< Protocol, SocketService >::io_control ( IoControlCommand &  command)
inline

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
asio::system_errorThrown on failure.
See also
IoControlCommand
asio::socket_base::bytes_readable
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
...
asio::ip::tcp::socket::bytes_readable command;
socket.io_control(command);
std::size_t bytes_readable = command.get();

Definition at line 983 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename IoControlCommand >
asio::error_code asio::basic_socket< Protocol, SocketService >::io_control ( IoControlCommand &  command,
asio::error_code ec 
)
inline

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
asio::socket_base::bytes_readable
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
...
asio::ip::tcp::socket::bytes_readable command;
socket.io_control(command, ec);
if (ec)
{
// An error occurred.
}
std::size_t bytes_readable = command.get();

Definition at line 1018 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
bool asio::basic_socket< Protocol, SocketService >::is_open ( ) const
inline

Determine whether the socket is open.

Definition at line 335 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
endpoint_type asio::basic_socket< Protocol, SocketService >::local_endpoint ( ) const
inline

Get the local endpoint of the socket.

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

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

Definition at line 1370 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
endpoint_type asio::basic_socket< Protocol, SocketService >::local_endpoint ( asio::error_code ec) const
inline

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

Definition at line 1400 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
lowest_layer_type& asio::basic_socket< Protocol, SocketService >::lowest_layer ( )
inline

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.

Definition at line 233 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
const lowest_layer_type& asio::basic_socket< Protocol, SocketService >::lowest_layer ( ) const
inline

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.

Definition at line 247 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
native_type asio::basic_socket< Protocol, SocketService >::native ( )
inline

(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.

Definition at line 394 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
native_handle_type asio::basic_socket< Protocol, SocketService >::native_handle ( )
inline

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.

Definition at line 405 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
bool asio::basic_socket< Protocol, SocketService >::native_non_blocking ( ) const
inline

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 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()(asio::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 = asio::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(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(asio::null_buffers(), op);
}

Definition at line 1165 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::native_non_blocking ( bool  mode)
inline

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 asio::error::would_block (or the equivalent system error).
Exceptions
asio::system_errorThrown on failure. If the mode is false, but the current value of non_blocking() is true, this function fails with 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()(asio::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 = asio::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(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(asio::null_buffers(), op);
}

Definition at line 1255 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::native_non_blocking ( bool  mode,
asio::error_code ec 
)
inline

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 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 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()(asio::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 = asio::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(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(asio::null_buffers(), op);
}

Definition at line 1348 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
bool asio::basic_socket< Protocol, SocketService >::non_blocking ( ) const
inline

Gets the non-blocking mode of the socket.

Returns
true if the socket's synchronous operations will fail with 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 asio::error::would_block.

Definition at line 1036 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::non_blocking ( bool  mode)
inline

Sets the non-blocking mode of the socket.

Parameters
modeIf true, the socket's synchronous operations will fail with asio::error::would_block if they are unable to perform the requested operation immediately. If false, synchronous operations will block until complete.
Exceptions
asio::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 asio::error::would_block.

Definition at line 1054 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::non_blocking ( bool  mode,
asio::error_code ec 
)
inline

Sets the non-blocking mode of the socket.

Parameters
modeIf true, the socket's synchronous operations will fail with 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 asio::error::would_block.

Definition at line 1074 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::open ( const protocol_type protocol = protocol_type())
inline

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
asio::system_errorThrown on failure.
Example

Definition at line 266 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::open ( const protocol_type protocol,
asio::error_code ec 
)
inline

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
if (ec)
{
// An error occurred.
}

Definition at line 292 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
endpoint_type asio::basic_socket< Protocol, SocketService >::remote_endpoint ( ) const
inline

Get the remote endpoint of the socket.

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

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

Definition at line 1420 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
endpoint_type asio::basic_socket< Protocol, SocketService >::remote_endpoint ( asio::error_code ec) const
inline

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

Definition at line 1450 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename SettableSocketOption >
void asio::basic_socket< Protocol, SocketService >::set_option ( const SettableSocketOption &  option)
inline

Set an option on the socket.

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

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

Definition at line 815 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
template<typename SettableSocketOption >
asio::error_code asio::basic_socket< Protocol, SocketService >::set_option ( const SettableSocketOption &  option,
asio::error_code ec 
)
inline

Set an option on the socket.

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

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

Definition at line 862 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
void asio::basic_socket< Protocol, SocketService >::shutdown ( shutdown_type  what)
inline

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
asio::system_errorThrown on failure.
Example
Shutting down the send side of the socket:

Definition at line 1472 of file basic_socket.hpp.

template<typename Protocol, typename SocketService>
asio::error_code asio::basic_socket< Protocol, SocketService >::shutdown ( shutdown_type  what,
asio::error_code ec 
)
inline

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:
...
asio::error_code ec;
if (ec)
{
// An error occurred.
}

Definition at line 1501 of file basic_socket.hpp.


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