This documentation is for version v1.3.0 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.


#include <nng/nng.h>

void nng_send_aio(nng_socket s, nng_aio *aio);


The nng_send_aio() sends a message using the socket s asynchronously.

The message to send must have previously been set on the aio using the nng_aio_set_msg() function. The function assumes “ownership” of the message.

If the message was successfully queued for delivery to the socket, then the aio will be completed, and nng_aio_result() will return zero. In this case the socket will dispose of the message when it is finished with it.

The operation will be “completed”, and the callback associated with the aio executed, as soon as the socket accepts the message for sending. This does not indicate that the message was actually delivered, as it may still be buffered in the sending socket, buffered in the receiving socket, or in flight over physical media.

If the operation fails for any reason (including cancellation or timeout), then the aio callback will be executed and nng_aio_result() will return a non-zero error status. In this case, the callback has a responsibility to retrieve the message from the aio with nng_aio_get_msg() and dispose of it appropriately. (This may include retrying the send operation on the same or a different socket, or deallocating the message with nng_msg_free().)

The semantics of what sending 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 sending (such as sub) or may require other conditions. (For example, rep sockets cannot normally send data, which are responses to requests, until they have first received a request.)


None. (The operation completes asynchronously.)



The operation was aborted.


The socket s is not open.


The message is too large.


Insufficient memory is available.


The protocol for socket s does not support sending.


The socket s cannot send data in this state.


The send timeout expired.