Remove File Descriptor from poll() set - Unix

This is a discussion on Remove File Descriptor from poll() set - Unix ; Is it possible to remove a file descriptor from a pollfd set? I've noticed that alternative poll implementations, such as Sun's /dev/poll seems to have this option, but I don't see any such option on regular poll(). Is there any ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Remove File Descriptor from poll() set

  1. Remove File Descriptor from poll() set

    Is it possible to remove a file descriptor from a pollfd set? I've
    noticed that alternative poll implementations, such as Sun's /dev/poll
    seems to have this option, but I don't see any such option on regular
    poll(). Is there any way to mark a certain file descriptor as
    removed, so that poll() does not check it? Otherwise, I would need to
    reallocate the entire pollfd array everytime, which seems inefficient.


  2. Re: Remove File Descriptor from poll() set

    wrote in message
    news:1174697071.702847.287590@p15g2000hsd.googlegr oups.com...
    > Is it possible to remove a file descriptor from a pollfd set? I've
    > noticed that alternative poll implementations, such as Sun's /dev/poll
    > seems to have this option, but I don't see any such option on regular
    > poll(). Is there any way to mark a certain file descriptor as
    > removed, so that poll() does not check it?


    If the fd member of a struct pollfd in the array passed to poll() is set
    to -1, it will be ignored.

    Alternatively, you can "pack" the array you pass to poll(): when you decide
    you want to remove a descriptor, copy the last element of the array into its
    place. This obviously involves some additional housekeeping which is not
    quite as trivial as it may first appear...

    Alex



  3. Re: Remove File Descriptor from poll() set

    chsalvia@gmail.com writes:

    >Is it possible to remove a file descriptor from a pollfd set? I've
    >noticed that alternative poll implementations, such as Sun's /dev/poll
    >seems to have this option, but I don't see any such option on regular
    >poll(). Is there any way to mark a certain file descriptor as
    >removed, so that poll() does not check it? Otherwise, I would need to
    >reallocate the entire pollfd array everytime, which seems inefficient.


    Just set the fd to "-1" and the poll structure is ignored:

    If the value fd is less than 0, events is ignored and
    revents is set to 0 in that entry on return from poll().

    So, apart from fd 0, you could use something like:

    pollfd[ignored].fd = -pollfd[ignored].fd;

    for those you want to ignore.

    Casper

+ Reply to Thread