1NN_SEND(3) nanomsg 1.1.5 NN_SEND(3)
2
3
4
6 nn_send - send a message
7
9 #include <nanomsg/nn.h>
10
11 int nn_send (int s, const void *buf, size_t len, int flags);
12
14 The function will send a message containing the data from buffer
15 pointed to by buf parameter to the socket s. The message will be len
16 bytes long.
17
18 Alternatively, to send a buffer allocated by nn_allocmsg(3) function
19 set the buf parameter to point to the pointer to the buffer and len
20 parameter to NN_MSG constant. In this case a successful call to nn_send
21 will deallocate the buffer. Trying to deallocate it afterwards will
22 result in undefined behaviour.
23
24 Which of the peers the message will be sent to is determined by the
25 particular socket type.
26
27 The flags argument is a combination of the flags defined below:
28
29 NN_DONTWAIT
30 Specifies that the operation should be performed in non-blocking
31 mode. If the message cannot be sent straight away, the function
32 will fail with errno set to EAGAIN.
33
35 If the function succeeds, the number of bytes in the message is
36 returned. Otherwise, -1 is returned and errno is set to to one of the
37 values defined below.
38
40 EFAULT
41 buf is NULL or len is NN_MSG and the message pointer (pointed to by
42 buf) is NULL.
43
44 EBADF
45 The provided socket is invalid.
46
47 ENOTSUP
48 The operation is not supported by this socket type.
49
50 EFSM
51 The operation cannot be performed on this socket at the moment
52 because the socket is not in the appropriate state. This error may
53 occur with socket types that switch between several states.
54
55 EAGAIN
56 Non-blocking mode was requested and the message cannot be sent at
57 the moment.
58
59 EINTR
60 The operation was interrupted by delivery of a signal before the
61 message was sent.
62
63 ETIMEDOUT
64 Individual socket types may define their own specific timeouts. If
65 such timeout is hit, this error will be returned.
66
67 ETERM
68 The library is terminating.
69
71 Using data directly:
72
73 nbytes = nn_send (s, "ABC", 3, 0);
74 assert (nbytes == 3);
75
76 Using a pre-allocated message buffer:
77
78 void *msg = nn_allocmsg(3, 0);
79 strncpy(msg, "ABC", 3);
80 nbytes = nn_send (s, &msg, NN_MSG, 0);
81 assert (nbytes == 3);
82
84 nn_recv(3) nn_sendmsg(3) nn_socket(3) nanomsg(7)
85
87 Martin Sustrik <sustrik@250bpm.com>
88
89
90
91 2019-07-25 NN_SEND(3)