= nng_tcp_listener_accept(3tcp)
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
// file was obtained (LICENSE.txt).  A copy of the license may also be
// found online at https://opensource.org/licenses/MIT.
//

== NAME

nng_tcp_listener_accept - accept incoming TCP connection

== SYNOPSIS

[source, c]
----
#include <nng/nng.h>
#include <nng/supplemental/tcp/tcp.h>

void nng_tcp_listener_accept(nng_tcp_listener *l, nng_aio *aio);
----

== DESCRIPTION

The `nng_tcp_listener_accept()` attempts to accept an incoming TCP connection
from a remote peer, using the listener _l_.
The operation is completed asynchronously, using _aio_.

This operation can only be done after the listener is already bound to
a TCP port and is listening.
(See `<<nng_tcp_listener_listen.3tcp#,nng_tcp_listener_listen()>>`.)

If a connection is successfully established, the _aio_ will have the
resulting `<<nng_tcp.5#,nng_tcp>>` stored as its first output.
(See `<<nng_aio_get_output.3#,nng_aio_get_output()>>`.)

The address of the remote peer can be determined by using the
`<<nng_tcp_peername.3tcp#,nng_tcp_peername()>>` function on the
returned `<<nng_tcp.5#,nng_tcp>>`.

== RETURN VALUES

None.

== ERRORS

[horizontal]
`NNG_ECANCELED`:: The operation was aborted.
`NNG_ECLOSED`:: The dialer is closed.
`NNG_ECONNRESET`:: The TCP connection was reset by the peer.
`NNG_ENOMEM`:: Insufficient free memory exists.
`NNG_ESTATE`:: The listener is not not listening.

== SEE ALSO

[.text-left]
<<nng_strerror.3#,nng_strerror(3)>>,
<<nng_tcp_listener_alloc.3tcp#,nng_tcp_listener_alloc(3tcp)>>,
<<nng_tcp_listener_close.3tcp#,nng_tcp_listener_close(3tcp)>>,
<<nng_tcp_listener_free.3tcp#,nng_tcp_listener_free(3tcp)>>,
<<nng_tcp_listener_listen.3tcp#,nng_tcp_listener_listen(3tcp)>>,
<<nng_aio.5#,nng_aio(5)>>,
<<nng_tcp.5#,nng_tcp(5)>>,
<<nng_tcp_listener.5#,nng_tcp_listener(5)>>
