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

NAME

6       zmq_recv - receive a message from a socket
7

SYNOPSIS

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

DESCRIPTION

12       The zmq_recv() function shall receive a message 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 messages available on
16       the specified socket the zmq_recv() function shall block until the
17       request can be satisfied. The flags argument is a combination of the
18       flags defined below:
19
20       ZMQ_NOBLOCK
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_recv() function shall fail with errno set to EAGAIN.
24
25   Multi-part messages
26       A 0MQ message is composed of 1 or more message parts; each message part
27       is an independent zmq_msg_t in its own right. 0MQ ensures atomic
28       delivery of messages; peers shall receive either all message parts of a
29       message or none at all.
30
31       The total number of message parts is unlimited.
32
33       An application wishing to determine if a message is composed of
34       multiple parts does so by retrieving the value of the ZMQ_RCVMORE
35       socket option on the socket it is receiving the message from. If there
36       are no message parts to follow, or if the message is not composed of
37       multiple parts, ZMQ_RCVMORE shall report a value of zero. Otherwise,
38       ZMQ_RCVMORE shall report a value of 1, indicating that more message
39       parts are to follow.
40

RETURN VALUE

42       The zmq_recv() function shall return zero if successful. Otherwise it
43       shall return -1 and set errno to one of the values defined below.
44

ERRORS

46       EAGAIN
47           Non-blocking mode was requested and no messages are available at
48           the moment.
49
50       ENOTSUP
51           The zmq_recv() operation is not supported by this socket type.
52
53       EFSM
54           The zmq_recv() operation cannot be performed on this socket at the
55           moment due to the socket not being in the appropriate state. This
56           error may occur with socket types that switch between several
57           states, such as ZMQ_REP. See the messaging patterns section of
58           zmq_socket(3) for more information.
59
60       ETERM
61           The 0MQ context associated with the specified socket was
62           terminated.
63
64       EFAULT
65           The provided socket was not valid (NULL).
66
67       EINTR
68           The operation was interrupted by delivery of a signal before a
69           message was available.
70

EXAMPLE

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

SEE ALSO

104       zmq_send(3) zmq_getsockopt(3) zmq_socket(7) zmq(7)
105

AUTHORS

107       This 0MQ manual page was written by Martin Sustrik
108       <sustrik@250bpm.com[1]> and Martin Lucina <mato@kotelna.sk[2]>.
109

NOTES

111        1. sustrik@250bpm.com
112           mailto:sustrik@250bpm.com
113
114        2. mato@kotelna.sk
115           mailto:mato@kotelna.sk
116
117
118
1190MQ 2.1.4                         03/30/2011                       ZMQ_RECV(3)
Impressum