ZMQ_SENDMSG(3)
π ZMQ_SENDMSG(3) β the 0MQ manual, but make it cute
okay bestie, gather round π«Ά this is zmq_sendmsg, straight out of the 0MQ Manual (yes the 3 in the corner means it's a library function page, iykyk). Let's get into it.
β¨ NAME β¨
zmq_sendmsg β send a message part on a socket π
πΈ SYNOPSIS πΈ
int zmq_sendmsg (void *socket, zmq_msg_t *msg, int flags);
π DESCRIPTION π
So zmq_sendmsg() shall queue up the message that msg is pointing at, and it gets sent to the socket that socket is pointing at. Simple. Iconic. No cap.
The flags argument is literally just a combination of the flags we're about to define below, and bestie, there are exactly two of them:
ZMQ_DONTWAITβ for socket types (DEALER,PUSH) that block (either whenZMQ_IMMEDIATEoption is set and there's no peer available, or when all peers are sitting at a full high-water mark), this says: do it in non-blocking mode, please. And if the message can't be queued on the socket?zmq_sendmsg()shall fail witherrnoset toEAGAIN. Bye. πZMQ_SNDMOREβ this says the message you're sending is a multi-part message and there are more parts coming. Scroll down to the multi-part messages section below for the whole tea.
The zmq_msg_t structure you pass to zmq_sendmsg() gets nullified during the call. Like, it's gone, girl. So if you want to send that same message to multiple sockets, you have to copy it first (e.g. using zmq_msg_copy()). Don't skip this step. π
Note β a successful invocation of zmq_sendmsg() does not mean the message has been transmitted to the network. It only means it's been queued on the socket and 0MQ has assumed responsibility for the message. It's a "we got it from here" situation. π
Note β this API method is deprecated in favor of zmq_msg_send(3). She's serving but she's retired, fr fr. π
π¦ Multi-part messages π¦
A 0MQ message is composed of 1 or more message parts. Every single message part is an independent zmq_msg_t in its own right β main character energy, each one.
0MQ ensures atomic delivery of messages: peers shall receive either all message parts of a message or none at all. Periodt. The total number of message parts is unlimited except by available memory (so, like, limited by your RAM, not by us π).
An application that sends multi-part messages must use the ZMQ_SNDMORE flag when sending each message part except the final one. Miss that and the whole vibe collapses. π
β RETURN VALUE β
The zmq_sendmsg() 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. She either slays or she flops, no in-between. π
π₯ ERRORS π₯
EAGAINβ non-blocking mode was requested and the message cannot be sent at the moment.ENOTSUPβ thezmq_sendmsg()operation is not supported by this socket type.EINVALβ the sender tried to send multipart data, which the socket type does not allow.EFSMβ thezmq_sendmsg()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.ETERMβ the 0MQ context associated with the specified socket was terminated.ENOTSOCKβ the provided socket was invalid.EINTRβ the operation was interrupted by delivery of a signal before the message was sent.EFAULTβ invalid message.EHOSTUNREACHβ the message cannot be routed.
π EXAMPLE π
Filling in a message and sending it to a socket. Look how tidy:
/* Create a new message, allocating 6 bytes for message content */
zmq_msg_t msg;
int rc = zmq_msg_init_size (&msg, 6);
assert (rc == 0);
/* Fill in message content with 'AAAAAA' */
memset (zmq_msg_data (&msg), 'A', 6);
/* Send the message to the socket */
rc = zmq_sendmsg (socket, &msg, 0);
assert (rc == 6);
Sending a multi-part message. Three parts, one glow-up:
/* Send a multi-part message consisting of three parts to socket */
rc = zmq_sendmsg (socket, &part1, ZMQ_SNDMORE);
rc = zmq_sendmsg (socket, &part2, ZMQ_SNDMORE);
/* Final part; no more parts to follow */
rc = zmq_sendmsg (socket, &part3, 0);
π SEE ALSO π
zmq_recv(3) zmq_socket(7) zmq(7)
π 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.
and that's the whole page, bestie π«Ά this was 0MQ 4.3.5, dated 10/09/2023 β go forth and send responsibly β¨π πΈ
π¦ 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