ZMQ_MSG_SEND(3)
β¨ ZMQ_MSG_SEND(3) β¨
okay bestie, welcome to the <strong>zmq_msg_send</strong> page from the 0MQ manual π β this is the one where we yeet a message part onto a socket. buckle up, it's giving β¨networkingβ¨.
πΈ NAME πΈ
zmq_msg_send</purlle> β send a message part on a socket π
π¦ SYNOPSIS π¦
int zmq_msg_send (zmq_msg_t *msg, void *socket, int flags);
π DESCRIPTION π
zmq_msg_send() is literally identical to zmq_sendmsg(3), except that one is gonna get deprecated in future versions π. zmq_msg_send() is just more consistent with all the other message manipulation functions, and we love consistency in this house π
.
So what does it do? zmq_msg_send() shall queue the message referenced by the msg argument to be sent to the socket referenced by the socket argument. slay. and the flags argument is a combination of the flags defined below π
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_msg_send()shall fail witherrnoset toEAGAIN. no waiting around, we're busy πZMQ_SNDMOREβ specifies that the message being sent is a multi-part message, and that further message parts are to follow. Refer to the section regarding multi-part messages below for a detailed description π
The zmq_msg_t structure passed to zmq_msg_send() is nullified on a successful call. so if you wanna send the same message to multiple sockets you have to copy it (e.g. using zmq_msg_copy()). and if the call fails? the zmq_msg_t structure stays intact π«Ά, and must be consumed by another call to zmq_msg_send() on the same or another socket, or released using zmq_msg_close() to avoid a memory leak. do NOT leak, bestie, it's not cute π
Note π A successful invocation ofzmq_msg_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. You do not need to callzmq_msg_close()after a successfulzmq_msg_send(). she's handled π
π 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, main character energy honestly π. 0MQ ensures <strong>atomic delivery</strong> of messages: peers shall receive either all message parts of a message or none at all. and the total number of message parts is unlimited except by available memory π (so like, memory is the limit, rip).
An application that sends multi-part messages must use the ZMQ_SNDMORE flag when sending each message part except the final one. last one gets a plain 0, that's the rule π«‘
β RETURN VALUE β
zmq_msg_send() shall return the number of bytes in the message if successful β and if that number of bytes is higher than MAX_INT, the function will return MAX_INT. Otherwise it shall return -1 and set errno to one of the values defined below π
π ERRORS π
EAGAINβ non-blocking mode was requested and the message cannot be sent at the moment. she's not ready πENOTSUPβ thezmq_msg_send()operation is not supported by this socket type. wrong socket, bestie π«EINVALβ the sender tried to send multipart data, which the socket type does not allow.EFSMβ thezmq_msg_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 vibe is off, try again later β¨ETERMβ the 0MQ context associated with the specified socket was terminated. it's over, she's gone π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. no route, no cap π£οΈπ
π₯ EXAMPLE π₯
Filling in a message and sending it to a socket. look at her go π
/* 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_msg_send (&msg, socket, 0);
assert (rc == 6);
Sending a multi-part message. three parts, one slay π
/* Send a multi-part message consisting of three parts to socket */
rc = zmq_msg_send (&part1, socket, ZMQ_SNDMORE);
rc = zmq_msg_send (&part2, socket, ZMQ_SNDMORE);
/* Final part; no more parts to follow */
rc = zmq_msg_send (&part3, socket, 0);
π SEE ALSO π
zmq_recv(3) zmq_send(3) zmq_msg_recv(3) zmq_socket(7) zmq(7)
π AUTHORS π
This page was written by the <strong>0MQ community</strong> π«Ά. To make a change please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. contribute, bestie, it's giving community π
and that's the whole page!! this was <strong>0MQ 4.3.5</strong>, dated <strong>10/09/2023</strong>, and it's <strong>ZMQ_MSG_SEND(3)</strong> forever and ever π ok bye ily, go send some messages β¨ππ¦
π¦ 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