NNG_LISTEN(3)
π 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 byurlis already in use. somebody beat you to it, awkward.NNG_EADDRINVALβ an invalidurlwas specified. that url is not it. πNNG_ECLOSEDβ the socketsis not open. not me trying to listen on a closed socketβ¦NNG_EINVALβ an invalid set offlagsor an invalidurlwas specified. (yep,flagsis 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
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms