| Home | Libraries | People | FAQ | More

##### basic_socket_acceptor::async_accept (1 of 2 overloads)

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.

###### Parameters

peer

  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.

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

###### Example

    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);