table of contents
NNG_SEND(3) | NNG Reference Manual | NNG_SEND(3) |
NAME¶
nng_send - send data
SYNOPSIS¶
#include <nng/nng.h> int nng_send(nng_socket s, void *data, size_t size, int flags);
DESCRIPTION¶
The nng_send() function sends a message containing the data of length size using the socket s.
Note
The semantics of what sending a message means vary from protocol
to
protocol, so examination of the protocol documentation is encouraged. (For
example, with an 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 data (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.)
The flags may contain either of (or neither of) the following values:
NNG_FLAG_NONBLOCK
NNG_FLAG_ALLOC
Note
The NNG_FLAG_ALLOC flag is deprecated and
may be removed in a future release.
Applications should use nng_sendmsg() for zero copy
performance improvements.
Note
Regardless of the presence or absence of
NNG_FLAG_NONBLOCK, there may
be queues between the sender and the receiver. Furthermore, there is no
guarantee that the message has actually been delivered. Finally, with some
protocols, the semantic is implicitly
NNG_FLAG_NONBLOCK, such as with pub sockets,
which are best-effort delivery only.
Important
When using NNG_FLAG_ALLOC, it is important
that the value of size
match the actual allocated size of the data. Using an incorrect size results
in unspecified behavior, which may include heap corruption, program crashes,
or trans-dimensional mutation of the program’s author.
RETURN VALUES¶
This function returns 0 on success, and non-zero otherwise.
ERRORS¶
NNG_EAGAIN
NNG_ECLOSED
NNG_EINVAL
NNG_EMSGSIZE
NNG_ENOMEM
NNG_ENOTSUP
NNG_ESTATE
NNG_ETIMEDOUT
SEE ALSO¶
nng_alloc(3), nng_free(3), nng_recv(3), nng_sendmsg(3), nng_strerror(3), nng_socket(5), nng(7)
2025-02-02 |