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 the ZMQ_IMMEDIATE option 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 with errno set to EAGAIN. 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 of zmq_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 call zmq_msg_close() after a successful zmq_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 β€” the zmq_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 β€” the zmq_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 as ZMQ_REP. See the messaging patterns section of zmq_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