ZMQ_SEND_CONST(3)

✨ ZMQ_SEND_CONST ✨

okay bestie, welcome to the 0MQ Manual πŸ’– this is the page for zmq_send_const, and it's genuinely one of the most iconic little functions in the whole socket world. buckle up πŸŽ€


🌸 NAME 🌸

zmq_send_const β€” send a constant-memory message part on a socket


πŸ¦‹ SYNOPSIS πŸ¦‹

int zmq_send_const (void *socket, const void *buf, size_t len, int flags);

πŸ’… DESCRIPTION πŸ’…

so the way that zmq_send_const() works is: it queues up a message made from the buffer that buf points at, with length len. and here's the tea β€” that message buffer is assumed to be constant-memory, which means 0MQ will not copy it and will not deallocate it in any way. it just... trusts you with it. no cap. πŸ”₯

the flags argument is a combo of the flags defined below:

  • ZMQ_DONTWAIT β€” for socket types (DEALER, PUSH) that block (either because the ZMQ_IMMEDIATE option is set and no peer is available, or because all peers have 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_send_const() shall fail with errno set to EAGAIN. πŸ™ˆ
  • ZMQ_SNDMORE β€” says that the message you're sending is a multi-part message and that more message parts are coming after it. scroll down to the multi-part messages section for the full rundown. πŸ‘‘
Note πŸ“Œ a successful call to zmq_send_const() does not mean the message made it to the network, bestie. it only means it got queued on the socket and 0MQ has now taken responsibility for the message. that's it. that's the whole vibe check. 😭

🌈 Multi-part messages 🌈

a 0MQ message is made of 1 or more message parts. 0MQ guarantees atomic delivery of messages: peers shall receive either all the message parts of a message, or none at all. and the total number of message parts? unlimited, except by available memory. slay. πŸ’€

an application that sends multi-part messages must use the ZMQ_SNDMORE flag when sending every message part except the final one. periodt.


⭐ RETURN VALUE ⭐

if it works, zmq_send_const() returns the number of bytes in the message. otherwise it returns -1 and sets errno to one of the values listed below. simple as that 🫢


😭 ERRORS 😭

  • EAGAIN β€” non-blocking mode was requested and the message cannot be sent at the moment.
  • ENOTSUP β€” the zmq_send_const() operation is not supported by this socket type.
  • EFSM β€” the zmq_send_const() operation cannot be performed on this socket at the moment because the socket is not in the appropriate state. this one can happen with socket types that switch between several states, like ZMQ_REP. go read the messaging patterns section of zmq_socket(3) for more info.
  • 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.
  • EHOSTUNREACH β€” the message cannot be routed.

πŸŽ€ EXAMPLE πŸŽ€

sending a multi-part message. iconic behaviour, honestly.

/* Send a multi-part message consisting of three parts to socket */
rc = zmq_send_const (socket, "ABC", 3, ZMQ_SNDMORE);
assert (rc == 3);
rc = zmq_send_const (socket, "DEFGH", 5, ZMQ_SNDMORE);
assert (rc == 5);
/* Final part; no more parts to follow */
rc = zmq_send_const (socket, "JK", 2, 0);
assert (rc == 2);

🧚 SEE ALSO 🧚

zmq_send(3) zmq_recv(3) zmq_socket(7) zmq(7)


πŸ’œ AUTHORS πŸ’œ

this page was written by the 0MQ community. if you wanna make a change, please go read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. they'd love that for you. 🌸


and that's the whole page, bestie πŸ’– this was 0MQ 4.3.5, dated 10/09/2023, and it's giving main character energy from start to finish. go forth and queue those constant-memory messages. mwah. πŸ’…βœ¨

πŸ“¦ where this page comes from