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

Provides the ability to accept new connections. More...

#include <basic_socket_acceptor.hpp>

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

Classes

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

Public Types

typedef Executor executor_type
 The type of the executor associated with the object.
 
typedef detail::reactive_socket_service< Protocol >::native_handle_type native_handle_type
 The native representation of an acceptor.
 
typedef Protocol protocol_type
 The protocol type.
 
typedef Protocol::endpoint endpoint_type
 The endpoint type.
 
- Public Types inherited from asio::socket_base
enum  shutdown_type { shutdown_receive = ASIO_OS_DEF(SHUT_RD), shutdown_send = ASIO_OS_DEF(SHUT_WR), shutdown_both = ASIO_OS_DEF(SHUT_RDWR) }
 Different ways a socket may be shutdown.
 
enum  wait_type { wait_read, wait_write, wait_error }
 Wait types. More...
 
typedef int message_flags
 Bitmask type for flags that can be passed to send and receive operations.
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_BROADCAST)> broadcast
 Socket option to permit sending of broadcast messages. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DEBUG)> debug
 Socket option to enable socket-level debugging. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_DONTROUTE)> do_not_route
 Socket option to prevent routing, use local interfaces only. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_KEEPALIVE)> keep_alive
 Socket option to send keep-alives. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDBUF)> send_buffer_size
 Socket option for the send buffer size of a socket. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_SNDLOWAT)> send_low_watermark
 Socket option for the send low watermark. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVBUF)> receive_buffer_size
 Socket option for the receive buffer size of a socket. More...
 
typedef asio::detail::socket_option::integer< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_RCVLOWAT)> receive_low_watermark
 Socket option for the receive low watermark. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_REUSEADDR)> reuse_address
 Socket option to allow the socket to be bound to an address that is already in use. More...
 
typedef asio::detail::socket_option::linger< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_LINGER)> linger
 Socket option to specify whether the socket lingers on close if unsent data is present. More...
 
typedef asio::detail::socket_option::boolean< ASIO_OS_DEF(SOL_SOCKET), ASIO_OS_DEF(SO_OOBINLINE)> out_of_band_inline
 Socket option for putting received out-of-band data inline. More...
 
typedef asio::detail::socket_option::boolean< asio::detail::custom_socket_option_level, asio::detail::enable_connection_aborted_option > enable_connection_aborted
 Socket option to report aborted connections on accept. More...
 
typedef asio::detail::io_control::bytes_readable bytes_readable
 IO control command to get the amount of data that can be read without blocking. More...
 

Public Member Functions

 basic_socket_acceptor (const executor_type &ex)
 Construct an acceptor without opening it. More...
 
template<typename ExecutionContext >
 basic_socket_acceptor (ExecutionContext &context, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct an acceptor without opening it. More...
 
 basic_socket_acceptor (const executor_type &ex, const protocol_type &protocol)
 Construct an open acceptor. More...
 
template<typename ExecutionContext >
 basic_socket_acceptor (ExecutionContext &context, const protocol_type &protocol, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct an open acceptor. More...
 
 basic_socket_acceptor (const executor_type &ex, const endpoint_type &endpoint, bool reuse_addr=true)
 Construct an acceptor opened on the given endpoint. More...
 
template<typename ExecutionContext >
 basic_socket_acceptor (ExecutionContext &context, const endpoint_type &endpoint, bool reuse_addr=true, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct an acceptor opened on the given endpoint. More...
 
 basic_socket_acceptor (const executor_type &ex, const protocol_type &protocol, const native_handle_type &native_acceptor)
 Construct a basic_socket_acceptor on an existing native acceptor. More...
 
template<typename ExecutionContext >
 basic_socket_acceptor (ExecutionContext &context, const protocol_type &protocol, const native_handle_type &native_acceptor, typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *=0)
 Construct a basic_socket_acceptor on an existing native acceptor. More...
 
 ~basic_socket_acceptor ()
 Destroys the acceptor. More...
 
executor_type get_executor () ASIO_NOEXCEPT
 Get the executor associated with the object.
 
void open (const protocol_type &protocol=protocol_type())
 Open the acceptor using the specified protocol. More...
 
ASIO_SYNC_OP_VOID open (const protocol_type &protocol, asio::error_code &ec)
 Open the acceptor using the specified protocol. More...
 
void assign (const protocol_type &protocol, const native_handle_type &native_acceptor)
 Assigns an existing native acceptor to the acceptor.
 
ASIO_SYNC_OP_VOID assign (const protocol_type &protocol, const native_handle_type &native_acceptor, asio::error_code &ec)
 Assigns an existing native acceptor to the acceptor.
 
bool is_open () const
 Determine whether the acceptor is open.
 
void bind (const endpoint_type &endpoint)
 Bind the acceptor to the given local endpoint. More...
 
ASIO_SYNC_OP_VOID bind (const endpoint_type &endpoint, asio::error_code &ec)
 Bind the acceptor to the given local endpoint. More...
 
void listen (int backlog=socket_base::max_listen_connections)
 Place the acceptor into the state where it will listen for new connections. More...
 
ASIO_SYNC_OP_VOID listen (int backlog, asio::error_code &ec)
 Place the acceptor into the state where it will listen for new connections. More...
 
void close ()
 Close the acceptor. More...
 
ASIO_SYNC_OP_VOID close (asio::error_code &ec)
 Close the acceptor. More...
 
native_handle_type release ()
 Release ownership of the underlying native acceptor. More...
 
native_handle_type release (asio::error_code &ec)
 Release ownership of the underlying native acceptor. More...
 
native_handle_type native_handle ()
 Get the native acceptor representation. More...
 
void cancel ()
 Cancel all asynchronous operations associated with the acceptor. More...
 
ASIO_SYNC_OP_VOID cancel (asio::error_code &ec)
 Cancel all asynchronous operations associated with the acceptor. More...
 
template<typename SettableSocketOption >
void set_option (const SettableSocketOption &option)
 Set an option on the acceptor. More...
 
template<typename SettableSocketOption >
ASIO_SYNC_OP_VOID set_option (const SettableSocketOption &option, asio::error_code &ec)
 Set an option on the acceptor. More...
 
template<typename GettableSocketOption >
void get_option (GettableSocketOption &option) const
 Get an option from the acceptor. More...
 
template<typename GettableSocketOption >
ASIO_SYNC_OP_VOID get_option (GettableSocketOption &option, asio::error_code &ec) const
 Get an option from the acceptor. More...
 
template<typename IoControlCommand >
void io_control (IoControlCommand &command)
 Perform an IO control command on the acceptor. More...
 
template<typename IoControlCommand >
ASIO_SYNC_OP_VOID io_control (IoControlCommand &command, asio::error_code &ec)
 Perform an IO control command on the acceptor. More...
 
bool non_blocking () const
 Gets the non-blocking mode of the acceptor. More...
 
void non_blocking (bool mode)
 Sets the non-blocking mode of the acceptor. More...
 
ASIO_SYNC_OP_VOID non_blocking (bool mode, asio::error_code &ec)
 Sets the non-blocking mode of the acceptor. More...
 
bool native_non_blocking () const
 Gets the non-blocking mode of the native acceptor implementation. More...
 
void native_non_blocking (bool mode)
 Sets the non-blocking mode of the native acceptor implementation. More...
 
ASIO_SYNC_OP_VOID native_non_blocking (bool mode, asio::error_code &ec)
 Sets the non-blocking mode of the native acceptor implementation. More...
 
endpoint_type local_endpoint () const
 Get the local endpoint of the acceptor. More...
 
endpoint_type local_endpoint (asio::error_code &ec) const
 Get the local endpoint of the acceptor. More...
 
void wait (wait_type w)
 Wait for the acceptor to become ready to read, ready to write, or to have pending error conditions. More...
 
ASIO_SYNC_OP_VOID wait (wait_type w, asio::error_code &ec)
 Wait for the acceptor to become ready to read, ready to write, or to have pending error conditions. More...
 
template<WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
 ASIO_INITFN_AUTO_RESULT_TYPE (WaitHandler, void(asio::error_code)) async_wait(wait_type w
 Asynchronously wait for the acceptor to become ready to read, ready to write, or to have pending error conditions. More...
 
 ASIO_MOVE_ARG (WaitHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
template<typename Protocol1 , typename Executor1 >
void accept (basic_socket< Protocol1, Executor1 > &peer, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type *=0)
 Accept a new connection. More...
 
template<typename Protocol1 , typename Executor1 >
ASIO_SYNC_OP_VOID accept (basic_socket< Protocol1, Executor1 > &peer, asio::error_code &ec, typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type *=0)
 Accept a new connection. More...
 
template<typename Protocol1 , typename Executor1 , AcceptHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
 ASIO_INITFN_AUTO_RESULT_TYPE (AcceptHandler, void(asio::error_code)) async_accept(basic_socket< Protocol1
 Start an asynchronous accept. More...
 
Executor1 ASIO_MOVE_ARG (AcceptHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type)
 
Executor1 enable_if< is_convertible< Protocol, Protocol1 >::value >::type AcceptHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (executor_type)> ASIO_INITFN_AUTO_RESULT_TYPE(AcceptHandler
 
Executor1 enable_if< is_convertible< Protocol, Protocol1 >::value >::type AcceptHandler void (asio::error_code)) async_accept(basic_socket< protocol_type
 
Executor1 enable_if< is_convertible< Protocol, Protocol1 >::value >::type AcceptHandler Executor1 endpoint_type ASIO_MOVE_ARG (AcceptHandler) handler ASIO_DEFAULT_COMPLETION_TOKEN(executor_type))
 
- Public Member Functions inherited from asio::socket_base
 ASIO_STATIC_CONSTANT (int, message_peek=ASIO_OS_DEF(MSG_PEEK))
 
 ASIO_STATIC_CONSTANT (int, message_out_of_band=ASIO_OS_DEF(MSG_OOB))
 
 ASIO_STATIC_CONSTANT (int, message_do_not_route=ASIO_OS_DEF(MSG_DONTROUTE))
 
 ASIO_STATIC_CONSTANT (int, message_end_of_record=ASIO_OS_DEF(MSG_EOR))
 
 ASIO_STATIC_CONSTANT (int, max_listen_connections=ASIO_OS_DEF(SOMAXCONN))
 The maximum length of the queue of pending incoming connections.
 
 ASIO_STATIC_CONSTANT (int, max_connections=ASIO_OS_DEF(SOMAXCONN))
 (Deprecated: Use max_listen_connections.) The maximum length of the queue of pending incoming connections. More...
 

Public Attributes

Executor1 & peer
 
Executor1 enable_if< is_convertible< Protocol, Protocol1 >::value >::type AcceptHandler Executor1 & peer
 
Executor1 enable_if< is_convertible< Protocol, Protocol1 >::value >::type AcceptHandler Executor1 endpoint_typepeer_endpoint
 

Additional Inherited Members

- Protected Member Functions inherited from asio::socket_base
 ~socket_base ()
 Protected destructor to prevent deletion through this type.
 

Detailed Description

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

Provides the ability to accept new connections.

The basic_socket_acceptor class template is used for accepting new socket connections.

Thread Safety
Distinct objects: Safe.
Shared objects: Unsafe.
Example
Opening a socket acceptor with the SO_REUSEADDR option enabled:
asio::ip::tcp::acceptor acceptor(my_context);
acceptor.open(endpoint.protocol());
acceptor.set_option(asio::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint);
acceptor.listen();

Constructor & Destructor Documentation

◆ basic_socket_acceptor() [1/8]

template<typename Protocol , typename Executor >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( const executor_type ex)
inlineexplicit

Construct an acceptor without opening it.

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.

Parameters
exThe I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.

◆ basic_socket_acceptor() [2/8]

template<typename Protocol , typename Executor >
template<typename ExecutionContext >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( ExecutionContext &  context,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
inlineexplicit

Construct an acceptor without opening it.

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.

Parameters
contextAn execution context which provides the I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.

◆ basic_socket_acceptor() [3/8]

template<typename Protocol , typename Executor >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( const executor_type ex,
const protocol_type protocol 
)
inline

Construct an open acceptor.

This constructor creates an acceptor and automatically opens it.

Parameters
exThe I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
protocolAn object specifying protocol parameters to be used.
Exceptions
asio::system_errorThrown on failure.

◆ basic_socket_acceptor() [4/8]

template<typename Protocol , typename Executor >
template<typename ExecutionContext >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( ExecutionContext &  context,
const protocol_type protocol,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
inline

Construct an open acceptor.

This constructor creates an acceptor and automatically opens it.

Parameters
contextAn execution context which provides the I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
protocolAn object specifying protocol parameters to be used.
Exceptions
asio::system_errorThrown on failure.

◆ basic_socket_acceptor() [5/8]

template<typename Protocol , typename Executor >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( const executor_type ex,
const endpoint_type endpoint,
bool  reuse_addr = true 
)
inline

Construct an acceptor opened on the given endpoint.

This constructor creates an acceptor and automatically opens it to listen for new connections on the specified endpoint.

Parameters
exThe I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
endpointAn endpoint on the local machine on which the acceptor will listen for new connections.
reuse_addrWhether the constructor should set the socket option socket_base::reuse_address.
Exceptions
asio::system_errorThrown on failure.
Note
This constructor is equivalent to the following code:
basic_socket_acceptor<Protocol> acceptor(my_context);
acceptor.open(endpoint.protocol());
if (reuse_addr)
acceptor.set_option(socket_base::reuse_address(true));
acceptor.bind(endpoint);
acceptor.listen();

◆ basic_socket_acceptor() [6/8]

template<typename Protocol , typename Executor >
template<typename ExecutionContext >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( ExecutionContext &  context,
const endpoint_type endpoint,
bool  reuse_addr = true,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
inline

Construct an acceptor opened on the given endpoint.

This constructor creates an acceptor and automatically opens it to listen for new connections on the specified endpoint.

Parameters
contextAn execution context which provides the I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
endpointAn endpoint on the local machine on which the acceptor will listen for new connections.
reuse_addrWhether the constructor should set the socket option socket_base::reuse_address.
Exceptions
asio::system_errorThrown on failure.
Note
This constructor is equivalent to the following code:
basic_socket_acceptor<Protocol> acceptor(my_context);
acceptor.open(endpoint.protocol());
if (reuse_addr)
acceptor.set_option(socket_base::reuse_address(true));
acceptor.bind(endpoint);
acceptor.listen();

◆ basic_socket_acceptor() [7/8]

template<typename Protocol , typename Executor >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( const executor_type ex,
const protocol_type protocol,
const native_handle_type native_acceptor 
)
inline

Construct a basic_socket_acceptor on an existing native acceptor.

This constructor creates an acceptor object to hold an existing native acceptor.

Parameters
exThe I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
protocolAn object specifying protocol parameters to be used.
native_acceptorA native acceptor.
Exceptions
asio::system_errorThrown on failure.

◆ basic_socket_acceptor() [8/8]

template<typename Protocol , typename Executor >
template<typename ExecutionContext >
asio::basic_socket_acceptor< Protocol, Executor >::basic_socket_acceptor ( ExecutionContext &  context,
const protocol_type protocol,
const native_handle_type native_acceptor,
typename enable_if< is_convertible< ExecutionContext &, execution_context &>::value >::type *  = 0 
)
inline

Construct a basic_socket_acceptor on an existing native acceptor.

This constructor creates an acceptor object to hold an existing native acceptor.

Parameters
contextAn execution context which provides the I/O executor that the acceptor will use, by default, to dispatch handlers for any asynchronous operations performed on the acceptor.
protocolAn object specifying protocol parameters to be used.
native_acceptorA native acceptor.
Exceptions
asio::system_errorThrown on failure.

◆ ~basic_socket_acceptor()

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

Destroys the acceptor.

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

Member Function Documentation

◆ accept() [1/2]

template<typename Protocol , typename Executor >
template<typename Protocol1 , typename Executor1 >
void asio::basic_socket_acceptor< Protocol, Executor >::accept ( basic_socket< Protocol1, Executor1 > &  peer,
typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type *  = 0 
)
inline

Accept a new connection.

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.

Parameters
peerThe socket into which the new connection will be accepted.
Exceptions
asio::system_errorThrown on failure.
Example
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::socket socket(my_context);
acceptor.accept(socket);

◆ accept() [2/2]

template<typename Protocol , typename Executor >
template<typename Protocol1 , typename Executor1 >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::accept ( basic_socket< Protocol1, Executor1 > &  peer,
asio::error_code ec,
typename enable_if< is_convertible< Protocol, Protocol1 >::value >::type *  = 0 
)
inline

Accept a new connection.

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.

Parameters
peerThe socket into which the new connection will be accepted.
ecSet to indicate what error occurred, if any.
Example
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::socket socket(my_context);
acceptor.accept(socket, ec);
if (ec)
{
// An error occurred.
}

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [1/2]

template<typename Protocol , typename Executor >
template<WaitHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
asio::basic_socket_acceptor< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( WaitHandler  ,
void(asio::error_code  
)

Asynchronously wait for the acceptor to become ready to read, ready to write, or to have pending error conditions.

This function is used to perform an asynchronous wait for an acceptor to enter a ready to read, write or error condition state.

Parameters
wSpecifies the desired acceptor state.
handlerThe handler to be called when the wait operation completes. Copies will be made of the handler as required. The function signature of the handler must be:
void handler(
const asio::error_code& error // Result of operation
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Example
void wait_handler(const asio::error_code& error)
{
if (!error)
{
// Wait succeeded.
}
}
...
asio::ip::tcp::acceptor acceptor(my_context);
...
acceptor.async_wait(
wait_handler);

◆ ASIO_INITFN_AUTO_RESULT_TYPE() [2/2]

template<typename Protocol , typename Executor >
template<typename Protocol1 , typename Executor1 , AcceptHandler ASIO_DEFAULT_COMPLETION_TOKEN_TYPE>
asio::basic_socket_acceptor< Protocol, Executor >::ASIO_INITFN_AUTO_RESULT_TYPE ( AcceptHandler  ,
void(asio::error_code  
)

Start an asynchronous accept.

This function is used to asynchronously accept a new connection into a socket. The function call always returns immediately.

Parameters
peerThe 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.
handlerThe 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 asio::error_code& error // Result of operation.
);
Regardless of whether the asynchronous operation completes immediately or not, the handler will not be invoked from within this function. On immediate completion, invocation of the handler will be performed in a manner equivalent to using asio::post().
Example
void accept_handler(const asio::error_code& error)
{
if (!error)
{
// Accept succeeded.
}
}
...
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::socket socket(my_context);
acceptor.async_accept(socket, accept_handler);

◆ bind() [1/2]

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

Bind the acceptor to the given local endpoint.

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

Parameters
endpointAn endpoint on the local machine to which the socket acceptor will be bound.
Exceptions
asio::system_errorThrown on failure.
Example
asio::ip::tcp::acceptor acceptor(my_context);
acceptor.open(endpoint.protocol());
acceptor.bind(endpoint);

◆ bind() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::bind ( const endpoint_type endpoint,
asio::error_code ec 
)
inline

Bind the acceptor to the given local endpoint.

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

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

◆ cancel() [1/2]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::cancel ( )
inline

Cancel all asynchronous operations associated with the acceptor.

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

Exceptions
asio::system_errorThrown on failure.

◆ cancel() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::cancel ( asio::error_code ec)
inline

Cancel all asynchronous operations associated with the acceptor.

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

Parameters
ecSet to indicate what error occurred, if any.

◆ close() [1/2]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::close ( )
inline

Close the acceptor.

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.

Exceptions
asio::system_errorThrown on failure.

◆ close() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::close ( asio::error_code ec)
inline

Close the acceptor.

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.

Parameters
ecSet to indicate what error occurred, if any.
Example
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::error_code ec;
acceptor.close(ec);
if (ec)
{
// An error occurred.
}

◆ get_option() [1/2]

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

Get an option from the acceptor.

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

Parameters
optionThe option value to be obtained from the acceptor.
Exceptions
asio::system_errorThrown on failure.
See also
GettableSocketOption
asio::socket_base::reuse_address
Example
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::reuse_address option;
acceptor.get_option(option);
bool is_set = option.get();

◆ get_option() [2/2]

template<typename Protocol , typename Executor >
template<typename GettableSocketOption >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::get_option ( GettableSocketOption &  option,
asio::error_code ec 
) const
inline

Get an option from the acceptor.

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

Parameters
optionThe option value to be obtained from the acceptor.
ecSet to indicate what error occurred, if any.
See also
GettableSocketOption
asio::socket_base::reuse_address
Example
Getting the value of the SOL_SOCKET/SO_REUSEADDR option:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::reuse_address option;
acceptor.get_option(option, ec);
if (ec)
{
// An error occurred.
}
bool is_set = option.get();

◆ io_control() [1/2]

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

Perform an IO control command on the acceptor.

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

Parameters
commandThe IO control command to be performed on the acceptor.
Exceptions
asio::system_errorThrown on failure.
See also
IoControlCommand
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::non_blocking_io command(true);
socket.io_control(command);

◆ io_control() [2/2]

template<typename Protocol , typename Executor >
template<typename IoControlCommand >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::io_control ( IoControlCommand &  command,
asio::error_code ec 
)
inline

Perform an IO control command on the acceptor.

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

Parameters
commandThe IO control command to be performed on the acceptor.
ecSet to indicate what error occurred, if any.
See also
IoControlCommand
asio::socket_base::non_blocking_io
Example
Getting the number of bytes ready to read:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::non_blocking_io command(true);
socket.io_control(command, ec);
if (ec)
{
// An error occurred.
}

◆ listen() [1/2]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::listen ( int  backlog = socket_base::max_listen_connections)
inline

Place the acceptor into the state where it will listen for new connections.

This function puts the socket acceptor into the state where it may accept new connections.

Parameters
backlogThe maximum length of the queue of pending connections.
Exceptions
asio::system_errorThrown on failure.

◆ listen() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::listen ( int  backlog,
asio::error_code ec 
)
inline

Place the acceptor into the state where it will listen for new connections.

This function puts the socket acceptor into the state where it may accept new connections.

Parameters
backlogThe maximum length of the queue of pending connections.
ecSet to indicate what error occurred, if any.
Example
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::error_code ec;
acceptor.listen(asio::socket_base::max_listen_connections, ec);
if (ec)
{
// An error occurred.
}

◆ local_endpoint() [1/2]

template<typename Protocol , typename Executor >
endpoint_type asio::basic_socket_acceptor< Protocol, Executor >::local_endpoint ( ) const
inline

Get the local endpoint of the acceptor.

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

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

◆ local_endpoint() [2/2]

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

Get the local endpoint of the acceptor.

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

Parameters
ecSet to indicate what error occurred, if any.
Returns
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.
Example
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::error_code ec;
asio::ip::tcp::endpoint endpoint = acceptor.local_endpoint(ec);
if (ec)
{
// An error occurred.
}

◆ native_handle()

template<typename Protocol , typename Executor >
native_handle_type asio::basic_socket_acceptor< Protocol, Executor >::native_handle ( )
inline

Get the native acceptor representation.

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.

◆ native_non_blocking() [1/3]

template<typename Protocol , typename Executor >
bool asio::basic_socket_acceptor< Protocol, Executor >::native_non_blocking ( ) const
inline

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

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.

Returns
true if the underlying acceptor is in non-blocking mode and direct system calls may fail with asio::error::would_block (or the equivalent system error).
Note
The current non-blocking mode is cached by the acceptor object. Consequently, the return value may be incorrect if the non-blocking mode was set directly on the native acceptor.

◆ native_non_blocking() [2/3]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::native_non_blocking ( bool  mode)
inline

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

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.

Parameters
modeIf true, the underlying acceptor is put into non-blocking mode and direct system calls may fail with asio::error::would_block (or the equivalent system error).
Exceptions
asio::system_errorThrown on failure. If the mode is false, but the current value of non_blocking() is true, this function fails with asio::error::invalid_argument, as the combination does not make sense.

◆ native_non_blocking() [3/3]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::native_non_blocking ( bool  mode,
asio::error_code ec 
)
inline

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

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.

Parameters
modeIf true, the underlying acceptor is put into non-blocking mode and direct system calls may fail with asio::error::would_block (or the equivalent system error).
ecSet to indicate what error occurred, if any. If the mode is false, but the current value of non_blocking() is true, this function fails with asio::error::invalid_argument, as the combination does not make sense.

◆ non_blocking() [1/3]

template<typename Protocol , typename Executor >
bool asio::basic_socket_acceptor< Protocol, Executor >::non_blocking ( ) const
inline

Gets the non-blocking mode of the acceptor.

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

◆ non_blocking() [2/3]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::non_blocking ( bool  mode)
inline

Sets the non-blocking mode of the acceptor.

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

◆ non_blocking() [3/3]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::non_blocking ( bool  mode,
asio::error_code ec 
)
inline

Sets the non-blocking mode of the acceptor.

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

◆ open() [1/2]

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

Open the acceptor using the specified protocol.

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

Parameters
protocolAn object specifying which protocol is to be used.
Exceptions
asio::system_errorThrown on failure.
Example
asio::ip::tcp::acceptor acceptor(my_context);
acceptor.open(asio::ip::tcp::v4());

◆ open() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::open ( const protocol_type protocol,
asio::error_code ec 
)
inline

Open the acceptor using the specified protocol.

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

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

◆ release() [1/2]

template<typename Protocol , typename Executor >
native_handle_type asio::basic_socket_acceptor< Protocol, Executor >::release ( )
inline

Release ownership of the underlying native acceptor.

This function causes all outstanding asynchronous accept operations to finish immediately, and the handlers for cancelled operations will be passed the asio::error::operation_aborted error. Ownership of the native acceptor is then transferred to the caller.

Exceptions
asio::system_errorThrown on failure.
Note
This function is unsupported on Windows versions prior to Windows 8.1, and will fail with asio::error::operation_not_supported on these platforms.

◆ release() [2/2]

template<typename Protocol , typename Executor >
native_handle_type asio::basic_socket_acceptor< Protocol, Executor >::release ( asio::error_code ec)
inline

Release ownership of the underlying native acceptor.

This function causes all outstanding asynchronous accept operations to finish immediately, and the handlers for cancelled operations will be passed the asio::error::operation_aborted error. Ownership of the native acceptor is then transferred to the caller.

Parameters
ecSet to indicate what error occurred, if any.
Note
This function is unsupported on Windows versions prior to Windows 8.1, and will fail with asio::error::operation_not_supported on these platforms.

◆ set_option() [1/2]

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

Set an option on the acceptor.

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

Parameters
optionThe new option value to be set on the acceptor.
Exceptions
asio::system_errorThrown on failure.
See also
SettableSocketOption
asio::socket_base::reuse_address asio::socket_base::enable_connection_aborted
Example
Setting the SOL_SOCKET/SO_REUSEADDR option:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::reuse_address option(true);
acceptor.set_option(option);

◆ set_option() [2/2]

template<typename Protocol , typename Executor >
template<typename SettableSocketOption >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::set_option ( const SettableSocketOption &  option,
asio::error_code ec 
)
inline

Set an option on the acceptor.

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

Parameters
optionThe new option value to be set on the acceptor.
ecSet to indicate what error occurred, if any.
See also
SettableSocketOption
asio::socket_base::reuse_address asio::socket_base::enable_connection_aborted
Example
Setting the SOL_SOCKET/SO_REUSEADDR option:
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::ip::tcp::acceptor::reuse_address option(true);
acceptor.set_option(option, ec);
if (ec)
{
// An error occurred.
}

◆ wait() [1/2]

template<typename Protocol , typename Executor >
void asio::basic_socket_acceptor< Protocol, Executor >::wait ( wait_type  w)
inline

Wait for the acceptor to become ready to read, ready to write, or to have pending error conditions.

This function is used to perform a blocking wait for an acceptor to enter a ready to read, write or error condition state.

Parameters
wSpecifies the desired acceptor state.
Example
Waiting for an acceptor to become readable.
asio::ip::tcp::acceptor acceptor(my_context);
...

◆ wait() [2/2]

template<typename Protocol , typename Executor >
ASIO_SYNC_OP_VOID asio::basic_socket_acceptor< Protocol, Executor >::wait ( wait_type  w,
asio::error_code ec 
)
inline

Wait for the acceptor to become ready to read, ready to write, or to have pending error conditions.

This function is used to perform a blocking wait for an acceptor to enter a ready to read, write or error condition state.

Parameters
wSpecifies the desired acceptor state.
ecSet to indicate what error occurred, if any.
Example
Waiting for an acceptor to become readable.
asio::ip::tcp::acceptor acceptor(my_context);
...
asio::error_code ec;

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