Click to See Complete Forum and Search --> : FIFO Help


Creed
09-17-2001, 02:20 PM
I am coding a little program that uses a fifo. This is the relevant code:

#define FIFO_NAME "/fifo/req_fifo"
//now, create the fifo
unlink(FIFO_NAME);
if(access(FIFO_NAME, F_OK)) {
cout << "creating req_fifo\n";
y = mkfifo(FIFO_NAME, 0777);
if(y !=0) {
cout << "could not create req_fifo\n";
return -1;
}
}


cout << "opening file\n";
req = open(FIFO_NAME, O_RDONLY);
cout << "file opened for read" << req << "\n";

cout << "try a read\n";
x = read(req, req_string, PIPE_BUF);

-----------------------------
now, from what I understand, the open command should return quickly, and the read command should block until something opens up the fifo for writing. What happens is that the program hangs on the open. If something opens the fifo for writing(ie. echo hi > /fifo/req_fifo), it returns from the open, and then immediately returns from the read as well. any thoughts?

jemfinch
09-17-2001, 10:21 PM
My wild guess (this is without checking any manpages, because I'm not at my computer) is that the open will block until there's a writer also connected to the fifo (or unless there's data already on the fifo.)

Jeremy

pinoy
09-18-2001, 04:32 AM
Opening a FIFO seems to block when opened readonly. Opening it O_RDWR, returns right away, but doesn't seem to return EOF when the client closes the other side.