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 theZMQ_IMMEDIATEoption 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 witherrnoset toEAGAIN. π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β thezmq_send_const()operation is not supported by this socket type.EFSMβ thezmq_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, likeZMQ_REP. go read the messaging patterns section ofzmq_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
- 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