ZMQ_DISCONNECT(3)

πŸ’– ZMQ_DISCONNECT(3) πŸ’–

okay bestie, welcome to the 0MQ Manual β€” this one's all about ✨ zmq_disconnect ✨, aka the "we're breaking up (politely)" function. no cap.


🌸 NAME 🌸

zmq_disconnect β€” disconnect a socket from an endpoint πŸ¦‹


✨ SYNOPSIS ✨

int zmq_disconnect (void *socket, const char *endpoint);

πŸ’… DESCRIPTION πŸ’…

so like. the zmq_disconnect() function shall disconnect a socket β€” the one you passed as the socket argument β€” from the endpoint you passed as the endpoint argument. that's it, that's the vibe. πŸ™ˆ

lowkey important: the actual disconnect system call might happen at a later time. not me being fashionably late to the syscall πŸ’€

once you disconnect, a few things go down:

  • the socket will also stop receiving messages originating from this endpoint, periodt. 🚫πŸ“₯
  • the socket will no longer be able to queue outgoing messages to this endpoint.
  • the outgoing message queue associated with the endpoint gets discarded. bye bye πŸ‘‹
  • BUT β€” and this is the iconic plot twist β€” if the socket's linger period is non-zero, libzmq will still attempt to transmit these discarded messages, until the linger period expires. she's persistent, we love that for her. πŸ’–

the endpoint argument is as described in zmq_connect(3) 🫢

⚠️ Note ⚠️ the default setting of ZMQ_LINGER does not discard unsent messages β€” this behaviour may cause the application to block when calling zmq_ctx_term(). for the details, go read zmq_setsockopt(3) and zmq_ctx_term(3). iykyk 😭

🌈 RETURN VALUE 🌈

zmq_disconnect() shall return zero if successful β€” slay. βœ…

otherwise it shall return -1 and set errno to one of the values defined below. not slay. πŸ’€


πŸŽ€ ERRORS πŸŽ€

  • EINVAL β€” the endpoint supplied is invalid. 🚫
  • ETERM β€” the 0MQ context associated with the specified socket was terminated. rip πŸͺ¦
  • ENOTSOCK β€” the provided socket was invalid. bestie that's not a socket 😭
  • ENOENT β€” the provided endpoint is not in use by the socket. who? never met her πŸ™ˆ

🧚 EXAMPLE 🧚

connecting a subscriber socket to an in-process and a TCP transport:

/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_connect (socket, "tcp://server001:5555");
assert (rc == 0);
/* Disconnect from the previously connected endpoint */
rc = zmq_disconnect (socket, "tcp://server001:5555");
assert (rc == 0);

look at that assert after every call. that's main character energy. protect your rc, bestie. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ‘‘ 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. πŸ’œ


and that's the whole page, fr fr. this was ZMQ_DISCONNECT(3) from the 0MQ 4.3.5 era, dated 10/09/2023 β€” literally iconic, no notes. go forth and disconnect responsibly, bestie πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from