ZMQ_MSG_RECV(3)
π ZMQ_MSG_RECV(3) π
okay bestie, gather round, because this is the 0MQ Manual page for zmq_msg_recv, and it's genuinely one of the most important little functions you'll ever meet. no cap.
β¨ NAME β¨
zmq_msg_recv β receive a message part from a socket π«Ά
β¨ SYNOPSIS β¨
int zmq_msg_recv (zmq_msg_t *msg, void *socket, int flags);
πΈ DESCRIPTION πΈ
so like. zmq_msg_recv() is identical to zmq_recvmsg(3), except that zmq_recvmsg(3) is gonna get deprecated in future versions π β zmq_msg_recv() is just way more consistent with the other message manipulation functions, and honestly? she ate. π
What zmq_msg_recv() does: she receives a message part from the socket referenced by the socket argument, and stores it in the message referenced by the msg argument. and here's the important bit β any content that was previously stored in msg gets properly deallocated. no leaks, we don't do that here. β¨
If there are no message parts available on the specified socket, zmq_msg_recv() shall block until the request can be satisfied. she will literally just sit there and wait for you. iconic patience tbh. π§
The flags argument is a combination of the flags defined below:
ZMQ_DONTWAITβ says the operation should be performed in non-blocking mode. so if there are no messages available on the specified socket,zmq_msg_recv()shall fail witherrnoset toEAGAIN. she's not waiting around, she has places to be π
π¦ Multi-part messages π¦
A 0MQ message is composed of 1 or more message parts. each message part is an independent zmq_msg_t in its own right, like her own little main character moment. π
0MQ ensures atomic delivery of messages: peers shall receive either all message parts of a message or none at all. it's all or nothing, periodt. π
The total number of message parts is unlimited except by available memory. go wild bestie, your RAM is the only limit π
An application that processes multi-part messages must use the ZMQ_RCVMORE zmq_getsockopt(3) option after calling zmq_msg_recv() to determine if there are further parts to receive. like, you gotta check. don't just assume. π₯
β RETURN VALUE β
The zmq_msg_recv() function shall return the number of bytes in the message if successful. π
Otherwise it shall return -1 and set errno to one of the values defined below. sad girl hours π
π ERRORS π
EAGAINβ Either the timeout set via the socket-optionZMQ_RCVTIMEO(seezmq_setsockopt(3)) has been reached (flagZMQ_DONTWAITnot set) without being able to read a message from the socket, or there are no messages available at the moment (flagZMQ_DONTWAITset) and the operation would block.ENOTSUPβ Thezmq_msg_recv()operation is not supported by this socket type. wrong socket for this vibe, bestie.EFSMβ Thezmq_msg_recv()operation cannot be performed on this socket at the moment due to the socket not being in the appropriate state. this error may occur with socket types that switch between several states, such asZMQ_REP. see the messaging patterns section ofzmq_socket(3)for more information. she's just not in the right headspace rn πETERNβ wait, no, it'sETERMβ the 0MQ context associated with the specified socket was terminated. rip πͺ¦ENOTSOCKβ The provided socket was invalid. that's not a socket, babe πEINTRβ The operation was interrupted by delivery of a signal before a message was available. rude of that signal tbh.EFAULTβ The message passed to the function was invalid.
π EXAMPLE π
Receiving a message from a socket. π«Ά
/* Create an empty 0MQ message */
zmq_msg_t msg;
int rc = zmq_msg_init (&msg);
assert (rc == 0);
/* Block until a message is available to be received from socket */
rc = zmq_msg_recv (&msg, socket, 0);
assert (rc != -1);
/* Release message */
zmq_msg_close (&msg);
Receiving a multi-part message. this one's the full meal β¨
int more;
size_t more_size = sizeof (more);
do {
/* Create an empty 0MQ message to hold the message part */
zmq_msg_t part;
int rc = zmq_msg_init (&part);
assert (rc == 0);
/* Block until a message is available to be received from socket */
rc = zmq_msg_recv (&part, socket, 0);
assert (rc != -1);
/* Determine if more message parts are to follow */
rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
assert (rc == 0);
zmq_msg_close (&part);
} while (more);
π SEE ALSO π
zmq_recv(3) zmq_send(3) zmq_msg_send(3) zmq_getsockopt(3) zmq_setsockopt(3) zmq_socket(7) zmq(7)
go read those next, i'm literally obsessed with this whole family π
π AUTHORS π
This page was written by the 0MQ community. To make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. bestie, if you wanna contribute, the door is open and we'd love to have you π«Ά
ok that's the whole page, nothing skipped, nothing invented, every flag and every errno is right there π
and that's a wrap! this was ZMQ_MSG_RECV(3) from the 0MQ Manual, shipped with 0MQ 4.3.5 and dated 10/09/2023. slay, stay hydrated, and always check ZMQ_RCVMORE πΈβ¨π¦
π¦ where this page comes from
- epel 10: zeromq 4.3.5-18.el10_0 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 43: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- fedora 44: zeromq 4.3.5-22.fc43 Β· MPL-2.0 AND BSD-3-Clause AND MIT
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- opensuse-leap 16.0: zeromq-devel 4.3.5-160000.2.2 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms