poll

Function

A better alternative of select

Function Prototype

totalFds = poll(fdarray[], nfds, timeout)
  • fdarray[] - stores the file descriptor we want to monitor and what event do we want to monitor. Each element inside is a struct
    • events- bit mask, each bit indicates an event of interest in fd
    • revents - bit mask, each bit indicates an event that occurred on fd
struct pollfd {
	int fd;
	short events;
	short revents;
}

How it works?

Similar to select, but we can monitor more than just read, write, and error. Instead, the events enable us to monitor more things

Additionally, the variable which record events of interest won’t be revised like that in select because we record the occurrence in revents