How do I use poll()?
Poll() in UNIX is used for to wait for some event on a file descriptor. When poll() is used, the user must allocate an array of pollfd structures, and pass the number of entries in this array.
int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
The parameter fd is a file descriptor to open the file while timeout is in milliseconds. If the timeout value is negative, it means negative timeout. The structure if the is as below:
struct pollfd {
int fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
How do I use poll()?
poll() allows an event to wait on a file descriptor. A pointer is accepted by poll() to a list of ‘struct pollfd’. A bitwise mask is used to specify the events in the field of events of the structure. The structure’s instance will be filled at a later point of time and returns with events that were occurred.
The struct pollfd has the following format
struct pollfd {
int fd; /* The descriptor. */
short events; /* The event(s) is/are specified here. */
short revents; /* Events found are returned here. */
};