Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext
basic_socket_acceptor::async_accept (3 of 8 overloads)

Start an asynchronous accept.

template<
    typename MoveAcceptHandler = DEFAULT>
DEDUCED async_accept(
    MoveAcceptHandler && handler = DEFAULT);

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

This overload requires that the Protocol template parameter satisfy the AcceptableProtocol type requirements.

Parameters

handler

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(
  // Result of operation.
  const boost::system::error_code& error,
  // On success, the newly accepted socket.
  typename Protocol::socket::template
    rebind_executor<executor_type>::other peer
);

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

Example
void accept_handler(const boost::system::error_code& error,
    boost::asio::ip::tcp::socket peer)
{
  if (!error)
  {
    // Accept succeeded.
  }
}

...

boost::asio::ip::tcp::acceptor acceptor(my_context);
...
acceptor.async_accept(accept_handler);

PrevUpHomeNext