table of contents
NNG_CTX_SEND(3) | NNG Reference Manual | NNG_CTX_SEND(3) |
NAME¶
nng_ctx_send - send message using context asynchronously
SYNOPSIS¶
#include <nng/nng.h> void nng_ctx_send(nng_ctx ctx, nng_aio *aio);
DESCRIPTION¶
The nng_ctx_send() sends a message using the context ctx 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.
Note
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().)
Note
The semantics of what sending a message means varies from protocol
to
protocol, so examination of the protocol documentation is encouraged.
Tip
Context send operations are asynchronous.
If a synchronous operation is needed, one can be constructed by using a
NULL callback on the aio and then waiting for
the operation using nng_aio_wait().
RETURN VALUES¶
None. (The operation completes asynchronously.)
ERRORS¶
NNG_ECANCELED
NNG_ECLOSED
NNG_EMSGSIZE
NNG_ENOMEM
NNG_ENOTSUP
NNG_ESTATE
NNG_ETIMEDOUT
SEE ALSO¶
nng_aio_get_msg(3), nng_aio_set_msg(3), nng_msg_alloc(3), nng_strerror(3), nng_aio(5), nng_ctx(5), nng_msg(5), nng(7)
2024-10-11 |