I haven't found sample code demonstrating this. Below is part of the code that I tested on a set of sockets. Note that (not in the below code), I set "except_set" to be the union of "read_set" and "write_set" in order to monitor all sockets involved.
Basically what I expect to see is when error happens, it should print out the list of error-some socket(s). However, what I observe is the case of "n == -1" which only gives one error message (in my case, "bad file descriptor"). It would be better to print out the socket which encounters the error.
Another issue: Since there is only one "errno" how can it represent error for multiple sockets (if more than one sockets encounter error in one select() call). I am really confused. What kind of error(s) would "except_set" capture on per socket basis? What is proper way of using it? Thanks a lot.
int n = select(max_fd + 1, &(read_set), &(write_set), &(except_set), &tv);
if (n == -1)
{
perror("select()");
exit(1);
}
else if (n == 0)
{
// process time-out ...
}
else // (n > 0)
{
for (int i=0; i < max_fd; ++i)
{
if (FD_ISSET(i, &(read_set)))
{
// process read
}
if (FD_ISSET(i, &(write_set)))
{
// process write
}
if (FD_ISSET(i, &(except_set)))
{
printf("error, %s, socket= %d", strerror(errno), i);
}
}
}