Skip to content

poll API Reference

#include <poll.h>

Prototype

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

struct pollfd

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

Common Events

Event Meaning
POLLIN fd is readable
POLLOUT fd is writable
POLLERR error condition
POLLHUP hang-up condition
POLLNVAL invalid fd

Return Value

Return Meaning
> 0 number of fds with returned events
0 timeout
-1 error, errno is set

Common Pitfalls

  • poll() reports readiness only; it does not consume data.
  • Read or write after readiness is reported.
  • Handle EINTR if interrupted by a signal.
  • Check revents, not only the requested events.