In LDD3's scull_p_poll function, if I understand correctly, if poll_wait is not woken up and a timeout occurs, poll returns zero.
static unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
struct scull_pipe *dev = filp->private_data;
unsigned int mask = 0;
/*
* The buffer is circular; it is considered full
* if "wp" is right behind "rp" and empty if the
* two are equal.
*/
down(&dev->sem);
poll_wait(filp, &dev->inq, wait);
poll_wait(filp, &dev->outq, wait);
if (dev->rp != dev->wp)
mask |= POLLIN | POLLRDNORM; /* readable */
if (spacefree(dev))
mask |= POLLOUT | POLLWRNORM; /* writable */
up(&dev->sem);
return mask;
}
Is this a correct assumption as to how poll_wait will work? This is what I took away from Why do we need to call poll_wait in poll? and How to add poll function to the kernel module code?
As all examples I have seen return zero if not a valid POLLIN or POLLRDNORM state exists, I assume zero is the correct timeout return. Can anyone clarify this or point me to documentation that shows this? I have not read deeper than poll.h
poll_wait
doesn't wait at all. Mask, returningscull_p_poll
is AND-ed with the mask requested inselect
/poll
system call and resulted mask is compared with 0. If resulted mask is non-zero, device is treated as ready, and system call returns. Otherwise, device is treated as not ready, and system call waits (outside ofscull_p_poll
!). Actual implementation of poll-related system calls is infs/select.c
.