0

Most examples of the select() function use a 0 to 'max file descriptor value' approach:

fd_set master_fd_set;
    FD_ZERO(&master_fd_set);

    fd_set temp_fd_set;
    FD_ZERO(&temp_fd_set);

    int max_fd = the_max_file_descriptor_value_of_descriptors_interested_in;

    ...

    temp_fd_set = master_fd_set;
    ::select(max_fd, &temp_fd_set, NULL, NULL, NULL);
    for (int i = 0; i <= max_fd; ++i)
    {
        if (FD_ISSET(i, &temp_fd_set))
        {
            // a read on file descriptor i
        }
        ...
    }

It seems to me that if I had an STL set (std::set<int>) of file descriptors, I could benefit from the set providing an ordering of the fd values (no need to manipulate the "max value" of 'max_fd'), and, instead of iterating from 0 to max_fd, I could just iterate over just those descriptors (in the set) in which I am interested:

for (set<int>::iterator iter = fdset.begin(); iter != fdset.end(); ++iter)
    {
        int i = *iter;
        if (FD_ISSET(i, &temp_fd_set))
        {
            // a read on file descriptor i
        }
        ...
    }

Does anyone know if it is required to iterate from 0 to max_fd when testing with FD_ISSET()? Would a "sparse" check of just those file descriptors (using a set iterator) in the set be ok to use?

Thanks for any input/insight.
-Mr68360

Edited by Mr68360: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by nezachem
0

> Would a "sparse" check of just those file descriptors (using a set iterator) in the set be ok to use?

Absolutely OK.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.