I opened a named pipe fd in read/nonblocking mode, and then associated a
stream using fdopen
int pipe1_fd = open("/tmp/myfirstfifo", open_mode);
FILE *pipe_fd= fdopen(pipe1_fd,"r");
First time, the read gets blocked on select with a time out of 20 secs as
set in the function call(expected behaviour).
Once there is something in the pipe, select returns and FD_ISSET succeeds.
But after the first successful read from pipe, the while loop continues and
the next select always returns 1 instead of blocking again for 20 secs(Note:
I am not writing any data to the pipe at this time). I am not able to reset
the fds' value. How can i do that? What went wrong? Is it because i am
mixing file descriptor and the stream?
The code is
main()
{
fd_set fds;
while(1)
{
if(isready(pipe_fd1,&fds)==1)
// there is data to process...
// read using fscanf(%d%c",&length,&comma) and fread(pipe_fd,buffer,length);
else
// there is no data to process. need to block on select
}
}
isready(int fd, fd_set *fds)
{
FD_ZERO(fds);
FD_SET(pipe_fd,fds);
rc = select(fd+1, fds, NULL, NULL, NULL);
if rc<0
return -1
FD_ISSET(fd,fds)?1:0;
}
Please clarify
Sathya
[Non-text portions of this message have been removed]