The Poll System call

The Poll System call performs a similar operation as the select system call. To understand the select system call, an interested reader can visit the below link.

The Select System call

The poll API differs with select API in the manner in which the file descriptors to be monitored are specified to the Poll API. The Poll API is provided below

The ‘nfds’ parameter defines the number of file descriptors in the pollfd structure array in the API. 

Each individual element of the pollfd structure array is as shown below

  • fd – the file descriptor to be monitored
  • events – bitmask of the events that are to monitored for the file descriptor
  • revents – bitmask of the events that are returned to the application when poll API returns

The events that can be monitored are provided below

  • POLLIN and POLLRDNORM are synonymous
  • POLLOUT and POLLWRNORM are synonymous

POLLRDHUP – provides information on whether the peer socket connection is closed or not. This allows adequate action to be taken by the application to close the socket connection. For more information on the flags and their usage – refer “Linux Programming Interface – Michael Kerrisk”.

The timeout parameter has a micro second granularity.

Poll API Code example

 

Comments

  1. Pingback: Select System Call API Code Example | Hitch Hiker's Guide to Learning

  2. Pingback: The Poll API code example | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *