1ZMQ_MSG_SEND(3)                   0MQ Manual                   ZMQ_MSG_SEND(3)
2
3
4

NAME

6       zmq_msg_send - send a message part on a socket
7

SYNOPSIS

9       int zmq_msg_send (zmq_msg_t *msg, void *socket, int flags);
10

DESCRIPTION

12       The zmq_msg_send() function is identical to zmq_sendmsg(3), which shall
13       be deprecated in future versions. zmq_msg_send() is more consistent
14       with other message manipulation functions.
15
16       The zmq_msg_send() function shall queue the message referenced by the
17       msg argument to be sent to the socket referenced by the socket
18       argument. The flags argument is a combination of the flags defined
19       below:
20
21       ZMQ_DONTWAIT
22           For socket types (DEALER, PUSH) that block (either with
23           ZMQ_IMMEDIATE option set and no peer available, or all peers having
24           full high-water mark), specifies that the operation should be
25           performed in non-blocking mode. If the message cannot be queued on
26           the socket, the zmq_msg_send() function shall fail with errno set
27           to EAGAIN.
28
29       ZMQ_SNDMORE
30           Specifies that the message being sent is a multi-part message, and
31           that further message parts are to follow. Refer to the section
32           regarding multi-part messages below for a detailed description.
33
34       The zmq_msg_t structure passed to zmq_msg_send() is nullified on a
35       successful call. If you want to send the same message to multiple
36       sockets you have to copy it (e.g. using zmq_msg_copy()). If the call
37       fails, the zmq_msg_t structure stays intact, and must be consumed by
38       another call to zmq_msg_send() on the same or another socket, or
39       released using zmq_msg_close() to avoid a memory leak.
40
41           Note
42           A successful invocation of zmq_msg_send() does not indicate that
43           the message has been transmitted to the network, only that it has
44           been queued on the socket and 0MQ has assumed responsibility for
45           the message. You do not need to call zmq_msg_close() after a
46           successful zmq_msg_send().
47
48   Multi-part messages
49       A 0MQ message is composed of 1 or more message parts. Each message part
50       is an independent zmq_msg_t in its own right. 0MQ ensures atomic
51       delivery of messages: peers shall receive either all message parts of a
52       message or none at all. The total number of message parts is unlimited
53       except by available memory.
54
55       An application that sends multi-part messages must use the ZMQ_SNDMORE
56       flag when sending each message part except the final one.
57

RETURN VALUE

59       The zmq_msg_send() function shall return number of bytes in the message
60       if successful (if number of bytes is higher than MAX_INT, the function
61       will return MAX_INT). Otherwise it shall return -1 and set errno to one
62       of the values defined below.
63

ERRORS

65       EAGAIN
66           Non-blocking mode was requested and the message cannot be sent at
67           the moment.
68
69       ENOTSUP
70           The zmq_msg_send() operation is not supported by this socket type.
71
72       EINVAL
73           The sender tried to send multipart data, which the socket type does
74           not allow.
75
76       EFSM
77           The zmq_msg_send() operation cannot be performed on this socket at
78           the moment due to the socket not being in the appropriate state.
79           This error may occur with socket types that switch between several
80           states, such as ZMQ_REP. See the messaging patterns section of
81           zmq_socket(3) for more information.
82
83       ETERM
84           The 0MQ context associated with the specified socket was
85           terminated.
86
87       ENOTSOCK
88           The provided socket was invalid.
89
90       EINTR
91           The operation was interrupted by delivery of a signal before the
92           message was sent.
93
94       EFAULT
95           Invalid message.
96
97       EHOSTUNREACH
98           The message cannot be routed.
99

EXAMPLE

101       Filling in a message and sending it to a socket.
102
103           /* Create a new message, allocating 6 bytes for message content */
104           zmq_msg_t msg;
105           int rc = zmq_msg_init_size (&msg, 6);
106           assert (rc == 0);
107           /* Fill in message content with 'AAAAAA' */
108           memset (zmq_msg_data (&msg), 'A', 6);
109           /* Send the message to the socket */
110           rc = zmq_msg_send (&msg, socket, 0);
111           assert (rc == 6);
112
113       Sending a multi-part message.
114
115           /* Send a multi-part message consisting of three parts to socket */
116           rc = zmq_msg_send (&part1, socket, ZMQ_SNDMORE);
117           rc = zmq_msg_send (&part2, socket, ZMQ_SNDMORE);
118           /* Final part; no more parts to follow */
119           rc = zmq_msg_send (&part3, socket, 0);
120
121

SEE ALSO

123       zmq_recv(3) zmq_send(3) zmq_msg_recv(3) zmq_socket(7) zmq(7)
124

AUTHORS

126       This page was written by the 0MQ community. To make a change please
127       read the 0MQ Contribution Policy at
128       http://www.zeromq.org/docs:contributing.
129
130
131
1320MQ 4.3.4                         01/21/2023                   ZMQ_MSG_SEND(3)
Impressum