table of contents
- experimental 1.2.1+dfsg-1
NN_SEND(3) | nanomsg 1.2.1 | NN_SEND(3) |
NAME¶
nn_send - send a message
SYNOPSIS¶
#include <nanomsg/nn.h>
int nn_send (int s, const void *buf, size_t len, int flags);
DESCRIPTION¶
The function will send a message containing the data from buffer pointed to by buf parameter to the socket s. The message will be len bytes long.
Alternatively, to send a buffer allocated by nn_allocmsg(3) function set the buf parameter to point to the pointer to the buffer and len parameter to NN_MSG constant. In this case a successful call to nn_send will deallocate the buffer. Trying to deallocate it afterwards will result in undefined behaviour.
Which of the peers the message will be sent to is determined by the particular socket type.
The flags argument is a combination of the flags defined below:
NN_DONTWAIT
RETURN VALUE¶
If the function succeeds, the number of bytes in the message is returned. Otherwise, -1 is returned and errno is set to to one of the values defined below.
ERRORS¶
EFAULT
EBADF
ENOTSUP
EFSM
EAGAIN
EINTR
ETIMEDOUT
ETERM
EXAMPLE¶
Using data directly:
nbytes = nn_send (s, "ABC", 3, 0); assert (nbytes == 3);
Using a pre-allocated message buffer:
void *msg = nn_allocmsg(3, 0); strncpy(msg, "ABC", 3); nbytes = nn_send (s, &msg, NN_MSG, 0); assert (nbytes == 3);
SEE ALSO¶
AUTHORS¶
Martin Sustrik <sustrik@250bpm.com>
2024-02-21 |