Is it OK to poll() a device file descriptor

Is it OK to poll() a device file descriptor

Shachar Shemesh shachar at shemesh.biz
Wed Jun 19 07:47:27 IDT 2013


On 18/06/13 22:16, Elazar Leibovich wrote:
> I'm using it as a fake "always non-blocking" file descriptor.
>
> My main libevent-like poll loop looks like:
>
>     poll(fds)
>     for fd in fds:
>        if fd.revents | POLLIN:
>            fd.read_callback()
>        if fd.revents | POLLOUT:
>            fd.write_callback()
>
> Now let's say I want a fake filedescriptor that always reads 'z's (a
> sleepy fd).
Why? What you just did was to turn the whole thing into a non-sleeping
loop. If that's the case, simply call poll with a zero timeout, so it
won't sleep, and call your callback at the end of each loop. No need to
artificially introduce another file descriptor into the mix.

Mind you, I still don't understand WHY you'd want such a thing. This
code will, by definition, consume 100% CPU all the time.

Shachar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20130619/d6b41b17/attachment.html>


More information about the Linux-il mailing list