NN_POLL(3)
๐ NN_POLL(3) ๐
okay bestie, welcome to nn_poll(3) from the nanomsg fam (manual name NN_POLL, section 3, if you were wondering ๐ซถ). this is the page where we learn how to peek at a whole lil squad of SP sockets and go "hey, can any of y'all talk to me right now?" no cap.
โจ NAME โจ
nn_poll โ poll a set of SP sockets for readability and/or writability
๐ธ SYNOPSIS ๐ธ
#include <nanomsg/nn.h>
int nn_poll (struct nn_pollfd *fds, int nfds, int timeout);
๐ฆ DESCRIPTION ๐ฆ
so basically this function checks a set of SP sockets and reports back whether it's possible to send a message to the socket and/or receive a message from each socket. it's giving "vibe check but for sockets" ๐
the fds argument is an array of nn_pollfd structures, and the nfds argument specifies the size of that array:
struct nn_pollfd {
int fd;
short events;
short revents;
};
every entry in the array = one SP socket you want checked. the events field says which events you're checking for. its value is a bitwise combination of these icons here:
NN_POLLINโ check whether at least one message can be received from thefdsocket without blocking. like, is there mail in the mailbox? ๐ฌNN_POLLOUTโ check whether at least one message can be sent to thefdsocket without blocking. like, is the mailbox open for business? ๐ฎ
after the function returns, the revents field contains a bitwise combination of NN_POLLIN and NN_POLLOUT depending on whether the socket is readable or writable. so that's where the receipts show up ๐งพ
the timeout parameter specifies how long โ in milliseconds โ the function should block if there are no events to report. (yes bestie, milliseconds, don't come at me with seconds ๐)
๐ RETURN VALUE ๐
upon successful completion, the number of nn_pollfds structures with events signaled is returned. slay. โจ
if it times out, the return value is 0. ๐
if there's an error, -1 is returned and errno is set to one of the values below. not the vibe.
๐ ERRORS ๐
EBADFโ some of the provided sockets are invalid. bestie... those sockets don't exist ๐ญEINTRโ the operation was interrupted by delivery of a signal before the message was sent. rude of that signal, honestly.ETERMโ the library is terminating. it's over, periodt.
๐ NOTE ๐
nn_poll is a convenience function. you can achieve the same behaviour by using the NN_RCVFD and NN_SNDFD socket options. however, using the socket options allows for usage that's not possible with nn_poll โ such as simultaneous polling for both SP and OS-level sockets, integration of SP sockets with external event loops, etc. so like, nn_poll is the cute little shortcut, but the socket options are the main character energy version ๐ซถ
๐ EXAMPLE ๐
struct nn_pollfd pfd [2];
pfd [0].fd = s1;
pfd [0].events = NN_POLLIN | NN_POLLOUT;
pfd [1].fd = s2;
pfd [1].events = NN_POLLIN;
rc = nn_poll (pfd, 2, 2000);
if (rc == 0) {
printf ("Timeout!");
exit (1);
}
if (rc == -1) {
printf ("Error!");
exit (1);
}
if (pfd [0].revents & NN_POLLIN) {
printf ("Message can be received from s1!");
exit (1);
}
๐ฅ SEE ALSO ๐ฅ
nn_socket(3) nn_getsockopt(3) nanomsg(7)
๐ AUTHORS ๐
Martin Sustrik <sustrik@250bpm.com> โ the icon who made this, we stan ๐ซก
and that's the whole page bestie!! this was nanomsg version 1.2.2, dated 2026-01-16, and yes it's literally NN_POLL(3) again because we came full circle ๐ฆโจ go poll something, you got this ๐
๐ฆ where this page comes from
- fedora 44: nanomsg-devel 1.2.2-2.fc44 ยท MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms