Sunday, January 09, 2011

select function does not stop

I use named FIFO and select function to do IPC programming. When program execute to "if(select(myfd+d, myfdSet, NULL, NULL, &waittime) > 0 && IS_SET(myfdSet))", it always fulfill condition even there is no any process wrote into named FIFO.
After I examin again, I find out that I open file as "O_RDONLY". Refer to Linux's man page, there is a section to discript it:


Under Linux, select() may report a socket file descriptor as "ready for reading", while nevertheless a subsequent read blocks.

Hence, I modify open statement from myfd = open("/tmp/a", O_RDONLY) to myfd = open("/tmp/a", O_RDWR|O_NONBLOCK). Everything is perfect right.

No comments: