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 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_send() shall fail with errno set to EAGAIN. 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 β€” the zmq_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 β€” the zmq_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 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