linuxpollingsystem-calls

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.


Solution

  • There are some description on poll() document.

    POLLIN  There is data to read.
    POLLPRI There is urgent data to read.
    

    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;