1NN_POLL(3)                       nanomsg 1.1.5                      NN_POLL(3)
2
3
4

NAME

6       nn_poll - poll a set of SP sockets for readability and/or writability
7

SYNOPSIS

9       #include <nanomsg/nn.h>
10
11       int nn_poll (struct nn_pollfd *fds, int nfds, int timeout);
12

DESCRIPTION

14       The function checks a set of SP socket and reports whether it’s
15       possible to send a message to the socket and/or receive a message from
16       each socket.
17
18       fds argument is an array of nn_pollfd structures with nfds argument
19       specifying the size of the array:
20
21           struct nn_pollfd {
22               int fd;
23               short events;
24               short revents;
25           };
26
27       Each entry in the array represents an SP socket to check. events field
28       specifies which events to check for. The value is a bitwise combination
29       of the following values:
30
31       NN_POLLIN
32           Check whether at least one message can be received from the fd
33           socket without blocking.
34
35       NN_POLLOUT
36           Check whether at least one message can be sent to the fd socket
37           without blocking.
38
39       After the function returns, revents field contains bitwise combination
40       of NN_POLLIN and NN_POLLOUT according to whether the socket is readable
41       or writable.
42
43       timeout parameter specifies how long (in milliseconds) should the
44       function block if there are no events to report.
45

RETURN VALUE

47       Upon successful completion, the number of nn_pollfds structures with
48       events signaled is returned. In case of timeout, return value is 0. In
49       case of error, -1 is returned and errno is set the one of the values
50       below.
51

ERRORS

53       EBADF
54           Some of the provided sockets are invalid.
55
56       EINTR
57           The operation was interrupted by delivery of a signal before the
58           message was sent.
59
60       ETERM
61           The library is terminating.
62

NOTE

64       nn_poll is a convenience function. You can achieve same behaviour by
65       using NN_RCVFD and NN_SNDFD socket options. However, using the socket
66       options allows for usage that’s not possible with nn_poll, such as
67       simultaneous polling for both SP and OS-level sockets, integration of
68       SP sockets with external event loops etc.
69

EXAMPLE

71           struct nn_pollfd pfd [2];
72           pfd [0].fd = s1;
73           pfd [0].events = NN_POLLIN | NN_POLLOUT;
74           pfd [1].fd = s2;
75           pfd [1].events = NN_POLLIN;
76           rc = nn_poll (pfd, 2, 2000);
77           if (rc == 0) {
78               printf ("Timeout!");
79               exit (1);
80           }
81           if (rc == -1) {
82               printf ("Error!");
83               exit (1);
84           }
85           if (pfd [0].revents &amp; NN_POLLIN) {
86               printf ("Message can be received from s1!");
87               exit (1);
88           }
89

SEE ALSO

91       nn_socket(3) nn_getsockopt(3) nanomsg(7)
92

AUTHORS

94       Martin Sustrik <sustrik@250bpm.com>
95
96
97
98                                  2019-07-25                        NN_POLL(3)
Impressum