NNG_LISTEN(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– NNG_LISTEN πŸ’–

okay bestie, so this is nng_listen(3) from the NNG Reference Manual, and it's literally the "start accepting new friends" function. let's get into it 🫢


✨ NAME ✨

nng_listen β€” create and start listener

like, it makes a listener and turns it on. that's the whole vibe. periodt.


πŸ“œ SYNOPSIS πŸ“œ

#include <nng/nng.h>

int nng_listen(nng_socket s, const char *url, nng_listener *lp, int flags);

🌸 DESCRIPTION 🌸

so nng_listen() does a LOT in one call and honestly? iconic behavior. it creates a brand-new, freshly initialized nng_listener object, ties it to the socket s, sets it up to listen at the address you gave it in url, and then immediately starts it. boom. done. no takebacks.

and if lp is not NULL? then the newly created listener gets stored at the address that lp points to, so you can hang onto it for later. cute.

listen up (pun absolutely intended): listeners are the ones that accept connections coming in from remote dialers. when a connection shows up, it usually results in an nng_pipe object being created and attached to socket s. and here's the slay part β€” unlike dialers, listeners can generally create many pipes, and those pipes can all be open at the same time. it's giving main character with a whole entourage. πŸ‘‘

and flags? it's ignored. completely. but it's reserved for future use, so don't get any ideas, it's just sitting there looking pretty. πŸ’…

Tip πŸ’‘ it's convenient to think of listeners as servers, but the relationship between listener and dialer is orthogonal to any server or client status that might be attached to a given protocol. so like, a req socket might have associated dialers, but it might also have associated listeners. it could even have some of each at the same time! multitasking queen fr fr. 🌈

and because the listener starts immediately, it's generally not possible to apply extra configuration afterwards. so if you need that? bestie, go use nng_listener_create() and nng_listener_start() instead. that's the whole point of those.

once it's up, the created listener will keep accepting new connections and associating their pipes with the socket β€” until either the listener itself or the socket s gets closed. that's it, that's the lifecycle. πŸ¦‹


πŸŽ€ RETURN VALUES πŸŽ€

this function returns 0 on success, and non-zero otherwise. that's the whole report card.


πŸ’€ ERRORS πŸ’€

  • NNG_EADDRINUSE β€” the address specified by url is already in use. somebody beat you to it, awkward.
  • NNG_EADDRINVAL β€” an invalid url was specified. that url is not it. 😭
  • NNG_ECLOSED β€” the socket s is not open. not me trying to listen on a closed socket…
  • NNG_EINVAL β€” an invalid set of flags or an invalid url was specified. (yep, flags is ignored, but it can still be invalid, don't ask, that's just how it is.)
  • NNG_ENOMEM β€” insufficient memory is available. the machine said "no thoughts, head empty." πŸ’€

πŸ‘€ SEE ALSO πŸ‘€

nng_dial(3), nng_listener_close(3), nng_listener_create(3), nng_listener_start(3), nng_strerror(3), nng_listener(5), nng(7)


that's the whole page bestie, no cap, every flag and error accounted for 🧚

mwah πŸ’‹ β€” this was NNG_LISTEN(3) from the NNG Reference Manual, dated 2026-06-30. go start a listener, you got this. πŸŽ€βœ¨

πŸ“¦ where this page comes from