Subject: Re: Faster pipes from FreeBSD
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 04/07/2001 00:04:29
> actually...while i know the strict "definition" of pipes is that they
> are unidirectional with a single read and a single write endpoint, in
> my (limited?) experience, i've always found pipes to be bidirectional.
> including ours.
When did you last test? Looking at sys_pipe(), I note that it opens
one end FREAD-only and the other end FWRITE-only.
And I did a test just now, and find that the pipe is in fact
unidirectional. Note in particular the marked kdump lines.
% cat pipetest.c
#include <unistd.h>
#include <stdlib.h>
int main(void);
int main(void)
{
int p[2];
char buf[32];
pipe(p);
write(p[0],"123",3);
write(p[1],"123",3);
read(p[0],&buf[0],32);
read(p[1],&buf[0],32);
exit(0);
}
% cc -o pipetest pipetest.c
% ktrace pipetest
% kdump | tail -20
25302 pipetest RET mmap 269307904/0x100d5000
25302 pipetest CALL munmap(0x100c0000,0xf000)
25302 pipetest RET munmap 0
25302 pipetest CALL close(0x3)
25302 pipetest RET close 0
25302 pipetest CALL pipe
25302 pipetest RET pipe 3
25302 pipetest CALL write(0x3,0x10aa0,0x3)
>>> 25302 pipetest RET write -1 errno 9 Bad file descriptor
25302 pipetest CALL write(0x4,0x10aa0,0x3)
25302 pipetest GIO fd 4 wrote 3 bytes
"123"
25302 pipetest RET write 3
25302 pipetest CALL read(0x3,0xeffff7f0,0x20)
25302 pipetest GIO fd 3 read 3 bytes
"123"
25302 pipetest RET read 3
25302 pipetest CALL read(0x4,0xeffff7f0,0x20)
>>> 25302 pipetest RET read -1 errno 9 Bad file descriptor
25302 pipetest CALL exit(0)
This test was done under 1.4T.
der Mouse
mouse@rodents.montreal.qc.ca
7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B