Sunday, 11 August 2013

select is not saving file descriptors

select is not saving file descriptors

Yesterday I discovered select, which is a very useful tool, but I'm not
able to make it work. This is part of my total code:
/* Code here */
FD_ZERO(&fifo_set);
printf("%d\n", num_proc);
for(i = 0; i < num_proc; ++i)
FD_SET(proc[i].fifowfd, &fifo_set);
/* More code here */
if(select(FD_SETSIZE, &fifo_set, NULL, NULL, NULL) < 0)
{
log_event(5, "Could not block.");
exit(1);
}
printf("FD_SETSIZE: %d\n", FD_SETSIZE);
for(i = 0; i < FD_SETSIZE; ++i)
printf("ISSET %d: %d\n", i, FD_ISSET(i,&fifo_set));
log_event(1, "Actions to be done.");
/* More code */
The array proc, is an array of processes, given its PID, and a read and
write FIFO. The file descriptors to the FIFOs are checked, and are valid.
The problem is: there are 3 processes (num_proc), with the fifowfd values
5, 7 and 9. But when I print all FD_ISSET, only the 5 seems to be
registered and have data, but all three have data. FD_SETSIZE has the
value 1024
Am I missing something?

No comments:

Post a Comment