ZMQ_SEND(3)
π ZMQ_SEND(3) β bestie, we're sending a message part π
okay so this is the 0MQ Manual page for zmq_send, and honestly? it's lowkey the most important function in the whole socket era. sit down, grab a boba, we're doing this π§β¨
β¨ NAME β¨
zmq_send β send a message part on a socket. that's it, that's the vibe π¦
πΈ SYNOPSIS πΈ
int zmq_send (void *socket, const void *buf, size_t len, int flags);
look at her. four args. iconic. π
π DESCRIPTION π
The zmq_send() function shall queue a message created from the buffer referenced by the buf and len arguments. so like, you hand it a chunk of memory and it goes "okay bestie, I got it from here" πββοΈ
The flags argument is a combination of the flags defined below β mix and match, it's giving build-your-own-adventure:
ZMQ_DONTWAITβ for socket types (DEALER,PUSH) that block (either with theZMQ_IMMEDIATEoption set and no peer available, or all peers having full high-water mark), this specifies that the operation should be performed in non-blocking mode. if the message cannot be queued on the socket,zmq_send()shall fail witherrnoset toEAGAIN. tl;dr: no waiting around, it's giving "I'm busy, try later" πZMQ_SNDMOREβ specifies that the message being sent is a multi-part message, and that further message parts are to follow. see the multi-part messages section below for the full tea π«
Note π A successful invocation of zmq_send() does not indicate that the message has been transmitted to the network β only that it has been queued on the socket and 0MQ has assumed responsibility for the message. so like... it's not at the party yet, it's in the group chat saying "omw" πββοΈ
π Multi-part messages π
A 0MQ message is composed of 1 or more message parts. 0MQ ensures atomic delivery of messages: peers shall receive either all message parts of a message or none at all. no half-sent situationships here, periodt π
The total number of message parts is unlimited except by available memory. (yes bestie, unlimited. go feral, but like, RAM exists π)
An application that sends multi-part messages must use the ZMQ_SNDMORE flag when sending each message part except the final one. that last one? raw. no flag. naked. free. π¦
β RETURN VALUE β
The zmq_send() 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. so if you get a number back, slay. if you get -1, read the next section, bestie π
π ERRORS π
EAGAINβ non-blocking mode was requested and the message cannot be sent at the moment. she's not available rn πENOTSUPβ thezmq_send()operation is not supported by this socket type. wrong socket, wrong vibe πEINVALβ the sender tried to send multipart data, which the socket type does not allow. you tried to be extra and the socket said no βEFSMβ thezmq_send()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. the socket is going through something, give her a minute π§ETERMβ the 0MQ context associated with the specified socket was terminated. rip context, she's gone π»ENOTSOCKβ the provided socket was invalid. bestie that's not even a socket πEINTRβ the operation was interrupted by delivery of a signal before the message was sent. rude of that signal tbh β‘EHOSTUNREACHβ the message cannot be routed. no route, no delivery, no cap π«
π₯ EXAMPLE π₯
Sending a multi-part message. look at this little three-parter, she's adorable:
/* Send a multi-part message consisting of three parts to socket */
rc = zmq_send (socket, "ABC", 3, ZMQ_SNDMORE);
assert (rc == 3);
rc = zmq_send (socket, "DEFGH", 5, ZMQ_SNDMORE);
assert (rc == 5);
/* Final part; no more parts to follow */
rc = zmq_send (socket, "JK", 2, 0);
assert (rc == 2);
see how the last one has no ZMQ_SNDMORE? that's the closer. main character energy fr fr π
π SEE ALSO π
zmq_send_const(3) Β· zmq_recv(3) Β· zmq_socket(7) Β· zmq(7) β go read these next, they're all part of the friend group π«Ά
π 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. (yes, that's a real URL, copy it exactly bestie, don't be cute with it π)
and that's the whole page!! this was 0MQ 4.3.5, dated 10/09/2023, and honestly she ate π β¨ no cap, go queue some messages, you're gonna do great ππ¦π
π¦ 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