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);
This constructor creates a serial port object to hold an existing native serial port.
The io_service
object that
the serial port will use to dispatch handlers for any asynchronous
operations performed on the port.
A native serial port.
Thrown on failure.
Move-construct a basic_serial_port
from another.
basic_serial_port( basic_serial_port && other);
This constructor moves a serial port from one object to another.
The other basic_serial_port
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_serial_port(io_service&) constructor
.
Cancel all asynchronous operations associated with the serial port.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all asynchronous operations associated with the serial port.
void cancel();
This function causes all outstanding asynchronous read or write operations
to finish immediately, and the handlers for cancelled operations will
be passed the boost::asio::error::operation_aborted
error.
Thrown on failure.
Cancel all asynchronous operations associated with the serial port.
boost::system::error_code cancel( boost::system::error_code & ec);
This function causes all outstanding asynchronous read or write 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.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the serial port.
void close();
This function is used to close the serial port. Any asynchronous read
or write operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Thrown on failure.
Close the serial port.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the serial port. Any asynchronous read
or write operations will be cancelled immediately, and will complete
with the boost::asio::error::operation_aborted
error.
Set to indicate what error occurred, if any.
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 serial port.
template< typename GettableSerialPortOption> void get_option( GettableSerialPortOption & option); » more... template< typename GettableSerialPortOption> boost::system::error_code get_option( GettableSerialPortOption & option, boost::system::error_code & ec); » more...
Get an option from the serial port.
template< typename GettableSerialPortOption> void get_option( GettableSerialPortOption & option);
This function is used to get the current value of an option on the serial port.
The option value to be obtained from the serial port.
Thrown on failure.
Get an option from the serial port.
template< typename GettableSerialPortOption> boost::system::error_code get_option( GettableSerialPortOption & option, boost::system::error_code & ec);
This function is used to get the current value of an option on the serial port.
The option value to be obtained from the serial port.
Set to indicate what error occurred, if any.
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_serial_port.hpp
Convenience header: boost/asio.hpp
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...
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_serial_port
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.
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_serial_port
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.
A basic_serial_port
is always the
lowest layer.
typedef basic_serial_port< SerialPortService > lowest_layer_type;
|
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
(Deprecated: Use native_handle()
.) Get the native serial port representation.
native_type native();
This function may be used to obtain the underlying representation of the serial port. This is intended to allow access to native serial port functionality that is not otherwise provided.
Get the native serial port representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the serial port. This is intended to allow access to native serial port functionality that is not otherwise provided.
The native representation of a serial port.
typedef SerialPortService::native_handle_type native_handle_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
(Deprecated: Use native_handle_type.) The native representation of a serial port.
typedef SerialPortService::native_handle_type native_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Open the serial port using the specified device name.
void open( const std::string & device); » more... boost::system::error_code open( const std::string & device, boost::system::error_code & ec); » more...
Open the serial port using the specified device name.
void open( const std::string & device);
This function opens the serial port for the specified device name.
The platform-specific device name.
Thrown on failure.
Open the serial port using the specified device name.
boost::system::error_code open( const std::string & device, boost::system::error_code & ec);
This function opens the serial port using the given platform-specific device name.
The platform-specific device name.
Set the indicate what error occurred, if any.
Move-assign a basic_serial_port
from another.
basic_serial_port & operator=( basic_serial_port && other);
This assignment operator moves a serial port from one object to another.
The other basic_serial_port
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_serial_port(io_service&) constructor
.
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers); » more... template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec); » more...
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers);
This function is used to read data from the serial port. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.
One or more buffers into which the data will be read.
The number of bytes read.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The read_some operation may not read 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 read into a single data buffer use the buffer
function as follows:
serial_port.read_some(boost::asio::buffer(data, size));
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.
Read some data from the serial port.
template< typename MutableBufferSequence> std::size_t read_some( const MutableBufferSequence & buffers, boost::system::error_code & ec);
This function is used to read data from the serial port. The function call will block until one or more bytes of data has been read successfully, or until an error occurs.
One or more buffers into which the data will be read.
Set to indicate what error occurred, if any.
The number of bytes read. Returns 0 if an error occurred.
The read_some operation may not read 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.
Send a break sequence to the serial port.
void send_break(); » more... boost::system::error_code send_break( boost::system::error_code & ec); » more...
Send a break sequence to the serial port.
void send_break();
This function causes a break sequence of platform-specific duration to be sent out the serial port.
Thrown on failure.
Send a break sequence to the serial port.
boost::system::error_code send_break( boost::system::error_code & ec);
This function causes a break sequence of platform-specific duration to be sent out the serial port.
Set to indicate what error occurred, if any.
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 SerialPortService service_type;
Header: boost/asio/basic_serial_port.hpp
Convenience header: boost/asio.hpp
Set an option on the serial port.
template< typename SettableSerialPortOption> void set_option( const SettableSerialPortOption & option); » more... template< typename SettableSerialPortOption> boost::system::error_code set_option( const SettableSerialPortOption & option, boost::system::error_code & ec); » more...
Set an option on the serial port.
template< typename SettableSerialPortOption> void set_option( const SettableSerialPortOption & option);
This function is used to set an option on the serial port.
The option value to be set on the serial port.
Thrown on failure.
Set an option on the serial port.
template< typename SettableSerialPortOption> boost::system::error_code set_option( const SettableSerialPortOption & option, boost::system::error_code & ec);
This function is used to set an option on the serial port.
The option value to be set on the serial port.
Set to indicate what error occurred, if any.
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers); » more... template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec); » more...
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers);
This function is used to write data to the serial port. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.
One or more data buffers to be written to the serial port.
The number of bytes written.
Thrown on failure. An error code of boost::asio::error::eof
indicates that the connection was closed by the peer.
The write_some 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.
To write a single data buffer use the buffer
function as follows:
serial_port.write_some(boost::asio::buffer(data, size));
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.
Write some data to the serial port.
template< typename ConstBufferSequence> std::size_t write_some( const ConstBufferSequence & buffers, boost::system::error_code & ec);
This function is used to write data to the serial port. The function call will block until one or more bytes of the data has been written successfully, or until an error occurs.
One or more data buffers to be written to the serial port.
Set to indicate what error occurred, if any.
The number of bytes written. Returns 0 if an error occurred.
The write_some 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.
Provides signal functionality.
template< typename SignalSetService = signal_set_service> class basic_signal_set : public basic_io_object< SignalSetService >
|
Name |
Description |
|---|---|
|
The underlying implementation type of I/O object. |
|
|
The type of the service that will be used to provide I/O operations. |
|
Name |
Description |
|---|---|
|
Add a signal to a signal_set. |
|
|
Start an asynchronous operation to wait for a signal to be delivered. |
|
|
Construct a signal set without adding any signals. Construct a signal set and add one signal. Construct a signal set and add two signals. Construct a signal set and add three signals. |
|
|
Cancel all operations associated with the signal set. |
|
|
Remove all signals from a signal_set. |
|
|
Get the io_service associated with the object. |
|
|
Remove a signal from a signal_set. |
|
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_signal_set
class template provides the ability to perform an asynchronous wait for one
or more signals to occur.
Most applications will use the signal_set
typedef.
Distinct objects: Safe.
Shared objects: Unsafe.
Performing an asynchronous wait:
void handler( const boost::system::error_code& error, int signal_number) { if (!error) { // A signal occurred. } } ... // Construct a signal set registered for process termination. boost::asio::signal_set signals(io_service, SIGINT, SIGTERM); // Start an asynchronous wait for one of the signals to occur. signals.async_wait(handler);
If a signal is registered with a signal_set, and the signal occurs when there are no waiting handlers, then the signal notification is queued. The next async_wait operation on that signal_set will dequeue the notification. If multiple notifications are queued, subsequent async_wait operations dequeue them one at a time. Signal notifications are dequeued in order of ascending signal number.
If a signal number is removed from a signal_set (using the remove
or erase
member functions) then any queued notifications for that signal are discarded.
The same signal number may be registered with different signal_set objects. When the signal occurs, one handler is called for each signal_set object.
Note that multiple registration only works for signals that are registered
using Asio. The application must not also register a signal handler using
functions such as signal()
or sigaction()
.
POSIX allows signals to be blocked using functions such as sigprocmask()
and pthread_sigmask()
.
For signals to be delivered, programs must ensure that any signals registered
using signal_set objects are unblocked in at least one thread.
Header: boost/asio/basic_signal_set.hpp
Convenience header: boost/asio.hpp
void add( int signal_number); » more... boost::system::error_code add( int signal_number, boost::system::error_code & ec); » more...
Add a signal to a signal_set.
void add( int signal_number);
This function adds the specified signal to the set. It has no effect if the signal is already in the set.
The signal to be added to the set.
Thrown on failure.
Add a signal to a signal_set.
boost::system::error_code add( int signal_number, boost::system::error_code & ec);
This function adds the specified signal to the set. It has no effect if the signal is already in the set.
The signal to be added to the set.
Set to indicate what error occurred, if any.
Start an asynchronous operation to wait for a signal to be delivered.
template< typename SignalHandler> void-or-deduced async_wait( SignalHandler handler);
This function may be used to initiate an asynchronous wait against the signal set. It always returns immediately.
For each call to async_wait()
, the supplied handler will be called
exactly once. The handler will be called when:
boost::asio::error::operation_aborted
.
The handler to be called when the signal occurs. 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. int signal_number // Indicates which signal occurred. );
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()
.
Construct a signal set without adding any signals.
explicit basic_signal_set( boost::asio::io_service & io_service); » more...
Construct a signal set and add one signal.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1); » more...
Construct a signal set and add two signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2); » more...
Construct a signal set and add three signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2, int signal_number_3); » more...
Construct a signal set without adding any signals.
basic_signal_set( boost::asio::io_service & io_service);
This constructor creates a signal set without registering for any signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
Construct a signal set and add one signal.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1);
This constructor creates a signal set and registers for one signal.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1);
Construct a signal set and add two signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2);
This constructor creates a signal set and registers for two signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The first signal number to be added.
The second signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1); signals.add(signal_number_2);
Construct a signal set and add three signals.
basic_signal_set( boost::asio::io_service & io_service, int signal_number_1, int signal_number_2, int signal_number_3);
This constructor creates a signal set and registers for three signals.
The io_service
object that
the signal set will use to dispatch handlers for any asynchronous
operations performed on the set.
The first signal number to be added.
The second signal number to be added.
The third signal number to be added.
This constructor is equivalent to performing:
boost::asio::signal_set signals(io_service); signals.add(signal_number_1); signals.add(signal_number_2); signals.add(signal_number_3);
Cancel all operations associated with the signal set.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all operations associated with the signal set.
void cancel();
This function forces the completion of any pending asynchronous wait
operations against the signal set. The handler for each cancelled operation
will be invoked with the boost::asio::error::operation_aborted
error code.
Cancellation does not alter the set of registered signals.
Thrown on failure.
If a registered signal occurred before cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Cancel all operations associated with the signal set.
boost::system::error_code cancel( boost::system::error_code & ec);
This function forces the completion of any pending asynchronous wait
operations against the signal set. The handler for each cancelled operation
will be invoked with the boost::asio::error::operation_aborted
error code.
Cancellation does not alter the set of registered signals.
Set to indicate what error occurred, if any.
If a registered signal occurred before cancel()
is called, then the handlers for asynchronous
wait operations will:
These handlers can no longer be cancelled, and therefore are passed an error code that indicates the successful completion of the wait operation.
Remove all signals from a signal_set.
void clear(); » more... boost::system::error_code clear( boost::system::error_code & ec); » more...
Remove all signals from a signal_set.
void clear();
This function removes all signals from the set. It has no effect if the set is already empty.
Thrown on failure.
Removes all queued notifications.
Remove all signals from a signal_set.
boost::system::error_code clear( boost::system::error_code & ec);
This function removes all signals from the set. It has no effect if the set is already empty.
Set to indicate what error occurred, if any.
Removes all queued notifications.
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 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_signal_set.hpp
Convenience header: boost/asio.hpp
Remove a signal from a signal_set.
void remove( int signal_number); » more... boost::system::error_code remove( int signal_number, boost::system::error_code & ec); » more...
Remove a signal from a signal_set.
void remove( int signal_number);
This function removes the specified signal from the set. It has no effect if the signal is not in the set.
The signal to be removed from the set.
Thrown on failure.
Removes any notifications that have been queued for the specified signal number.
Remove a signal from a signal_set.
boost::system::error_code remove( int signal_number, boost::system::error_code & ec);
This function removes the specified signal from the set. It has no effect if the signal is not in the set.
The signal to be removed from the set.
Set to indicate what error occurred, if any.
Removes any notifications that have been queued for the specified signal number.
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 SignalSetService service_type;
Header: boost/asio/basic_signal_set.hpp
Convenience header: boost/asio.hpp
Provides socket functionality.
template< typename Protocol, typename SocketService> class basic_socket : public basic_io_object< SocketService >, public socket_base
|
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_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...
Assign an existing native socket to the socket.
void assign( const protocol_type & protocol, const native_handle_type & native_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);
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);
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...
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.
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...
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.
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_socket
without opening it.
explicit basic_socket( boost::asio::io_service & io_service); » more...
Construct and open a basic_socket
.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct a basic_socket
, opening it and binding
it to the given local endpoint.
basic_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint); » more...
Construct a basic_socket
on an existing native
socket.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket); » more...
Move-construct a basic_socket
from another.
basic_socket( basic_socket && other); » more...
Move-construct a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> basic_socket( basic_socket< Protocol1, SocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct a basic_socket
without opening
it.
basic_socket( boost::asio::io_service & io_service);
This constructor creates a socket without opening it.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
Construct and open a basic_socket
.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates and opens a socket.
The io_service
object that
the 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_socket
, opening it and
binding it to the given local endpoint.
basic_socket( boost::asio::io_service & io_service, const endpoint_type & endpoint);
This constructor creates a socket and automatically opens it bound to the specified endpoint on the local machine. The protocol used is the protocol associated with the given endpoint.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
An endpoint on the local machine to which the socket will be bound.
Thrown on failure.
Construct a basic_socket
on an existing
native socket.
basic_socket( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_socket);
This constructor creates a socket object to hold an existing native socket.
The io_service
object that
the socket will use to dispatch handlers for any asynchronous operations
performed on the socket.
An object specifying protocol parameters to be used.
A native socket.
Thrown on failure.
Move-construct a basic_socket
from another.
basic_socket( basic_socket && other);
This constructor moves a socket from one object to another.
The other basic_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_socket(io_service&) constructor
.
Move-construct a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> basic_socket( basic_socket< Protocol1, SocketService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves a socket from one object to another.
The other basic_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_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...
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));
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_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_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...
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.
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...
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.
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...
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);
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_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_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_socket.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_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.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option) const; » more... template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec) const; » more...
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();
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_socket.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the socket.
template< typename IoControlCommand> void io_control( IoControlCommand & command); » more... template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
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();
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_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_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...
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();
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...
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.
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.
A basic_socket
is always the lowest
layer.
typedef basic_socket< Protocol, SocketService > 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_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_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;
(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.
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 SocketService::native_handle_type native_handle_type;
Header: boost/asio/basic_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...
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); }
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); }
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 SocketService::native_handle_type native_type;
Header: boost/asio/basic_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...
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
.
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
.
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_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...
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());
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_socket
from another.
basic_socket & operator=( basic_socket && other); » more...
Move-assign a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket >::type & operator=( basic_socket< Protocol1, SocketService1 > && other); » more...
Move-assign a basic_socket
from another.
basic_socket & operator=( basic_socket && other);
This assignment operator moves a socket from one object to another.
The other basic_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_socket(io_service&) constructor
.
Move-assign a basic_socket
from a socket of
another protocol type.
template< typename Protocol1, typename SocketService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket >::type & operator=( basic_socket< Protocol1, SocketService1 > && other);
This assignment operator moves a socket from one object to another.
The other basic_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_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
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_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_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...
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();
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_socket.hpp
Convenience header: boost/asio.hpp
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_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_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 SocketService service_type;
Header: boost/asio/basic_socket.hpp
Convenience header: boost/asio.hpp
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option); » more... template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
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);
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...
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);
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 the ability to accept new connections.
template< typename Protocol, typename SocketAcceptorService = socket_acceptor_service<Protocol>> class basic_socket_acceptor : public basic_io_object< SocketAcceptorService >, public socket_base
|
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. |
|
|
Bitmask type for flags that can be passed to send and receive operations. |
|
|
The native representation of an acceptor. |
|
|
(Deprecated: Use native_handle_type.) The native representation of an acceptor. |
|
|
(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 |
|---|---|
|
Accept a new connection. Accept a new connection and obtain the endpoint of the peer. |
|
|
Assigns an existing native acceptor to the acceptor. |
|
|
Start an asynchronous accept. |
|
|
Construct an acceptor without opening it. Construct an open acceptor. Construct an acceptor opened on the given endpoint. Construct a basic_socket_acceptor on an existing native acceptor. Move-construct a basic_socket_acceptor from another. Move-construct a basic_socket_acceptor from an acceptor of another protocol type. |
|
|
Bind the acceptor to the given local endpoint. |
|
|
Cancel all asynchronous operations associated with the acceptor. |
|
|
Close the acceptor. |
|
|
Get the io_service associated with the object. |
|
|
Get an option from the acceptor. |
|
|
Perform an IO control command on the acceptor. |
|
|
Determine whether the acceptor is open. |
|
|
Place the acceptor into the state where it will listen for new connections. |
|
|
Get the local endpoint of the acceptor. |
|
|
(Deprecated: Use native_handle().) Get the native acceptor representation. |
|
|
Get the native acceptor representation. |
|
|
Gets the non-blocking mode of the native acceptor implementation. Sets the non-blocking mode of the native acceptor implementation. |
|
|
Gets the non-blocking mode of the acceptor. Sets the non-blocking mode of the acceptor. |
|
|
Open the acceptor using the specified protocol. |
|
|
Move-assign a basic_socket_acceptor from another. Move-assign a basic_socket_acceptor from an acceptor of another protocol type. |
|
|
Set an option on the acceptor. |
|
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_socket_acceptor
class template
is used for accepting new socket connections.
Distinct objects: Safe.
Shared objects: Unsafe.
Opening a socket acceptor with the SO_REUSEADDR option enabled:
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port); acceptor.open(endpoint.protocol()); acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen();
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
template< typename Protocol1, typename SocketService> void accept( basic_socket< Protocol1, SocketService > & peer, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more... template< typename Protocol1, typename SocketService> boost::system::error_code accept( basic_socket< Protocol1, SocketService > & peer, boost::system::error_code & ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more...
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> void accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint); » more... template< typename SocketService> boost::system::error_code accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, boost::system::error_code & ec); » more...
Accept a new connection.
template< typename Protocol1, typename SocketService> void accept( basic_socket< Protocol1, SocketService > & peer, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to accept a new connection from a peer into the given socket. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); acceptor.accept(socket);
Accept a new connection.
template< typename Protocol1, typename SocketService> boost::system::error_code accept( basic_socket< Protocol1, SocketService > & peer, boost::system::error_code & ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to accept a new connection from a peer into the given socket. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::soocket socket(io_service); boost::system::error_code ec; acceptor.accept(socket, ec); if (ec) { // An error occurred. }
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> void accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint);
This function is used to accept a new connection from a peer into the given socket, and additionally provide the endpoint of the remote peer. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
An endpoint object which will receive the endpoint of the remote peer.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint; acceptor.accept(socket, endpoint);
Accept a new connection and obtain the endpoint of the peer.
template< typename SocketService> boost::system::error_code accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, boost::system::error_code & ec);
This function is used to accept a new connection from a peer into the given socket, and additionally provide the endpoint of the remote peer. The function call will block until a new connection has been accepted successfully or an error occurs.
The socket into which the new connection will be accepted.
An endpoint object which will receive the endpoint of the remote peer.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); boost::asio::ip::tcp::endpoint endpoint; boost::system::error_code ec; acceptor.accept(socket, endpoint, ec); if (ec) { // An error occurred. }
Assigns an existing native acceptor to the acceptor.
void assign( const protocol_type & protocol, const native_handle_type & native_acceptor); » more... boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_acceptor, boost::system::error_code & ec); » more...
Assigns an existing native acceptor to the acceptor.
void assign( const protocol_type & protocol, const native_handle_type & native_acceptor);
Assigns an existing native acceptor to the acceptor.
boost::system::error_code assign( const protocol_type & protocol, const native_handle_type & native_acceptor, boost::system::error_code & ec);
template< typename Protocol1, typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< Protocol1, SocketService > & peer, AcceptHandler handler, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0); » more... template< typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, AcceptHandler handler); » more...
Start an asynchronous accept.
template< typename Protocol1, typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< Protocol1, SocketService > & peer, AcceptHandler handler, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type * = 0);
This function is used to asynchronously accept a new connection into a socket. The function call always returns immediately.
The socket into which the new connection will be accepted. Ownership of the peer object is retained by the caller, which must guarantee that it is valid until the handler is called.
The handler to be called when the accept 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 accept_handler(const boost::system::error_code& error) { if (!error) { // Accept succeeded. } } ... boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::socket socket(io_service); acceptor.async_accept(socket, accept_handler);
Start an asynchronous accept.
template< typename SocketService, typename AcceptHandler> void-or-deduced async_accept( basic_socket< protocol_type, SocketService > & peer, endpoint_type & peer_endpoint, AcceptHandler handler);
This function is used to asynchronously accept a new connection into a socket, and additionally obtain the endpoint of the remote peer. The function call always returns immediately.
The socket into which the new connection will be accepted. Ownership of the peer object is retained by the caller, which must guarantee that it is valid until the handler is called.
An endpoint object into which the endpoint of the remote peer will be written. Ownership of the peer_endpoint object is retained by the caller, which must guarantee that it is valid until the handler is called.
The handler to be called when the accept 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()
.
Construct an acceptor without opening it.
explicit basic_socket_acceptor( boost::asio::io_service & io_service); » more...
Construct an open acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol); » more...
Construct an acceptor opened on the given endpoint.
basic_socket_acceptor( boost::asio::io_service & io_service, const endpoint_type & endpoint, bool reuse_addr = true); » more...
Construct a basic_socket_acceptor
on an existing
native acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_acceptor); » more...
Move-construct a basic_socket_acceptor
from another.
basic_socket_acceptor( basic_socket_acceptor && other); » more...
Move-construct a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> basic_socket_acceptor( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0); » more...
Construct an acceptor without opening it.
basic_socket_acceptor( boost::asio::io_service & io_service);
This constructor creates an acceptor without opening it to listen for
new connections. The open()
function must be called before the
acceptor can accept new socket connections.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
Construct an open acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol);
This constructor creates an acceptor and automatically opens it.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An object specifying protocol parameters to be used.
Thrown on failure.
Construct an acceptor opened on the given endpoint.
basic_socket_acceptor( boost::asio::io_service & io_service, const endpoint_type & endpoint, bool reuse_addr = true);
This constructor creates an acceptor and automatically opens it to listen for new connections on the specified endpoint.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An endpoint on the local machine on which the acceptor will listen for new connections.
Whether the constructor should set the socket option socket_base::reuse_address
.
Thrown on failure.
This constructor is equivalent to the following code:
basic_socket_acceptor<Protocol> acceptor(io_service); acceptor.open(endpoint.protocol()); if (reuse_addr) acceptor.set_option(socket_base::reuse_address(true)); acceptor.bind(endpoint); acceptor.listen(listen_backlog);
Construct a basic_socket_acceptor
on an
existing native acceptor.
basic_socket_acceptor( boost::asio::io_service & io_service, const protocol_type & protocol, const native_handle_type & native_acceptor);
This constructor creates an acceptor object to hold an existing native acceptor.
The io_service
object that
the acceptor will use to dispatch handlers for any asynchronous
operations performed on the acceptor.
An object specifying protocol parameters to be used.
A native acceptor.
Thrown on failure.
Move-construct a basic_socket_acceptor
from another.
basic_socket_acceptor( basic_socket_acceptor && other);
This constructor moves an acceptor from one object to another.
The other basic_socket_acceptor
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_socket_acceptor(io_service&) constructor
.
Move-construct a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> basic_socket_acceptor( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other, typename enable_if< is_convertible< Protocol1, Protocol >::value >::type * = 0);
This constructor moves an acceptor from one object to another.
The other basic_socket_acceptor
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_socket(io_service&) constructor
.
Bind the acceptor 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...
Bind the acceptor to the given local endpoint.
void bind( const endpoint_type & endpoint);
This function binds the socket acceptor to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket acceptor will be bound.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345); acceptor.open(endpoint.protocol()); acceptor.bind(endpoint);
Bind the acceptor to the given local endpoint.
boost::system::error_code bind( const endpoint_type & endpoint, boost::system::error_code & ec);
This function binds the socket acceptor to the specified endpoint on the local machine.
An endpoint on the local machine to which the socket acceptor will be bound.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 12345); acceptor.open(endpoint.protocol()); boost::system::error_code ec; acceptor.bind(endpoint, 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_socket_acceptor.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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Cancel all asynchronous operations associated with the acceptor.
void cancel(); » more... boost::system::error_code cancel( boost::system::error_code & ec); » more...
Cancel all asynchronous operations associated with the acceptor.
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.
Cancel all asynchronous operations associated with the acceptor.
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.
void close(); » more... boost::system::error_code close( boost::system::error_code & ec); » more...
Close the acceptor.
void close();
This function is used to close the acceptor. Any asynchronous accept operations will be cancelled immediately.
A subsequent call to open()
is required before the acceptor can
again be used to again perform socket accept operations.
Thrown on failure.
Close the acceptor.
boost::system::error_code close( boost::system::error_code & ec);
This function is used to close the acceptor. Any asynchronous accept operations will be cancelled immediately.
A subsequent call to open()
is required before the acceptor can
again be used to again perform socket accept operations.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; acceptor.close(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_socket_acceptor.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_socket_acceptor.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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket_acceptor.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 acceptor.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option); » more... template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec); » more...
Get an option from the acceptor.
template< typename GettableSocketOption> void get_option( GettableSocketOption & option);
This function is used to get the current value of an option on the acceptor.
The option value to be obtained from the acceptor.
Thrown on failure.
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option; acceptor.get_option(option); bool is_set = option.get();
Get an option from the acceptor.
template< typename GettableSocketOption> boost::system::error_code get_option( GettableSocketOption & option, boost::system::error_code & ec);
This function is used to get the current value of an option on the acceptor.
The option value to be obtained from the acceptor.
Set to indicate what error occurred, if any.
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option; boost::system::error_code ec; acceptor.get_option(option, ec); if (ec) { // An error occurred. } bool is_set = option.get();
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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Perform an IO control command on the acceptor.
template< typename IoControlCommand> void io_control( IoControlCommand & command); » more... template< typename IoControlCommand> boost::system::error_code io_control( IoControlCommand & command, boost::system::error_code & ec); » more...
Perform an IO control command on the acceptor.
template< typename IoControlCommand> void io_control( IoControlCommand & command);
This function is used to execute an IO control command on the acceptor.
The IO control command to be performed on the acceptor.
Thrown on failure.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::non_blocking_io command(true); socket.io_control(command);
Perform an IO control command on the acceptor.
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 acceptor.
The IO control command to be performed on the acceptor.
Set to indicate what error occurred, if any.
Getting the number of bytes ready to read:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::non_blocking_io command(true); boost::system::error_code ec; socket.io_control(command, ec); if (ec) { // An error occurred. }
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_socket_acceptor.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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Place the acceptor into the state where it will listen for new connections.
void listen( int backlog = socket_base::max_connections); » more... boost::system::error_code listen( int backlog, boost::system::error_code & ec); » more...
Place the acceptor into the state where it will listen for new connections.
void listen( int backlog = socket_base::max_connections);
This function puts the socket acceptor into the state where it may accept new connections.
The maximum length of the queue of pending connections.
Thrown on failure.
Place the acceptor into the state where it will listen for new connections.
boost::system::error_code listen( int backlog, boost::system::error_code & ec);
This function puts the socket acceptor into the state where it may accept new connections.
The maximum length of the queue of pending connections.
Set to indicate what error occurred, if any.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; acceptor.listen(boost::asio::socket_base::max_connections, ec); if (ec) { // An error occurred. }
Get the local endpoint of the acceptor.
endpoint_type local_endpoint() const; » more... endpoint_type local_endpoint( boost::system::error_code & ec) const; » more...
Get the local endpoint of the acceptor.
endpoint_type local_endpoint() const;
This function is used to obtain the locally bound endpoint of the acceptor.
An object that represents the local endpoint of the acceptor.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint();
Get the local endpoint of the acceptor.
endpoint_type local_endpoint( boost::system::error_code & ec) const;
This function is used to obtain the locally bound endpoint of the acceptor.
Set to indicate what error occurred, if any.
An object that represents the local endpoint of the acceptor. Returns a default-constructed endpoint object if an error occurred and the error handler did not throw an exception.
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::system::error_code ec; boost::asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec); if (ec) { // An error occurred. }
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_socket_acceptor.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;
(Deprecated: Use native_handle()
.) Get the native acceptor representation.
native_type native();
This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided.
Get the native acceptor representation.
native_handle_type native_handle();
This function may be used to obtain the underlying representation of the acceptor. This is intended to allow access to native acceptor functionality that is not otherwise provided.
The native representation of an acceptor.
typedef SocketAcceptorService::native_handle_type native_handle_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the native acceptor implementation.
bool native_non_blocking() const; » more...
Sets the non-blocking mode of the native acceptor implementation.
void native_non_blocking( bool mode); » more... boost::system::error_code native_non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the native acceptor implementation.
bool native_non_blocking() const;
This function is used to retrieve the non-blocking mode of the underlying native acceptor. This mode has no effect on the behaviour of the acceptor object's synchronous operations.
true
if the underlying acceptor
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 acceptor object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native acceptor.
Sets the non-blocking mode of the native acceptor implementation.
void native_non_blocking( bool mode);
This function is used to modify the non-blocking mode of the underlying native acceptor. It has no effect on the behaviour of the acceptor object's synchronous operations.
If true
, the underlying
acceptor 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.
Sets the non-blocking mode of the native acceptor 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 acceptor. It has no effect on the behaviour of the acceptor object's synchronous operations.
If true
, the underlying
acceptor 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.
(Deprecated: Use native_handle_type.) The native representation of an acceptor.
typedef SocketAcceptorService::native_handle_type native_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Gets the non-blocking mode of the acceptor.
bool non_blocking() const; » more...
Sets the non-blocking mode of the acceptor.
void non_blocking( bool mode); » more... boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec); » more...
Gets the non-blocking mode of the acceptor.
bool non_blocking() const;
true
if the acceptor'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
.
Sets the non-blocking mode of the acceptor.
void non_blocking( bool mode);
If true
, the acceptor'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
.
Sets the non-blocking mode of the acceptor.
boost::system::error_code non_blocking( bool mode, boost::system::error_code & ec);
If true
, the acceptor'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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Open the acceptor 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...
Open the acceptor using the specified protocol.
void open( const protocol_type & protocol = protocol_type());
This function opens the socket acceptor so that it will use the specified protocol.
An object specifying which protocol is to be used.
Thrown on failure.
boost::asio::ip::tcp::acceptor acceptor(io_service); acceptor.open(boost::asio::ip::tcp::v4());
Open the acceptor using the specified protocol.
boost::system::error_code open( const protocol_type & protocol, boost::system::error_code & ec);
This function opens the socket acceptor 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::acceptor acceptor(io_service); boost::system::error_code ec; acceptor.open(boost::asio::ip::tcp::v4(), ec); if (ec) { // An error occurred. }
Move-assign a basic_socket_acceptor
from another.
basic_socket_acceptor & operator=( basic_socket_acceptor && other); » more...
Move-assign a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket_acceptor >::type & operator=( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other); » more...
Move-assign a basic_socket_acceptor
from another.
basic_socket_acceptor & operator=( basic_socket_acceptor && other);
This assignment operator moves an acceptor from one object to another.
The other basic_socket_acceptor
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_socket_acceptor(io_service&) constructor
.
Move-assign a basic_socket_acceptor
from an
acceptor of another protocol type.
template< typename Protocol1, typename SocketAcceptorService1> enable_if< is_convertible< Protocol1, Protocol >::value, basic_socket_acceptor >::type & operator=( basic_socket_acceptor< Protocol1, SocketAcceptorService1 > && other);
This assignment operator moves an acceptor from one object to another.
The other basic_socket_acceptor
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_socket(io_service&) constructor
.
typedef Protocol protocol_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
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_socket_acceptor.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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
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_socket_acceptor.hpp
Convenience header: boost/asio.hpp
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_socket_acceptor.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_socket_acceptor.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 SocketAcceptorService service_type;
Header: boost/asio/basic_socket_acceptor.hpp
Convenience header: boost/asio.hpp
Set an option on the acceptor.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option); » more... template< typename SettableSocketOption> boost::system::error_code set_option( const SettableSocketOption & option, boost::system::error_code & ec); » more...
Set an option on the acceptor.
template< typename SettableSocketOption> void set_option( const SettableSocketOption & option);
This function is used to set an option on the acceptor.
The new option value to be set on the acceptor.
Thrown on failure.
Setting the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option(true); acceptor.set_option(option);
Set an option on the acceptor.
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 acceptor.
The new option value to be set on the acceptor.
Set to indicate what error occurred, if any.
Setting the SOL_SOCKET/SO_REUSEADDR option:
boost::asio::ip::tcp::acceptor acceptor(io_service); ... boost::asio::ip::tcp::acceptor::reuse_address option(true); boost::system::error_code ec; acceptor.set_option(option, 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.
Iostream interface for a socket.
template< typename Protocol, typename StreamSocketService = stream_socket_service<Protocol>, typename Time = boost::posix_time::ptime, typename TimeTraits = boost::asio::time_traits<Time>, typename TimerService = deadline_timer_service<Time, TimeTraits>> class basic_socket_iostream
|
Name |
Description |
|---|---|
|
The duration type. |
|
|
The endpoint type. |
|
|
The time type. |
|
Name |
Description |
|---|---|
|
Construct a basic_socket_iostream without establishing a connection.  Set the stream's expiry time as an absolute time. |
|
|
Get the timer's expiry time relative to now. Set the stream's expiry time relative to now. |
|
|
Return a pointer to the underlying streambuf. |
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
Construct a basic_socket_iostream
without
establishing a connection.
basic_socket_iostream(); » more...
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> explicit basic_socket_iostream( T1 t1, ... , TN tn); » more...
Construct a basic_socket_iostream
without
establishing a connection.
basic_socket_iostream();
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> basic_socket_iostream( T1 t1, ... , TN tn);
This constructor automatically establishes a connection based on the supplied resolver query parameters. The arguments are used to construct a resolver query object.
Establish a connection to an endpoint corresponding to a resolver query.
template< typename T1, ... , typename TN> void connect( T1 t1, ... , TN tn);
This function automatically establishes a connection based on the supplied resolver query parameters. The arguments are used to construct a resolver query object.
typedef TimeTraits::duration_type duration_type;
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
typedef Protocol::endpoint endpoint_type;
Header: boost/asio/basic_socket_iostream.hpp
Convenience header: boost/asio.hpp
Get the last error associated with the stream.
const boost::system::error_code & error() const;
An error_code
corresponding
to the last error from the stream.
To print the error associated with a failure to establish a connection:
tcp::iostream s("www.boost.org", "http"); if (!s) { std::cout << "Error: " << s.error().message() << std::endl; }
Get the stream's expiry time as an absolute time.
time_type expires_at() const; » more...
Set the stream's expiry time as an absolute time.
void expires_at( const time_type & expiry_time); » more...

Set the stream's expiry time as an absolute time.
void expires_at( const time_type & expiry_time);
This function sets the expiry time associated with the stream. Stream
operations performed after this time (where the operations cannot be
completed using the internal buffers) will fail with the error boost::asio::error::operation_aborted
.
The expiry time to be used for the stream.
Get the timer's expiry time relative to now.