Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (0 / 6) |
Uptime: | 56:35:35 |
Calls: | 481 |
Files: | 1,071 |
Messages: | 95,868 |
In our last episode, the evil Dr. Lacto had captured our hero,
Lawrence D'Oliveiro <ldo@nz.invalid>, who said:
Typically when you open a file descriptor on a pipe, it’s either for
reading or writing, but not both.
However, when you open a named pipe, it is possible to specify the
mode O_RDWR; but does this work, or return an error? And if it doesn’t
return an error, what exactly does it do?
I'm not exactly sure what you're asking here, but I just set this up yesterday.
I open a FIFO
char myfifoname[100];
int myfifo;
sprintf(myfifoname,"/tmp/program.%08d",getpid());
mkfifo(myfifoname, S_IRUSR | S_IWUSR);
myfifo = open(myfifoname,O_RDWR | O_NONBLOCK);
Then I spawn a bunch of forks which already have the FIFO open. The
forked children write to the FIFO
if ( (cpid[9]=fork()) == 0)
{
for (;;)
{
write(myfifo,"9a\n",strlen("9a\n"));
napms( (int) Random(50,250));
write(myfifo,"9b\n",strlen("9b\n"));
napms( (int) Random(50,250));
}
}
And the parent process reads from the FIFO
for (;;)
{
int r=read(myfifo,buf,10);
int window = buf[0]-'0';
if (buf[1] == 'a')
/* Do stuff on the provided window */
if (buf[1] == 'b')
/* Do stuff on the provided window */
}
In my case, I know there's always a single-digit number followed by a
single character.
--hymie! http://nasalinux.net/~hymie hymie@nasalinux.net
Typically when you open a file descriptor on a pipe, it’s either for reading or writing, but not both.
However, when you open a named pipe, it is possible to specify the
mode O_RDWR; but does this work, or return an error? And if it doesn’t return an error, what exactly does it do?