1ZMQ_RECVMSG(3) 0MQ Manual ZMQ_RECVMSG(3)
2
3
4
6 zmq_recvmsg - receive a message part from a socket
7
9 int zmq_recvmsg (void *socket, zmq_msg_t *msg, int flags);
10
12 The zmq_recvmsg() function shall receive a message part from the socket
13 referenced by the socket argument and store it in the message
14 referenced by the msg argument. Any content previously stored in msg
15 shall be properly deallocated. If there are no message parts available
16 on the specified socket the zmq_recvmsg() function shall block until
17 the request can be satisfied. The flags argument is a combination of
18 the flags defined below:
19
20 ZMQ_DONTWAIT
21 Specifies that the operation should be performed in non-blocking
22 mode. If there are no messages available on the specified socket,
23 the zmq_recvmsg() function shall fail with errno set to EAGAIN.
24
25 Note
26 this API method is deprecated in favor of zmq_msg_recv(3).
27
28 Multi-part messages
29 A 0MQ message is composed of 1 or more message parts. Each message part
30 is an independent zmq_msg_t in its own right. 0MQ ensures atomic
31 delivery of messages: peers shall receive either all message parts of a
32 message or none at all. The total number of message parts is unlimited
33 except by available memory.
34
35 An application that processes multi-part messages must use the
36 ZMQ_RCVMORE zmq_getsockopt(3) option after calling zmq_recvmsg() to
37 determine if there are further parts to receive.
38
40 The zmq_recvmsg() function shall return number of bytes in the message
41 if successful. Otherwise it shall return -1 and set errno to one of the
42 values defined below.
43
45 EAGAIN
46 Either the timeout set via the socket-option ZMQ_RCVTIMEO (see
47 zmq_setsockopt(3)) has been reached (flag ZMQ_DONTWAIT not set)
48 without being able to read a message from the socket or there are
49 no messages available at the moment (flag ZMQ_DONTWAIT set) and the
50 operation would block.
51
52 ENOTSUP
53 The zmq_recvmsg() operation is not supported by this socket type.
54
55 EFSM
56 The zmq_recvmsg() operation cannot be performed on this socket at
57 the moment due to the socket not being in the appropriate state.
58 This error may occur with socket types that switch between several
59 states, such as ZMQ_REP. See the messaging patterns section of
60 zmq_socket(3) for more information.
61
62 ETERM
63 The 0MQ context associated with the specified socket was
64 terminated.
65
66 ENOTSOCK
67 The provided socket was invalid.
68
69 EINTR
70 The operation was interrupted by delivery of a signal before a
71 message was available.
72
73 EFAULT
74 The message passed to the function was invalid.
75
77 Receiving a message from a socket.
78
79 /* Create an empty 0MQ message */
80 zmq_msg_t msg;
81 int rc = zmq_msg_init (&msg);
82 assert (rc == 0);
83 /* Block until a message is available to be received from socket */
84 rc = zmq_recvmsg (socket, &msg, 0);
85 assert (rc != -1);
86 /* Release message */
87 zmq_msg_close (&msg);
88
89 Receiving a multi-part message.
90
91 int more;
92 size_t more_size = sizeof (more);
93 do {
94 /* Create an empty 0MQ message to hold the message part */
95 zmq_msg_t part;
96 int rc = zmq_msg_init (&part);
97 assert (rc == 0);
98 /* Block until a message is available to be received from socket */
99 rc = zmq_recvmsg (socket, &part, 0);
100 assert (rc != -1);
101 /* Determine if more message parts are to follow */
102 rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
103 assert (rc == 0);
104 zmq_msg_close (&part);
105 } while (more);
106
107
109 zmq_recv(3) zmq_send(3) zmq_getsockopt(3) zmq_setsockopt(3)
110 zmq_socket(7) zmq(7)
111
113 This page was written by the 0MQ community. To make a change please
114 read the 0MQ Contribution Policy at
115 http://www.zeromq.org/docs:contributing.
116
117
118
1190MQ 4.3.4 07/23/2022 ZMQ_RECVMSG(3)