NN_POLL(3compat)
π NN_POLL(3compat) β the NNG Reference Manual, bestie edition β¨
okay so you found nn_poll in the NNG Reference Manual and you're like "what is this legacy situation" β don't worry, I got you π«Ά
πΈ NAME πΈ
nn_poll β poll sockets (compatible API). that's it, that's the vibe. it's the compatibility-flavoured poll π
β¨ SYNOPSIS β¨
#include <nanomsg/nn.h>
#define NN_POLLIN 1
#define NN_POLLOUT 2
struct nn_pollfd {
int fd;
uint16_t events;
uint16_t revents;
};
int nn_poll(struct nn_pollfd *pfds, int npfd, int timeout);
like, literally copy that struct exactly, bestie, don't be creative with it π
π¦ DESCRIPTION π¦
nn_poll() polls a whole group of sockets to see who's ready to send and who's ready to receive. very "who's up, who's not" energy π
Note β this function is here for API compatibility with legacy libnanomsg. consider using the relevant modern API instead. fr fr, this is the nostalgia tour, not the main event π
you pass in pfds, the array of sockets to poll β the manpage calls it nfds sockets in the prose while the argument is literally npfd, and honestly? we love a little inconsistency, iykyk π. each member of that array gets set up with:
fdβ set it to the socket πeventsβ set it to a mask that can contain either or both ofNN_POLLINandNN_POLLOUTβ
and what do those flags mean?
NN_POLLINβ the socket is ready for receiving without blocking (meaning: a message is available on the socket, come get it bestie π)NN_POLLOUTβ the socket is ready for sending without blocking π
on success, the function returns the number of updates to the revents field of each member of the pfds array, setting it to show whether the requested status is true or not. slay β¨
Note βreventswill only have a flag set if the corresponding flag was ALSO set in theeventsfield. no sneaky extra flags, that's the rule π
now the timeout field, and this is the part where people get confused, so focus π§
- if
timeoutis positive, the function waits up to that many milliseconds. if none of the requested events happens before the timeout hits, the function returns-1and sets the error toETIMEDOUTπ - if
timeoutis zero, the function returns immediately, right after updating the current status of the sockets. instant. no waiting. main character speed π₯ - if
timeoutis-1, the function waits forever, or until one of the requested events occurs. literally forever. committing to the bit π
Important β this function is ONLY suitable for sockets you got withnn_socket(). it is not compatible with file descriptors obtained via any other means β and yes, that includes file descriptors you got using theNN_SNDFDorNN_RCVFDoptions withnn_getsockopt(). do not try it. i'm serious π
Note β this function is significantly less efficient than other polling or asynchronous I/O mechanisms, and it's provided for API compatibility only. its use is discouraged. it's giving "kept alive for the elders" π
Note β this function is not supported on systems other than POSIX derived platforms and Windows. if you're on something exotic, sorry babe π
π RETURN VALUES π
this function returns the number of sockets with events on success, or -1 on error. simple as that β¨
π ERRORS π
ENOMEMβ insufficient memory available πEBADFβ one of the sockets is not open πETIMEDOUTβ operation timed out β°ENOTSUPβ this function is not supported on this platform π«
π SEE ALSO π
nn_errno(3compat), nn_recv(3compat), nn_send(3compat), nn_socket(3compat), nn_compat(3compat), nng(7)
go read those next, bestie, they're iconic π«Ά
and that's the whole page!! this little gem is from the NNG Reference Manual, dated 2026-01-13, and it lives at NN_POLL(3compat) β mwah, go poll something responsibly π
β¨
π¦ where this page comes from
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms