POLL(2) Linux Programmer's Manual POLL(2)
NAME
poll - wait for some event on a file(1,n) descriptor
SYNOPSIS
#include <sys/poll.h>
int poll(struct pollfd *ufds, unsigned int nfds, int timeout(1,3x,3x cbreak));
DESCRIPTION
poll is a variation on the theme of select(2,7,2 select_tut). It specifies an array of
nfds structures of type
struct pollfd {
int fd; /* file(1,n) descriptor */
short events; /* requested events */
short revents; /* returned events */
};
and a timeout(1,3x,3x cbreak) in(1,8) milliseconds. A negative value means infinite timeout.
The field fd contains a file(1,n) descriptor for an open(2,3,n) file. The field
events is an input parameter, a bitmask specifying the events the
application is interested in. The field revents is an output parame-
ter, filled by the kernel with the events that actually occurred,
either of the type requested, or of one of the types POLLERR or POLLHUP
or POLLNVAL. (These three bits are meaningless in(1,8) the events field,
and will be set(7,n,1 builtins) in(1,8) the revents field whenever the corresponding condi-
tion is true.) If none of the events requested (and no error(8,n)) has
occurred for any of the file(1,n) descriptors, the kernel waits for timeout(1,3x,3x cbreak)
milliseconds for one of these events to occur. The following possible
bits in(1,8) these masks are defined in(1,8) <sys/poll.h>
#define POLLIN 0x0001 /* There is data to read(2,n,1 builtins) */
#define POLLPRI 0x0002 /* There is urgent data to read(2,n,1 builtins) */
#define POLLOUT 0x0004 /* Writing now will not block */
#define POLLERR 0x0008 /* Error condition */
#define POLLHUP 0x0010 /* Hung up */
#define POLLNVAL 0x0020 /* Invalid request: fd not open(2,3,n) */
When compiling XPG4.2 source one also has
#ifdef _XOPEN_SOURCE
#define POLLRDNORM 0x0040 /* Normal data may be read(2,n,1 builtins) */
#define POLLRDBAND 0x0080 /* Priority data may be read(2,n,1 builtins) */
#define POLLWRNORM 0x0100 /* Writing now will not block */
#define POLLWRBAND 0x0200 /* Priority data may be written */
#endif
Finally, Linux knows about
#ifdef _GNU_SOURCE
#define POLLMSG 0x0400
#endif
RETURN VALUE
On success, a positive number is returned, where the number returned is
the number of structures which have non-zero revents fields (in(1,8) other
words, those descriptors with events or errors reported). A value of 0
indicates that the call timed out and no file(1,n) descriptors have been
selected. On error(8,n), -1 is returned, and errno is set(7,n,1 builtins) appropriately.
ERRORS
EBADF An invalid file(1,n) descriptor was given in(1,8) one of the sets.
EFAULT The array given as argument was not contained in(1,8) the calling
program's address space.
EINTR A signal(2,7) occurred before any requested event.
EINVAL The nfds value exceeds the RLIMIT_NOFILE value.
ENOMEM There was no space to allocate file(1,n) descriptor tables.
BUGS
See the BUGS section of select(2,7,2 select_tut)(2).
CONFORMING TO
XPG4-UNIX.
AVAILABILITY
The poll() systemcall was introduced in(1,8) Linux 2.1.23. The poll()
library call was introduced in(1,8) libc 5.4.28 (and provides emulation
using select(2,7,2 select_tut) if(3,n) your kernel does not have a poll syscall).
SEE ALSO
select(2,7,2 select_tut)(2), select_tut(2)
Linux 2.1.23 1997-12-07 POLL(2)