ZMQ_CLOSE(3)

πŸ’… ZMQ_CLOSE β€” bestie, it's time to let the socket go πŸ’…

okay so this is the zmq_close(3) page from the 0MQ manual, and it's genuinely so important, like the main character of cleanup functions. 🫢


✨ NAME ✨

zmq_close β€” close a 0MQ socket, bestie. that's it. that's the whole job. 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

int zmq_close (void *socket);

πŸ‘‘ DESCRIPTION πŸ‘‘

The zmq_close() function shall destroy the socket referenced by the socket argument. gone. deleted. no more socket for you. πŸ’€

Any outstanding messages that were physically received from the network but haven't been received by your app yet with zmq_recv() shall be discarded. like, they're just gone, poof, no cap. 😭

Now the messy part β€” what happens to messages you sent with zmq_send() that haven't been physically transferred to the network yet? That depends entirely on the value of the ZMQ_LINGER socket option for that specific socket. so it's giving "it depends", which is so real of it. ✨

zmq_close() must be called exactly once for each socket. one socket, one close. the way that it has to be exactly once is so serious.

  • if you never call it? zmq_ctx_term() will block forever. like forever forever. that's not a vibe. 🚨
  • if you call it multiple times for the same socket, or if socket doesn't actually point to a socket? the behaviour is undefined. we don't do that here, bestie. πŸ™ˆ
Note πŸŽ€ β€” the default setting of ZMQ_LINGER does not discard unsent messages. this behaviour may cause your application to block when calling zmq_ctx_term(). for the full tea, go read zmq_setsockopt(3) and zmq_ctx_term(3).
Note ⭐ β€” this API will complete asynchronously, so not everything will be deallocated after it returns. lowkey important! see above for all the details about linger. πŸ‘‘

🌈 RETURN VALUE 🌈

The zmq_close() function shall return zero if successful. iconic. flawless. πŸ’–

Otherwise it shall return -1 and set errno to one of the values listed below. so if you see a -1, go check errno, fr fr.


πŸ”₯ ERRORS πŸ”₯

  • ENOTSOCK β€” the provided socket was NULL. yeah, you passed it nothing. it's giving empty-handed. 😭

πŸ’œ 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, bestie!! this was 0MQ 4.3.5, dated 10/09/2023, and it's the ZMQ_CLOSE(3) manual page β€” now go close your sockets exactly once and slay πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from