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?
#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?