This documentation is for version v1.7.1 of NNG, but the latest released version is v1.8.0. see the documentation for v1.8.0 for the most up-to-date information.

nng_recv_aio(3)

NAME

nng_recv_aio - receive message asynchronously

SYNOPSIS

#include <nng/nng.h>

void nng_recv_aio(nng_socket s, nng_aio *aio);

DESCRIPTION

The nng_recv_aio() receives a message using the socket s asynchronously.

When a message is successfully received by the socket, it is stored in the aio by an internal call equivalent to nng_aio_set_msg(), then the completion callback on the aio is executed. In this case, nng_aio_result() will return zero. The callback function is responsible for retrieving the message and disposing of it appropriately.

Failing to accept and dispose of messages in this case can lead to memory leaks.

If for some reason the asynchronous receive cannot be completed successfully (including by being canceled or timing out), then the callback will still be executed, but nng_aio_result() will be non-zero.

The semantics of what receiving a message means varies from protocol to protocol, so examination of the protocol documentation is encouraged. (For example, with a pub socket the data is broadcast, so that any peers who have a suitable subscription will be able to receive it using nng_recv() or a similar function.) Furthermore, some protocols may not support receiving (such as pub) or may require other conditions. (For example, req sockets cannot normally receive data, which are replies to requests, until they have first sent a request.)

RETURN VALUES

None. (The operation completes asynchronously.)

ERRORS

NNG_ECANCELED

The operation was aborted.

NNG_ECLOSED

The socket s is not open.

NNG_ENOMEM

Insufficient memory is available.

NNG_ENOTSUP

The protocol for socket s does not support receiving.

NNG_ESTATE

The socket s cannot receive data in this state.

NNG_ETIMEDOUT

The receive timeout expired.

SEE ALSO