Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
POLL(2)                   OpenBSD Programmer's Manual                  POLL(2)

NAME
     poll - synchronous I/O multiplexing

SYNOPSIS
     #include <poll.h>

     int
     poll(struct pollfd *fds, int nfds, int timeout);

DESCRIPTION
     poll() provides a mechanism for reporting I/O conditions across a set of
     file descriptors.

     The arguments are as follows:

     fds      Points to an array of pollfd structures, which are defined as:

                    struct pollfd {
                            int fd;
                            short events;
                            short revents;
                    };

              The fd member is an open file descriptor.  If fd is -1, the
              pollfd structure is considered unused, and revents will be
              cleared.

              The events and revents members are bitmasks of conditions to
              monitor and conditions found, respectively.

     nfds     The number of pollfd structures in the array.

     timeout  Maximum interval to wait for the poll to complete, in millisec-
              onds.  If this value is 0, then poll() will return immediately.
              If this value is INFTIM (-1), poll() will block indefinitely un-
              til a condition is found.

     The calling process sets the events bitmask and poll() sets the revents
     bitmask.  Each call to poll() resets the revents bitmask for accuracy.
     The condition flags in the bitmasks are defined as:

     POLLIN      Data other than high-priority data may be read without block-
                 ing.

     POLLRDNORM  Normal data may be read without blocking.

     POLLRDBAND  Priority data may be read without blocking.

     POLLNORM    Same as POLLRDNORM.  This flag is provided for source code
                 compatibility with older programs and should not be used in
                 new code.

     POLLPRI     High-priority data may be read without blocking.

     POLLOUT     Normal data may be written without blocking.

     POLLWRNORM  Same as POLLOUT.

     POLLWRBAND  Priority data may be written.

     POLLERR     An error has occurred on the device or socket.  This flag is
                 only valid in the revents bitmask; it is ignored in the
                 events member.

     POLLHUP     The device or socket has been disconnected.  This event and
                 POLLOUT are mutually-exclusive; a descriptor can never be
                 writable if a hangup has occurred.  However, this event and
                 POLLIN, POLLRDNORM, POLLRDBAND, or POLLPRI are not mutually-
                 exclusive.  This flag is only valid in the revents bitmask;
                 it is ignored in the events member.

     POLLNVAL    The corresponding file descriptor is invalid.  This flag is
                 only valid in the revents bitmask; it is ignored in the
                 events member.

     In addition to I/O multiplexing, poll() can be used to generate simple
     timeouts.  This functionality may be achieved by passing a null pointer
     for fds.

RETURN VALUES
     Upon error, poll() returns a -1 and sets the global variable errno to in-
     dicate the error.  If the timeout interval was reached before any events
     occurred, a 0 is returned.  Otherwise, poll() returns the number of file
     descriptors for which revents is non-zero.

ERRORS
     poll() will fail if:

     [EINVAL]   nfds was either a negative number or greater than the number
                of available file descriptors.

     [EINVAL]   The timeout passed to poll() was too large.

     [EAGAIN]   Resource allocation failed inside of poll().  Subsequent calls
                to poll() may succeed.

     [EINTR]    poll() caught a signal during the polling process.

SEE ALSO
     getrlimit(2), read(2), select(2), write(2)

HISTORY
     A poll() system call appeared in AT&T System V.3 UNIX.

BUGS
     The POLLHUP and POLLERR flags are currently unimplemented in OpenBSD.

     Because OpenBSD does not implement STREAMS, there is no distinction be-
     tween some of the fields in the events and revents bitmasks.  As a re-
     sult, the POLLIN, POLLNORM, POLLPRI, POLLRDNORM and POLLRDBAND flags are
     all equivalent.  Also, the POLLWRBAND flag is equivalent to POLLWRNORM.

OpenBSD 3.4                    December 13, 1994                             2

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SEE ALSO | HISTORY | BUGS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=poll&sektion=2&manpath=OpenBSD+3.4>

home | help