Return to BSD News archive
Xref: sserve comp.os.lynx:127 comp.unix.bsd:13076
Path: sserve!newshost.anu.edu.au!munnari.oz.au!bunyip.cc.uq.oz.au!harbinger.cc.monash.edu.au!yeshua.marcam.com!news.kei.com!sol.ctr.columbia.edu!howland.reston.ans.net!europa.eng.gtefsd.com!uunet!decwrl!parc!draco!leisner
From: leisner@draco (Marty Leisner 25733)
Newsgroups: comp.os.lynx,comp.unix.bsd
Subject: select, read and named pipes
Date: 13 Dec 1993 23:17:04 GMT
Organization: Xerox Palo Alto Research Center
Lines: 82
Message-ID: <2eit5g$t3i@news.parc.xerox.com>
Reply-To: leisner@sdsp.mc.xerox.com
NNTP-Posting-Host: draco.sdsp.mc.xerox.com
X-Newsreader: TIN [version 1.2 PL2]
I have this program:
/tmp/devpp is a named pipe.
1) on sunos sparc it run as expected (processes can
open/close /tmp/devpp, and select is only knocked out when
something is there to be read.
2) on lynx/sparc, it works until the first process terminates
(closes the pipe). Then select returns a postive response
(something interesting happened), and read returns 0 (nothing
to read).
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
static void test_and_read(const int fd)
{
fd_set read_set;
int status;
static int i = 0;
char buffer[1024];
i++;
FD_ZERO(&read_set);
FD_SET(fd, &read_set);
status = select(fd +1, &read_set, NULL, NULL, NULL);
switch(status) {
case 0:
printf("Nothing in loop %d\n", i);
break;
case -1:
perror("select");
break;
default:
if(FD_ISSET(fd, &read_set)) {
int num_bytes;
num_bytes = read(fd, &buffer, sizeof(buffer));
printf("Read %d bytes in loop %d\n", num_bytes, i);
} else printf("No fd set in %d\n", i);
}
}
main()
{
int fd;
#if 0
fd = open("/tmp/devpp", O_RDONLY | O_NDELAY);
#else
fd = open("/tmp/devpp", O_RDONLY );
#endif
if(fd < 0) {
perror("open /tmp/devpp");
exit(1);
}
while(1)
test_and_read(fd);
}
The O_NDELAY only has an effect if the open blocks or not...
I would appreciate if this was run on other BSD systems to determine
the behavior. Also any comments on whether the SunOS behavior is
correct or not...
--
marty
leisner@sdsp.mc.xerox.com leisner.henr801c@xerox.com
Member of the League for Programming Freedom
"I just know I'm a better manager when I have Joe DiMaggio in center field" -- Casey Stengel