NN_POLL(3compat)

πŸ“¦ version 1.11, in alpine 3.24

πŸ’… 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 of NN_POLLIN and NN_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 β€” revents will only have a flag set if the corresponding flag was ALSO set in the events field. no sneaky extra flags, that's the rule πŸ’…

now the timeout field, and this is the part where people get confused, so focus 🧚

  • if timeout is positive, the function waits up to that many milliseconds. if none of the requested events happens before the timeout hits, the function returns -1 and sets the error to ETIMEDOUT 😭
  • if timeout is zero, the function returns immediately, right after updating the current status of the sockets. instant. no waiting. main character speed πŸ”₯
  • if timeout is -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 with nn_socket(). it is not compatible with file descriptors obtained via any other means β€” and yes, that includes file descriptors you got using the NN_SNDFD or NN_RCVFD options with nn_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