Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between POLLIN and POLLPRI in poll() syscall

The documentation of poll() did not explain this in detail. While polling on an fd, when should one POLLIN and when should one use POLLPRI? Any insights will be useful.

like image 776
Punit Soni Avatar asked Oct 21 '25 02:10

Punit Soni


1 Answers

There are some description on poll() document.

POLLIN  There is data to read.
POLLPRI There is urgent data to read.
  • If you use POLLIN only, poll() will return if there is data or urgent data to read.
  • If you use POLLPRI only, poll() will return only if there is urgent data to read, but ignore normal data.

What's urgent data?

Like tcp's out-of-band data. In TCP frame header, there is a flag named urg_data. urg_data means this frame has higher priority to delivery. Once kernel received a urg_data marked frame, it set a POLLPRI flag! Look at the following code:

...
if (tp->urg_data & TCP_URG_VALID)
   mask |= POLLPRI;
....
return mask;
like image 100
Bennett Ma Avatar answered Oct 25 '25 15:10

Bennett Ma