ZMQ_RECVMSG(3)
π ZMQ_RECVMSG(3) β the 0MQ manual, but make it make sense
okay bestie, pull up a chair, we're learning zmq_recvmsg today and honestly? it's giving main character energy for anyone doing message passing. this is the page from the 0MQ manual, so like, you're in the right place. π
β¨ NAME β¨
zmq_recvmsg β receive a message part from a socket π«Ά
β¨ SYNOPSIS β¨
int zmq_recvmsg (void *socket, zmq_msg_t *msg, int flags);
β¨ DESCRIPTION β¨
so basically, zmq_recvmsg() receives a message part from the socket that socket points at, and it stores that part in the message that msg points at. π
and listen β anything that was already chillin' inside msg beforehand? it gets properly deallocated. no leaks, no leftovers, we clean up after ourselves in this house.
if there are literally no message parts available on that socket yet, zmq_recvmsg() shall block until the request can be satisfied. it's patient like that. it'll just wait. π§
the flags argument is a combination of the flags defined below:
ZMQ_DONTWAITβ says the operation should run in non-blocking mode. so if there are no messages available on the specified socket,zmq_recvmsg()shall fail witherrnoset toEAGAIN. no waiting around, we move on. β¨
β οΈ note: this API method is deprecated in favor of zmq_msg_recv(3). it still works, but like, the new one is the moment. π
πΈ 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 β they're individuals, not a group project. π
0MQ ensures atomic delivery of messages: peers shall receive either all message parts of a message or none at all. no half-delivered situationships here, periodt. π
the total number of message parts is unlimited except by available memory. yes bestie, unlimited. go feral.
if your application processes multi-part messages, you must use the ZMQ_RCVMORE zmq_getsockopt(3) option after calling zmq_recvmsg() to figure out if there are further parts to receive. otherwise you'll be standing there wondering if that was it, and that's embarrassing. π
β¨ RETURN VALUE β¨
the zmq_recvmsg() function shall return the number of bytes in the message if it succeeds. slay. π
otherwise it shall return -1 and set errno to one of the values defined below. not slay, but informative.
β¨ ERRORS β¨
EAGAINβ either the timeout set via the socket-optionZMQ_RCVTIMEO(seezmq_setsockopt(3)) has been reached (with flagZMQ_DONTWAITnot set) without being able to read a message from the socket, or there are no messages available at the moment (with flagZMQ_DONTWAITset) and the operation would block. either way: nothing to read right now, bestie. πENOTSUPβ thezmq_recvmsg()operation is not supported by this socket type. this socket said "not my job." πEFSMβ thezmq_recvmsg()operation cannot be performed on this socket at the moment because the socket is not 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 info. it's a timing thing, it's not you. π¦ETERMβ the 0MQ context associated with the specified socket was terminated. it's gone, babes. πENOTSOCKβ the provided socket was invalid. that's not a socket, that's a stranger. πEINTRβ the operation was interrupted by delivery of a signal before a message was available. rude of that signal, honestly.EFAULTβ the message passed to the function was invalid. π (derogatory)
β¨ 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_recvmsg (socket, &msg, 0);
assert (rc != -1);
/* Release message */
zmq_msg_close (&msg);
receiving a multi-part message. πβ¨
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_recvmsg (socket, &part, 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_getsockopt(3) zmq_setsockopt(3) zmq_socket(7) zmq(7) β go read these too, they're the friend group. π«Ά
β¨ AUTHORS β¨
this page was written by the 0MQ community. if you wanna make a change, please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. they'd love to have you. π
and that's the whole page, bestie!! this was the 0MQ 4.3.5 version, dated 10/09/2023, and honestly it ate. go forth and receive your messages responsibly. mwah π β¨
π¦ 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