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

NAME

6       zmq_msg_recv - receive a message part from a socket
7

SYNOPSIS

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

DESCRIPTION

12       The zmq_msg_recv() function is identical to zmq_recvmsg(3), which shall
13       be deprecated in future versions. zmq_msg_recv() is more consistent
14       with other message manipulation functions.
15
16       The zmq_msg_recv() function shall receive a message part from the
17       socket referenced by the socket argument and store it in the message
18       referenced by the msg argument. Any content previously stored in msg
19       shall be properly deallocated. If there are no message parts available
20       on the specified socket the zmq_msg_recv() function shall block until
21       the request can be satisfied. The flags argument is a combination of
22       the flags defined below:
23
24       ZMQ_DONTWAIT
25           Specifies that the operation should be performed in non-blocking
26           mode. If there are no messages available on the specified socket,
27           the zmq_msg_recv() function shall fail with errno set to EAGAIN.
28
29   Multi-part messages
30       A 0MQ message is composed of 1 or more message parts. Each message part
31       is an independent zmq_msg_t in its own right. 0MQ ensures atomic
32       delivery of messages: peers shall receive either all message parts of a
33       message or none at all. The total number of message parts is unlimited
34       except by available memory.
35
36       An application that processes multi-part messages must use the
37       ZMQ_RCVMORE zmq_getsockopt(3) option after calling zmq_msg_recv() to
38       determine if there are further parts to receive.
39

RETURN VALUE

41       The zmq_msg_recv() function shall return number of bytes in the message
42       if successful. Otherwise it shall return -1 and set errno to one of the
43       values defined below.
44

ERRORS

46       EAGAIN
47           Either the timeout set via the socket-option ZMQ_RCVTIMEO (see
48           zmq_setsockopt(3)) has been reached (flag ZMQ_DONTWAIT not set)
49           without being able to read a message from the socket or there are
50           no messages available at the moment (flag ZMQ_DONTWAIT set) and the
51           operation would block.
52
53       ENOTSUP
54           The zmq_msg_recv() operation is not supported by this socket type.
55
56       EFSM
57           The zmq_msg_recv() operation cannot be performed on this socket at
58           the moment due to the socket not being in the appropriate state.
59           This error may occur with socket types that switch between several
60           states, such as ZMQ_REP. See the messaging patterns section of
61           zmq_socket(3) for more information.
62
63       ETERM
64           The 0MQ context associated with the specified socket was
65           terminated.
66
67       ENOTSOCK
68           The provided socket was invalid.
69
70       EINTR
71           The operation was interrupted by delivery of a signal before a
72           message was available.
73
74       EFAULT
75           The message passed to the function was invalid.
76

EXAMPLE

78       Receiving a message from a socket.
79
80           /* Create an empty 0MQ message */
81           zmq_msg_t msg;
82           int rc = zmq_msg_init (&msg);
83           assert (rc == 0);
84           /* Block until a message is available to be received from socket */
85           rc = zmq_msg_recv (&msg, socket, 0);
86           assert (rc != -1);
87           /* Release message */
88           zmq_msg_close (&msg);
89
90       Receiving a multi-part message.
91
92           int more;
93           size_t more_size = sizeof (more);
94           do {
95               /* Create an empty 0MQ message to hold the message part */
96               zmq_msg_t part;
97               int rc = zmq_msg_init (&part);
98               assert (rc == 0);
99               /* Block until a message is available to be received from socket */
100               rc = zmq_msg_recv (&part, socket, 0);
101               assert (rc != -1);
102               /* Determine if more message parts are to follow */
103               rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
104               assert (rc == 0);
105               zmq_msg_close (&part);
106           } while (more);
107
108

SEE ALSO

110       zmq_recv(3) zmq_send(3) zmq_msg_send(3) zmq_getsockopt(3)
111       zmq_setsockopt(3) zmq_socket(7) zmq(7)
112

AUTHORS

114       This page was written by the 0MQ community. To make a change please
115       read the 0MQ Contribution Policy at
116       http://www.zeromq.org/docs:contributing.
117
118
119
1200MQ 4.3.4                         07/23/2021                   ZMQ_MSG_RECV(3)
Impressum