from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Move-construct a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> basic_raw_socket( basic_raw_socket< Protocol1, RawSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
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.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
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.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_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.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
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.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & 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.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
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.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, RawSocketService > lowest_layer_type;
|
Name |
Description |
|---|---|
|
Socket option to permit sending of broadcast messages. |
|
|
IO control command to get the amount of data that can be read without blocking. |
|
|
Socket option to enable socket-level debugging. |
|
|
Socket option to prevent routing, use local interfaces only. |
|
|
Socket option to report aborted connections on accept. |
|
|
The endpoint type. |
|
|
The underlying implementation type of I/O object. |
|
|
Socket option to send keep-alives. |
|
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
|
A basic_socket is always the lowest layer. |
|
|
Bitmask type for flags that can be passed to send and receive operations. |
|
|
The native representation of a socket. |
|
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
|
The protocol type. |
|
|
Socket option for the receive buffer size of a socket. |
|
|
Socket option for the receive low watermark. |
|
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
|
Socket option for the send buffer size of a socket. |
|
|
Socket option for the send low watermark. |
|
|
The type of the service that will be used to provide I/O operations. |
|
|
Different ways a socket may be shutdown. |
|
Name |
Description |
|---|---|
|
Assign an existing native socket to the socket. |
|
|
Start an asynchronous connect. |
|
|
Determine whether the socket is at the out-of-band data mark. |
|
|
Determine the number of bytes available for reading. |
|
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another.  Get a const reference to the lowest layer. |
|
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
|
Get the native socket representation. |
|
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
|
Open the socket using the specified protocol. |
|
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
|
Get the remote endpoint of the socket. |
|
|
Set an option on the socket. |
|
|
Disable sends or receives on the socket. |
|
Name |
Description |
|---|---|
|
Get the underlying implementation of the I/O object. |
|
|
Get the service associated with the I/O object. |
|
|
Protected destructor to prevent deletion through this type. |
|
Name |
Description |
|---|---|
|
The maximum length of the queue of pending incoming connections. |
|
|
Specify that the data should not be subject to routing. |
|
|
Specifies that the data marks the end of a record. |
|
|
Process out-of-band data. |
|
|
Peek at incoming data without removing it from the input queue. |
|
Name |
Description |
|---|---|
|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
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.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
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.
The native representation of a socket.
typedef RawSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
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.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
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.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
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.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
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.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef RawSocketService::native_handle_type native_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_raw_socket
from another.
basic_raw_socket & operator=( basic_raw_socket && other); » more...
Move-assign a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_raw_socket >::type & operator=( basic_raw_socket< Protocol1, RawSocketService1 > && other); » more...
Move-assign a basic_raw_socket
from another.
basic_raw_socket & operator=( basic_raw_socket && other);
This assignment operator moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
Move-assign a basic_raw_socket
from a socket
of another protocol type.
template< typename Protocol1, typename RawSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_raw_socket >::type & operator=( basic_raw_socket< Protocol1, RawSocketService1 > && other);
This assignment operator moves a raw socket from one object to another.
The other basic_raw_socket
object
from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_raw_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers);
This function is used to receive data on the raw socket. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size));
See the 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 some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags);
This function is used to receive data on the raw socket. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to receive data on the raw socket. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
The receive operation can only be used with a connected socket. Use the receive_from function to receive data on an unconnected raw socket.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags); » more... template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
The number of bytes received.
Thrown on failure.
To receive into a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint sender_endpoint; socket.receive_from( boost::asio::buffer(data, size), sender_endpoint);
See the 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 raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
Flags specifying how the receive call is to be made.
The number of bytes received.
Thrown on failure.
Receive raw data with the endpoint of the sender.
template< typename MutableBufferSequence> std::size_t receive_from( const MutableBufferSequence & buffers, endpoint_type & sender_endpoint, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to receive raw data. The function call will block until data has been received successfully or an error occurs.
One or more buffers into which the data will be received.
An endpoint object that receives the endpoint of the remote sender of the data.
Flags specifying how the receive call is to be made.
Set to indicate what error occurred, if any.
The number of bytes received.
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers);
This function is used to send data on the raw socket. The function call will block until the data has been sent successfully or an error occurs.
One ore more data buffers to be sent on the socket.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size));
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
This function is used to send data on the raw socket. The function call will block until the data has been sent successfully or an error occurs.
One ore more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
Send some data on a connected socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to send data on the raw socket. The function call will block until the data has been sent successfully or an error occurs.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
The send operation can only be used with a connected socket. Use the send_to function to send data on an unconnected raw socket.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination);
This function is used to send raw data to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
The number of bytes sent.
Thrown on failure.
To send a single data buffer use the buffer
function as follows:
boost::asio::ip::udp::endpoint destination( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); socket.send_to(boost::asio::buffer(data, size), destination);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags);
This function is used to send raw data to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
Send raw data to the specified endpoint.
template< typename ConstBufferSequence> std::size_t send_to( const ConstBufferSequence & buffers, const endpoint_type & destination, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to send raw data to the specified remote endpoint. The function call will block until the data has been sent successfully or an error occurs.
One or more data buffers to be sent to the remote endpoint.
The remote endpoint to which the data will be sent.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent.
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef RawSocketService service_type;
Header: boost/asio/basic_raw_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides sequenced packet socket functionality.
template< typename Protocol, typename SeqPacketSocketService = seq_packet_socket_service<Protocol>> class basic_seq_packet_socket : public basic_socket< Protocol, SeqPacketSocketService >
|
Name |
Description |
|---|---|
|
Socket option to permit sending of broadcast messages. |
|
|
IO control command to get the amount of data that can be read without blocking. |
|
|
Socket option to enable socket-level debugging. |
|
|
Socket option to prevent routing, use local interfaces only. |
|
|
Socket option to report aborted connections on accept. |
|
|
The endpoint type. |
|
|
The underlying implementation type of I/O object. |
|
|
Socket option to send keep-alives. |
|
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
|
A basic_socket is always the lowest layer. |
|
|
Bitmask type for flags that can be passed to send and receive operations. |
|
|
The native representation of a socket. |
|
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
|
The protocol type. |
|
|
Socket option for the receive buffer size of a socket. |
|
|
Socket option for the receive low watermark. |
|
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
|
Socket option for the send buffer size of a socket. |
|
|
Socket option for the send low watermark. |
|
|
The type of the service that will be used to provide I/O operations. |
|
|
Different ways a socket may be shutdown. |
|
Name |
Description |
|---|---|
|
Assign an existing native socket to the socket. |
|
|
Start an asynchronous connect. |
|
|
Start an asynchronous receive. |
|
|
Start an asynchronous send. |
|
|
Determine whether the socket is at the out-of-band data mark. |
|
|
Determine the number of bytes available for reading. |
|
|
Construct a basic_seq_packet_socket without opening it. Construct and open a basic_seq_packet_socket. Construct a basic_seq_packet_socket, opening it and binding it to the given local endpoint. Construct a basic_seq_packet_socket on an existing native socket. Move-construct a basic_seq_packet_socket from another.  Get a const reference to the lowest layer. |
|
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
|
Get the native socket representation. |
|
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
|
Open the socket using the specified protocol. |
|
|
Move-assign a basic_seq_packet_socket from another. Move-assign a basic_seq_packet_socket from a socket of another protocol type. |
|
|
Receive some data on the socket. Receive some data on a connected socket. |
|
|
Get the remote endpoint of the socket. |
|
|
Send some data on the socket. |
|
|
Set an option on the socket. |
|
|
Disable sends or receives on the socket. |
|
Name |
Description |
|---|---|
|
Get the underlying implementation of the I/O object. |
|
|
Get the service associated with the I/O object. |
|
Name |
Description |
|---|---|
|
The maximum length of the queue of pending incoming connections. |
|
|
Specify that the data should not be subject to routing. |
|
|
Specifies that the data marks the end of a record. |
|
|
Process out-of-band data. |
|
|
Peek at incoming data without removing it from the input queue. |
|
Name |
Description |
|---|---|
|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_seq_packet_socket
class template
provides asynchronous and blocking sequenced packet socket functionality.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_socket);
Inherited from basic_socket.
Assign an existing native socket to the socket.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_socket, boost::system::error_code & ec);
Inherited from basic_socket.
Start an asynchronous connect.
template< typename ConnectHandler> void-or-deduced async_connect( const endpoint_type & peer_endpoint, ConnectHandler handler);
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.
The remote endpoint to which the socket will be connected. Copies will be made of the endpoint object as required.
The handler to be called when the connection operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error // Result of operation );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
void connect_handler(const boost::system::error_code& error) { if (!error) { // Connect succeeded. } } ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); socket.async_connect(endpoint, connect_handler);
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags, ReadHandler handler); » more... template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, ReadHandler handler); » more...
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags, ReadHandler handler);
This function is used to asynchronously receive data from the sequenced packet socket. The function call always returns immediately.
One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
Once the asynchronous operation completes, contains flags associated
with the received data. For example, if the socket_base::message_end_of_record
bit is set then the received data marks the end of a record. The
caller must guarantee that the referenced variable remains valid
until the handler is called.
The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive(boost::asio::buffer(data, size), out_flags, handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
Start an asynchronous receive.
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, ReadHandler handler);
This function is used to asynchronously receive data from the sequenced data socket. The function call always returns immediately.
One or more buffers into which the data will be received. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
Flags specifying how the receive call is to be made.
Once the asynchronous operation completes, contains flags associated
with the received data. For example, if the socket_base::message_end_of_record
bit is set then the received data marks the end of a record. The
caller must guarantee that the referenced variable remains valid
until the handler is called.
The handler to be called when the receive operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes received. );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
To receive into a single data buffer use the buffer
function as follows:
socket.async_receive( boost::asio::buffer(data, size), 0, out_flags, handler);
See the buffer
documentation for information on receiving into multiple buffers in one
go, and how to use it with arrays, boost::array or std::vector.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_send( const ConstBufferSequence & buffers, socket_base::message_flags flags, WriteHandler handler);
This function is used to asynchronously send data on the sequenced packet socket. The function call always returns immediately.
One or more data buffers to be sent on the socket. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
Flags specifying how the send call is to be made.
The handler to be called when the send operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes sent. );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
To send a single data buffer use the buffer
function as follows:
socket.async_send(boost::asio::buffer(data, size), 0, handler);
See the buffer
documentation for information on sending multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const; » more... bool at_mark( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark() const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
A bool indicating whether the socket is at the out-of-band data mark.
Thrown on failure.
Inherited from basic_socket.
Determine whether the socket is at the out-of-band data mark.
bool at_mark( boost::system::error_code & ec) const;
This function is used to check whether the socket input is currently positioned at the out-of-band data mark.
Set to indicate what error occurred, if any.
A bool indicating whether the socket is at the out-of-band data mark.
Determine the number of bytes available for reading.
std::size_t available() const; » more... std::size_t available( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available() const;
This function is used to determine the number of bytes that may be read without blocking.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Thrown on failure.
Inherited from basic_socket.
Determine the number of bytes available for reading.
std::size_t available( boost::system::error_code & ec) const;
This function is used to determine the number of bytes that may be read without blocking.
Set to indicate what error occurred, if any.
The number of bytes that may be read without blocking, or 0 if an error occurs.
Construct a basic_seq_packet_socket
without
opening it.
explicit basic_seq_packet_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_seq_packet_socket
.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_seq_packet_socket
, opening
it and binding it to the given local endpoint.
basic_seq_packet_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_seq_packet_socket
on an
existing native socket.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_seq_packet_socket
from another.
basic_seq_packet_socket( basic_seq_packet_socket && other); » more...
Move-construct a basic_seq_packet_socket
from a
socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> basic_seq_packet_socket( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_seq_packet_socket
without
opening it.
basic_seq_packet_socket( boost::asio::io_service & io_service);
This constructor creates a sequenced packet socket without opening it. The socket needs to be opened and then connected or accepted before data can be sent or received on it.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
Construct and open a basic_seq_packet_socket
.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates and opens a sequenced_packet socket. The socket needs to be connected or accepted before data can be sent or received on it.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct a basic_seq_packet_socket
, opening
it and binding it to the given local endpoint.
basic_seq_packet_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint);
This constructor creates a sequenced packet 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.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An endpoint on the local machine to which the sequenced packet socket will be bound.
Thrown on failure.
Construct a basic_seq_packet_socket
on an
existing native socket.
basic_seq_packet_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a sequenced packet socket object to hold an existing native socket.
The io_service
object that
the sequenced packet socket will use to dispatch handlers for any
asynchronous operations performed on the socket.
An object specifying protocol parameters to be used.
The new underlying socket implementation.
Thrown on failure.
Move-construct a basic_seq_packet_socket
from
another.
basic_seq_packet_socket( basic_seq_packet_socket && other);
This constructor moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Move-construct a basic_seq_packet_socket
from
a socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> basic_seq_packet_socket( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint); » more... boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Bind the socket to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345));
Inherited from basic_socket.
Bind the socket to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4()); boost::system::error_code ec; socket.bind(boost::asio::ip::tcp::endpoint( boost::asio::ip::tcp::v4(), 12345), ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to permit sending of broadcast messages.
typedef implementation_defined broadcast;
Implements the SOL_SOCKET/SO_BROADCAST socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::broadcast option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
IO control command to get the amount of data that can be read without blocking.
typedef implementation_defined bytes_readable;
Implements the FIONREAD IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::bytes_readable command(true); socket.io_control(command); std::size_t bytes_readable = command.get();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the socket.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
void cancel();
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
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.
Inherited from basic_socket.
Cancel all asynchronous operations associated with the socket.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous connect, send and receive
operations to finish immediately, and the handlers for cancelled operations
will be passed the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
Calls to cancel()
will always fail with boost::asio::error::operation_not_supported
when run on Windows XP, Windows Server 2003, and earlier versions of
Windows, unless BOOST_ASIO_ENABLE_CANCELIO is defined. However, the CancelIo
function has two issues that should be considered before enabling its
use:
For portable cancellation, consider using one of the following alternatives:
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.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Inherited from basic_socket.
Close the socket.
void close();
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure. Note that, even if the function indicates an error, the underlying descriptor is closed.
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Inherited from basic_socket.
Close the socket.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the socket. Any asynchronous send, receive
or connect operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any. Note that, even if the function indicates an error, the underlying descriptor is closed.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.close(ec); if (ec) { // An error occurred. }
For portable behaviour with respect to graceful closure of a connected
socket, call shutdown()
before closing the socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_endpoint); » more... boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Connect the socket to the specified endpoint.
void connect( const endpoint_type & peer_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.
The remote endpoint to which the socket will be connected.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); socket.connect(endpoint);
Inherited from basic_socket.
Connect the socket to the specified endpoint.
boost::system::error_code connect( const endpoint_type & peer_endpoint, boost::system::error_code & ec);
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.
The remote endpoint to which the socket will be connected.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint( boost::asio::ip::address::from_string("<IP_ADDRESS>"), 12345); boost::system::error_code ec; socket.connect(endpoint, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to enable socket-level debugging.
typedef implementation_defined debug;
Implements the SOL_SOCKET/SO_DEBUG socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::debug option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to prevent routing, use local interfaces only.
typedef implementation_defined do_not_route;
Implements the SOL_SOCKET/SO_DONTROUTE socket option.
Setting the option:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::udp::socket socket(io_service); ... boost::asio::socket_base::do_not_route option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to report aborted connections on accept.
typedef implementation_defined enable_connection_aborted;
Implements a custom socket option that determines whether or not an accept
operation is permitted to fail with boost::asio::error::connection_aborted
.
By default the option is false.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::enable_connection_aborted option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the underlying implementation of the I/O object.
implementation_type & get_implementation(); » more... const implementation_type & get_implementation() const; » more...
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
implementation_type & get_implementation();
Inherited from basic_io_object.
Get the underlying implementation of the I/O object.
const implementation_type & get_implementation() const;
Inherited from basic_io_object.
Get the io_service
associated with the
object.
boost::asio::io_service & get_io_service();
This function may be used to obtain the io_service
object that the I/O
object uses to dispatch handlers for asynchronous operations.
A reference to the io_service
object that the I/O
object will use to dispatch handlers. Ownership is not transferred to the
caller.
Get an option from the socket.
void get_option( GettableSocketOption & option) const; » more... boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; socket.get_option(option); bool is_set = option.value();
Inherited from basic_socket.
Get an option from the socket.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const;
This function is used to get the current value of an option on the socket.
The option value to be obtained from the socket.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_KEEPALIVE option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::keep_alive option; boost::system::error_code ec; socket.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.value();
Get the service associated with the I/O object.
service_type & get_service(); » more... const service_type & get_service() const; » more...
Inherited from basic_io_object.
Get the service associated with the I/O object.
service_type & get_service();
Inherited from basic_io_object.
Get the service associated with the I/O object.
const service_type & get_service() const;
Inherited from basic_io_object.
(Deprecated: Use get_implementation()
.) The underlying implementation of the
I/O object.
implementation_type implementation;
Inherited from basic_io_object.
The underlying implementation type of I/O object.
typedef service_type::implementation_type implementation_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
void io_control( IoControlCommand & command); » more... boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; socket.io_control(command); std::size_t bytes_readable = command.get();
Inherited from basic_socket.
Perform an IO control command on the socket.
template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec);
This function is used to execute an IO control command on the socket.
The IO control command to be performed on the socket.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::socket::bytes_readable command; boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. } std::size_t bytes_readable = command.get();
Inherited from socket_base.
Socket option to send keep-alives.
typedef implementation_defined keep_alive;
Implements the SOL_SOCKET/SO_KEEPALIVE socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option(true); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::keep_alive option; socket.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option to specify whether the socket lingers on close if unsent data is present.
typedef implementation_defined linger;
Implements the SOL_SOCKET/SO_LINGER socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option(true, 30); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::linger option; socket.get_option(option); bool is_set = option.enabled(); unsigned short timeout = option.timeout();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the local endpoint of the socket.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the socket.
An object that represents the local endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint();
Inherited from basic_socket.
Get the local endpoint of the socket.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.local_endpoint(ec); if (ec) { // An error occurred. }
Get a reference to the lowest layer.
lowest_layer_type & lowest_layer(); » more...
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const; » more...
Inherited from basic_socket.
Get a reference to the lowest layer.
lowest_layer_type & 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.
A reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
Get a const reference to the lowest layer.
const lowest_layer_type & lowest_layer() const;
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.
A const reference to the lowest layer in the stack of layers. Ownership is not transferred to the caller.
Inherited from basic_socket.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, SeqPacketSocketService > lowest_layer_type;
|
Name |
Description |
|---|---|
|
Socket option to permit sending of broadcast messages. |
|
|
IO control command to get the amount of data that can be read without blocking. |
|
|
Socket option to enable socket-level debugging. |
|
|
Socket option to prevent routing, use local interfaces only. |
|
|
Socket option to report aborted connections on accept. |
|
|
The endpoint type. |
|
|
The underlying implementation type of I/O object. |
|
|
Socket option to send keep-alives. |
|
|
Socket option to specify whether the socket lingers on close if unsent data is present. |
|
|
A basic_socket is always the lowest layer. |
|
|
Bitmask type for flags that can be passed to send and receive operations. |
|
|
The native representation of a socket. |
|
|
(Deprecated: Use native_handle_type.) The native representation of a socket. |
|
|
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket. |
|
|
The protocol type. |
|
|
Socket option for the receive buffer size of a socket. |
|
|
Socket option for the receive low watermark. |
|
|
Socket option to allow the socket to be bound to an address that is already in use. |
|
|
Socket option for the send buffer size of a socket. |
|
|
Socket option for the send low watermark. |
|
|
The type of the service that will be used to provide I/O operations. |
|
|
Different ways a socket may be shutdown. |
|
Name |
Description |
|---|---|
|
Assign an existing native socket to the socket. |
|
|
Start an asynchronous connect. |
|
|
Determine whether the socket is at the out-of-band data mark. |
|
|
Determine the number of bytes available for reading. |
|
|
Construct a basic_socket without opening it. Construct and open a basic_socket. Construct a basic_socket, opening it and binding it to the given local endpoint. Construct a basic_socket on an existing native socket. Move-construct a basic_socket from another.  Get a const reference to the lowest layer. |
|
|
(Deprecated: Use native_handle().) Get the native socket representation. |
|
|
Get the native socket representation. |
|
|
Gets the non-blocking mode of the native socket implementation. Sets the non-blocking mode of the native socket implementation. |
|
|
Gets the non-blocking mode of the socket. Sets the non-blocking mode of the socket. |
|
|
Open the socket using the specified protocol. |
|
|
Move-assign a basic_socket from another. Move-assign a basic_socket from a socket of another protocol type. |
|
|
Get the remote endpoint of the socket. |
|
|
Set an option on the socket. |
|
|
Disable sends or receives on the socket. |
|
Name |
Description |
|---|---|
|
Get the underlying implementation of the I/O object. |
|
|
Get the service associated with the I/O object. |
|
|
Protected destructor to prevent deletion through this type. |
|
Name |
Description |
|---|---|
|
The maximum length of the queue of pending incoming connections. |
|
|
Specify that the data should not be subject to routing. |
|
|
Specifies that the data marks the end of a record. |
|
|
Process out-of-band data. |
|
|
Peek at incoming data without removing it from the input queue. |
|
Name |
Description |
|---|---|
|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_socket
class template provides functionality that is common to both stream-oriented
and datagram-oriented sockets.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
The maximum length of the queue of pending incoming connections.
static const int max_connections = implementation_defined;
Inherited from socket_base.
Specify that the data should not be subject to routing.
static const int message_do_not_route = implementation_defined;
Inherited from socket_base.
Specifies that the data marks the end of a record.
static const int message_end_of_record = implementation_defined;
Inherited from socket_base.
Bitmask type for flags that can be passed to send and receive operations.
typedef int message_flags;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
static const int message_out_of_band = implementation_defined;
Inherited from socket_base.
Peek at incoming data without removing it from the input queue.
static const int message_peek = implementation_defined;
Inherited from basic_socket.
(Deprecated: Use native_handle()
.) Get the native socket representation.
native_type native();
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.
Inherited from basic_socket.
Get the native socket representation.
native_handle_type native_handle();
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.
The native representation of a socket.
typedef SeqPacketSocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the native socket implementation.
bool native_non_blocking() const;
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.
true
if the underlying socket
is in non-blocking mode and direct system calls may fail with boost::asio::error::would_block
(or the equivalent system
error).
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.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
void native_non_blocking( bool mode);
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.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Thrown on failure. If the mode
is false
, but the
current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
Inherited from basic_socket.
Sets the non-blocking mode of the native socket implementation.
boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec);
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.
If true
, the underlying
socket is put into non-blocking mode and direct system calls may
fail with boost::asio::error::would_block
(or the equivalent system error).
Set to indicate what error occurred, if any. If the mode
is false
,
but the current value of non_blocking()
is true
,
this function fails with boost::asio::error::invalid_argument
,
as the combination does not make sense.
This function is intended to allow the encapsulation of arbitrary non-blocking
system calls as asynchronous operations, in a way that is transparent
to the user of the socket object. The following example illustrates how
Linux's sendfile
system
call might be encapsulated:
template <typename Handler> struct sendfile_op { tcp::socket& sock_; int fd_; Handler handler_; off_t offset_; std::size_t total_bytes_transferred_; // Function call operator meeting WriteHandler requirements. // Used as the handler for the async_write_some operation. void operator()(boost::system::error_code ec, std::size_t) { // Put the underlying socket into non-blocking mode. if (!ec) if (!sock_.native_non_blocking()) sock_.native_non_blocking(true, ec); if (!ec) { for (;;) { // Try the system call. errno = 0; int n = ::sendfile(sock_.native_handle(), fd_, &offset_, 65536); ec = boost::system::error_code(n < 0 ? errno : 0, boost::asio::error::get_system_category()); total_bytes_transferred_ += ec ? 0 : n; // Retry operation immediately if interrupted by signal. if (ec == boost::asio::error::interrupted) continue; // Check if we need to run the operation again. if (ec == boost::asio::error::would_block || ec == boost::asio::error::try_again) { // We have to wait for the socket to become ready again. sock_.async_write_some(boost::asio::null_buffers(), *this); return; } if (ec || n == 0) { // An error occurred, or we have reached the end of the file. // Either way we must exit the loop so we can call the handler. break; } // Loop around to try calling sendfile again. } } // Pass result back to user's handler. handler_(ec, total_bytes_transferred_); } }; template <typename Handler> void async_sendfile(tcp::socket& sock, int fd, Handler h) { sendfile_op<Handler> op = { sock, fd, h, 0, 0 }; sock.async_write_some(boost::asio::null_buffers(), op); }
(Deprecated: Use native_handle_type.) The native representation of a socket.
typedef SeqPacketSocketService::native_handle_type native_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the socket.
bool non_blocking() const; » more...
Sets the non-blocking mode of the socket.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Gets the non-blocking mode of the socket.
bool non_blocking() const;
true
if the socket's synchronous
operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately. If
false
, synchronous operations
will block until complete.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
void non_blocking( bool mode);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Thrown on failure.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from basic_socket.
Sets the non-blocking mode of the socket.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the socket's
synchronous operations will fail with boost::asio::error::would_block
if they are unable to perform the requested operation immediately.
If false
, synchronous
operations will block until complete.
Set to indicate what error occurred, if any.
The non-blocking mode has no effect on the behaviour of asynchronous
operations. Asynchronous operations will never fail with the error boost::asio::error::would_block
.
Inherited from socket_base.
(Deprecated: Use non_blocking().) IO control command to set the blocking mode of the socket.
typedef implementation_defined non_blocking_io;
Implements the FIONBIO IO control command.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::non_blocking_io command(true); socket.io_control(command);
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type()); » more... boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Open the socket using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket so that it will use the specified protocol.
An object specifying protocol parameters to be used.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); socket.open(boost::asio::ip::tcp::v4());
Inherited from basic_socket.
Open the socket using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket so that it will use the specified protocol.
An object specifying which protocol is to be used.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::socket socket(io_service); boost::system::error_code ec; socket.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_seq_packet_socket
from another.
basic_seq_packet_socket & operator=( basic_seq_packet_socket && other); » more...
Move-assign a basic_seq_packet_socket
from a
socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_seq_packet_socket >::type & operator=( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other); » more...
Move-assign a basic_seq_packet_socket
from
another.
basic_seq_packet_socket & operator=( basic_seq_packet_socket && other);
This assignment operator moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
Move-assign a basic_seq_packet_socket
from
a socket of another protocol type.
template< typename Protocol1, typename SeqPacketSocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_seq_packet_socket >::type & operator=( basic_seq_packet_socket< Protocol1, SeqPacketSocketService1 > && other);
This assignment operator moves a sequenced packet socket from one object to another.
The other basic_seq_packet_socket
object from which the move will occur.
Following the move, the moved-from object is in the same state as if
constructed using the basic_seq_packet_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags); » more... template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags); » more...
Receive some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, boost::system::error_code & ec); » more...
Receive some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags & out_flags);
This function is used to receive data on the sequenced packet socket. The function call will block until data has been received successfully, or until an error occurs.
One or more buffers into which the data will be received.
After the receive call completes, contains flags associated with
the received data. For example, if the socket_base::message_end_of_record
bit is set then the received data marks the end of a record.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size), out_flags);
See the 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 some data on the socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags);
This function is used to receive data on the sequenced packet socket. The function call will block until data has been received successfully, or until an error occurs.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
After the receive call completes, contains flags associated with
the received data. For example, if the socket_base::message_end_of_record
bit is set then the received data marks the end of a record.
The number of bytes received.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
To receive into a single data buffer use the buffer
function as follows:
socket.receive(boost::asio::buffer(data, size), 0, out_flags);
See the 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 some data on a connected socket.
template< typename MutableBufferSequence> std::size_t receive( const MutableBufferSequence & buffers, socket_base::message_flags in_flags, socket_base::message_flags & out_flags, boost::system::error_code & ec);
This function is used to receive data on the sequenced packet socket. The function call will block until data has been received successfully, or until an error occurs.
One or more buffers into which the data will be received.
Flags specifying how the receive call is to be made.
After the receive call completes, contains flags associated with
the received data. For example, if the socket_base::message_end_of_record
bit is set then the received data marks the end of a record.
Set to indicate what error occurred, if any.
The number of bytes received. Returns 0 if an error occurred.
The receive operation may not receive all of the requested number of
bytes. Consider using the read
function if you need to
ensure that the requested amount of data is read before the blocking
operation completes.
Inherited from socket_base.
Socket option for the receive buffer size of a socket.
typedef implementation_defined receive_buffer_size;
Implements the SOL_SOCKET/SO_RCVBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the receive low watermark.
typedef implementation_defined receive_low_watermark;
Implements the SOL_SOCKET/SO_RCVLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::receive_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const; » more... endpoint_type remote_endpoint( boost::system::error_code & ec) const; » more...
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint() const;
This function is used to obtain the remote endpoint of the socket.
An object that represents the remote endpoint of the socket.
Thrown on failure.
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint();
Inherited from basic_socket.
Get the remote endpoint of the socket.
endpoint_type remote_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the remote endpoint of the socket.
Set to indicate what error occurred, if any.
An object that represents the remote endpoint of the socket. Returns a default-constructed endpoint object if an error occurred.
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = socket.remote_endpoint(ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Socket option to allow the socket to be bound to an address that is already in use.
typedef implementation_defined reuse_address;
Implements the SOL_SOCKET/SO_REUSEADDR socket option.
Setting the option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option(true); acceptor.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::socket_base::reuse_address option; acceptor.get_option(option); bool is_set = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags); » more... template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec); » more...
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags);
This function is used to send data on the sequenced packet socket. The function call will block until the data has been sent successfully, or an until error occurs.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
The number of bytes sent.
Thrown on failure.
To send a single data buffer use the buffer
function as follows:
socket.send(boost::asio::buffer(data, size), 0);
See the buffer
documentation for information on sending multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
Send some data on the socket.
template< typename ConstBufferSequence> std::size_t send( const ConstBufferSequence & buffers, socket_base::message_flags flags, boost::system::error_code & ec);
This function is used to send data on the sequenced packet socket. The function call will block the data has been sent successfully, or an until error occurs.
One or more data buffers to be sent on the socket.
Flags specifying how the send call is to be made.
Set to indicate what error occurred, if any.
The number of bytes sent. Returns 0 if an error occurred.
The send operation may not transmit all of the data to the peer. Consider
using the write
function if you need to ensure that all data is written before the blocking
operation completes.
Inherited from socket_base.
Socket option for the send buffer size of a socket.
typedef implementation_defined send_buffer_size;
Implements the SOL_SOCKET/SO_SNDBUF socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option(8192); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_buffer_size option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from socket_base.
Socket option for the send low watermark.
typedef implementation_defined send_low_watermark;
Implements the SOL_SOCKET/SO_SNDLOWAT socket option.
Setting the option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option(1024); socket.set_option(option);
Getting the current option value:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::socket_base::send_low_watermark option; socket.get_option(option); int size = option.value();
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
Inherited from basic_io_object.
(Deprecated: Use get_service()
.) The service associated with the I/O
object.
service_type & service;
Available only for services that do not support movability.
Inherited from basic_io_object.
The type of the service that will be used to provide I/O operations.
typedef SeqPacketSocketService service_type;
Header: boost/asio/basic_seq_packet_socket.hpp
Convenience header: boost/asio.hpp
void set_option( const SettableSocketOption & option); » more... boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Thrown on failure.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); socket.set_option(option);
Inherited from basic_socket.
Set an option on the socket.
template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec);
This function is used to set an option on the socket.
The new option value to be set on the socket.
Set to indicate what error occurred, if any.
Setting the IPPROTO_TCP/TCP_NODELAY option:
boost::asio::ip::tcp::socket socket(io_service); ... boost::asio::ip::tcp::no_delay option(true); boost::system::error_code ec; socket.set_option(option, ec); if (ec) { // An error occurred. }
Disable sends or receives on the socket.
void shutdown( shutdown_type what); » more... boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec); » more...
Inherited from basic_socket.
Disable sends or receives on the socket.
void shutdown( shutdown_type what);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Thrown on failure.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send);
Inherited from basic_socket.
Disable sends or receives on the socket.
boost::system::error_code shutdown( shutdown_type what, boost::system::error_code & ec);
This function is used to disable send operations, receive operations, or both.
Determines what types of operation will no longer be allowed.
Set to indicate what error occurred, if any.
Shutting down the send side of the socket:
boost::asio::ip::tcp::socket socket(io_service); ... boost::system::error_code ec; socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec); if (ec) { // An error occurred. }
Inherited from socket_base.
Different ways a socket may be shutdown.
enum shutdown_type
Shutdown the receive side of the socket.
Shutdown the send side of the socket.
Shutdown both send and receive on the socket.
Provides serial port functionality.
template< typename SerialPortService = serial_port_service> class basic_serial_port : public basic_io_object< SerialPortService >, public serial_port_base
|
Name |
Description |
|---|---|
|
The underlying implementation type of I/O object. |
|
|
A basic_serial_port is always the lowest layer. |
|
|
The native representation of a serial port. |
|
|
(Deprecated: Use native_handle_type.) The native representation of a serial port. |
|
|
The type of the service that will be used to provide I/O operations. |
|
Name |
Description |
|---|---|
|
Assign an existing native serial port to the serial port. |
|
|
Start an asynchronous read. |
|
|
Start an asynchronous write. |
|
|
Construct a basic_serial_port without opening it. Construct and open a basic_serial_port. Construct a basic_serial_port on an existing native serial port.  Get a const reference to the lowest layer. |
|
|
(Deprecated: Use native_handle().) Get the native serial port representation. |
|
|
Get the native serial port representation. |
|
|
Open the serial port using the specified device name. |
|
|
Move-assign a basic_serial_port from another. |
|
|
Read some data from the serial port. |
|
|
Send a break sequence to the serial port. |
|
|
Set an option on the serial port. |
|
|
Write some data to the serial port. |
|
Name |
Description |
|---|---|
|
Get the underlying implementation of the I/O object. |
|
|
Get the service associated with the I/O object. |
|
Name |
Description |
|---|---|
|
(Deprecated: Use get_implementation().) The underlying implementation of the I/O object. |
|
|
(Deprecated: Use get_service().) The service associated with the I/O object. |
The basic_serial_port
class template
provides functionality that is common to all serial ports.
Distinct objects: Safe.
Shared objects: Unsafe.
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Assign an existing native serial port to the serial port.
void assign( const native_handle_type & native_serial_port); » more... boost::system::error_code assign( const native_handle_type & native_serial_port, boost::system::error_code & ec); » more...
Assign an existing native serial port to the serial port.
void assign( const native_handle_type & native_serial_port);
Assign an existing native serial port to the serial port.
boost::system::error_code assign( const native_handle_type & native_serial_port, boost::system::error_code & ec);
template< typename MutableBufferSequence, typename ReadHandler> void-or-deduced async_read_some( const MutableBufferSequence & buffers, ReadHandler handler);
This function is used to asynchronously read data from the serial port. The function call always returns immediately.
One or more buffers into which the data will be read. Although the buffers object may be copied as necessary, ownership of the underlying memory blocks is retained by the caller, which must guarantee that they remain valid until the handler is called.
The handler to be called when the read operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes read. );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
The read operation may not read all of the requested number of bytes. Consider
using the async_read
function if you need
to ensure that the requested amount of data is read before the asynchronous
operation completes.
To read into a single data buffer use the buffer
function as follows:
serial_port.async_read_some(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on reading into multiple buffers in one go,
and how to use it with arrays, boost::array or std::vector.
template< typename ConstBufferSequence, typename WriteHandler> void-or-deduced async_write_some( const ConstBufferSequence & buffers, WriteHandler handler);
This function is used to asynchronously write data to the serial port. The function call always returns immediately.
One or more data buffers to be written to the serial port. 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.
The handler to be called when the write operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler( const boost::system::error_code& error, // Result of operation. std::size_t bytes_transferred // Number of bytes written. );
Regardless of whether the asynchronous operation completes immediately
or not, the handler will not be invoked from within this function.
Invocation of the handler will be performed in a manner equivalent
to using boost::asio::io_service::post()
.
The write operation may not transmit all of the data to the peer. Consider
using the async_write
function if you need
to ensure that all data is written before the asynchronous operation completes.
To write a single data buffer use the buffer
function as follows:
serial_port.async_write_some(boost::asio::buffer(data, size), handler);
See the buffer
documentation for information on writing multiple buffers in one go, and
how to use it with arrays, boost::array or std::vector.
Construct a basic_serial_port
without opening
it.
explicit basic_serial_port( boost::asio::io_service & io_service); » more...
Construct and open a basic_serial_port
.
explicit basic_serial_port( boost::asio::io_service & io_service, const char * device); » more... explicit basic_serial_port( boost::asio::io_service & io_service, const std::string & device); » more...
Construct a basic_serial_port
on an existing
native serial port.
basic_serial_port( boost::asio::io_service & io_service, const native_handle_type & native_serial_port); » more...
Move-construct a basic_serial_port
from another.
basic_serial_port( basic_serial_port && other); » more...
Construct a basic_serial_port
without opening
it.
basic_serial_port( boost::asio::io_service & io_service);
This constructor creates a serial port without opening it.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
Construct and open a basic_serial_port
.
basic_serial_port( boost::asio::io_service & io_service, const char * device);
This constructor creates and opens a serial port for the specified device name.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
The platform-specific device name for this serial port.
Construct and open a basic_serial_port
.
basic_serial_port( boost::asio::io_service & io_service, const std::string & device);
This constructor creates and opens a serial port for the specified device name.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
The platform-specific device name for this serial port.