ZMQ_RECV(3)
β¨ NAME β¨
zmq_recv β bestie, this is the one that receives a message part from a socket π like it literally pulls a message part right out of a socket, slay
πΈ SYNOPSIS πΈ
int zmq_recv (void *socket, void *buf, size_t len, int flags);
π DESCRIPTION π
okay so here's the tea β the zmq_recv() function is gonna receive a message from the socket referenced by the socket argument and stash it in the buffer that buf points at. and bestie, listen β any bytes exceeding the length specified by the len argument shall be truncated. yes literally cut off. bye βοΈ
and if there's no messages available on the specified socket, the zmq_recv() function is gonna block until the request can be satisfied π΄ like it just sits there waiting, main character patience energy.
the flags argument is a combination of the flags defined below π oh and btw: The buf argument may be null if len is zero. no cap.
ZMQ_DONTWAITβ this one says the operation should be performed in non-blocking mode. so if there are no messages available on the specified socket, thenzmq_recv()shall fail witherrnoset toEAGAIN. it's giving "i'm not waiting around for you" π
π« Multi-part messages π«
so a 0MQ message is composed of 1 or more message parts. and 0MQ ensures atomic delivery of messages: peers shall receive either all message parts of a message or none at all β all or nothing, periodt π and the total number of message parts is unlimited except by available memory. unlimited!! well. as long as ur RAM is behaving.
an application that processes multi-part messages must use the ZMQ_RCVMORE zmq_getsockopt(3) option after calling zmq_recv() to determine if there are further parts to receive. don't skip this step bestie i'm begging π
π₯ RETURN VALUE π₯
the zmq_recv() function shall return number of bytes in the message if successful. and heads up β the value can exceed the value of the len parameter in case the message was truncated. yes fr fr, it can be bigger than len, that's not a typo, that's just how truncation works π«
If not successful the function shall return -1 and set errno to one of the values defined below.
π 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. two whole situations, one error code, iconic behavior honestly.ENOTSUPβ Thezmq_recv()operation is not supported by this socket type. this socket said "not my job" πEFSMβ Thezmq_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. it's giving "wrong place wrong time" πETERMβ The 0MQ context associated with the specified socket was terminated. rip the context, gone, deceased πENOTSOCKβ The provided socket was invalid. bestie that's not even a socket, what is that π§EINTRβ The operation was interrupted by delivery of a signal before a message was available. a signal rudely cut in line β
π EXAMPLE π
Receiving a message from a socket. look at this little moment:
char buf [256];
nbytes = zmq_recv (socket, buf, 256, 0);
assert (nbytes != -1);
so clean. so demure. so mindful β¨
π¦ SEE ALSO π¦
zmq_send(3) zmq_getsockopt(3) zmq_setsockopt(3) zmq_socket(7) zmq(7)
π AUTHORS π
This page was written by the 0MQ community. and if u wanna make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. the community ate and left no crumbs π«Ά
okay that's the whole page bestie, go forth and receive ur messages π this was brought to u by 0MQ 4.3.5, dated 10/09/2023 β mwah, catch u later, don't forget 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