NN_TERM(3)

πŸ“¦
version 1.2.2 Β· 5 versions
, in fedora 44

πŸ’– NN_TERM(3) πŸ’–

okay bestie, gather round, because this is the nanomsg nn_term page β€” manual section 3, from nanomsg 1.2.2 β€” and it's literally the "everybody get out of the pool" function 🫢


✨ NAME ✨

nn_term β€” notify all sockets about process termination


🌸 SYNOPSIS 🌸

#include <nanomsg/nn.h>

void nn_term (void);

like. that's it. no args. no return value. she just does things πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe: shutting down multi-threaded programs is lowkey a nightmare, and nanomsg said "not on my watch." Enter nn_term(), the icon herself. She closes all open sockets and releases all related resources. Boom. Cleaned up. Main character energy, no cap.

Now the spicy part πŸ”₯ If a socket is blocked inside a blocking function β€” think nn_recv(3) β€” it will get unblocked, and an EBADF error gets returned to you. And not just that one time, bestie: subsequent calls on such sockets will also return EBADF. She's done. She's not coming back. Respect it.

And if you try to open a new socket with nn_socket(3) after termination? Yeah no. You get an ETERM error. The door is closed, the lights are off, the party is over πŸ™ˆ

One more thing, and this one's important if you're out here polling: if you're waiting for NN_SNDFD or NN_RCVFD using a polling function like poll() or select(), that call will unblock with both NN_SNDFD and NN_RCVFD signaled. Both of them. Not one. Both. It's giving "we're ALL leaving together" ✨


πŸŽ€ EXAMPLE πŸŽ€

s = nn_socket (AF_SP, NN_PAIR);
nn_term ();
rc = nn_send (s, "ABC", 3, 0);
assert (rc == -1 && errno == EBADF);

see how nn_send just fully gives up after the nn_term()? rc == -1 and errno == EBADF. exactly as promised, periodt πŸ’―


⭐ SEE ALSO ⭐

go read those too, iykyk 🧚


πŸ‘‘ AUTHORS πŸ‘‘

This masterpiece was brought to you by:

  • Martin Sustrik <sustrik@250bpm.com>
  • Garrett D’Amore <garrett@damore.org>

absolute legends, fr fr 🌈


and that's the whole page, bestie β€” this version dropped on 2026-01-16 and lives in the nanomsg 1.2.2 era, so if you're reading it, you're reading the real thing. now go close your sockets properly, slay πŸ’…βœ¨

πŸ“¦ where this page comes from