[comp.unix.wizards] Stream Pipes: how to use them on V.3/386

jom@belltec.UUCP (Jerry Merlaine) (09/24/89)

If you want to use UNIX V.3 Stream Pipes (like you're not supposed to),
here's how:  call the following routine instead of pipe(2) (look it up).
You will get a pair of cross-connected read/write Streams file descriptors.  

FDINSERT's are covered in streams(7) in the UNIX manual.
If you want your own stream pipe, get the Streams Programmer's Guide
and type in the loopback driver sources.  It's Fun And Easy!

#include <sys/types.h>
#include <sys/param.h>
#include <sys/stream.h>
#include <sys/stropts.h>

strpipe(pv)
int pv[2];
{
	struct strfdinsert fdi;

	pv[0] = open("/dev/spx", 2);
	pv[1] = open("/dev/spx", 2);
	if (pv[1] < 0) {
		close(pv[1]);
		if (pv[0] >= 0)
			close(pv[0]);
		return -1;
	}
	if (pv[0] < 0) 
		return -1;
	fdi.ctlbuf.buf = (char *) pv;
	fdi.ctlbuf.len = 4;
	fdi.databuf.buf = 0;
	fdi.databuf.len = -1;
	fdi.offset = 0;
	fdi.fildes = pv[1];
	fdi.flags = 0;
	if (ioctl(pv[0], I_FDINSERT, &fdi) < -1) {
		close(pv[0]);
		close(pv[1]);
		return -1;
	}
	return 0;
}

gil@banyan.UUCP (Gil Pilz@Eng@Banyan) (09/27/89)

In article <405@belltec.UUCP> jom@belltec.UUCP (Jerry Merlaine) writes:

(see previous post for full routine)

>	fdi.ctlbuf.buf = (char *) pv; <---- these two together are wrong ??
>	fdi.ctlbuf.len = 4;                  /
>	fdi.databuf.buf = 0;                /
>	fdi.databuf.len = -1;              /
>	fdi.offset = 0;            <------/
>	fdi.fildes = pv[1];
>	fdi.flags = 0;
>	if (ioctl(pv[0], I_FDINSERT, &fdi) < -1) {
>		close(pv[0]);
>		close(pv[1]);
>		return -1;
>	}

As I understand the streamio(7) documentation (which is to say,
barely), this is gonna cause you to roach pv[0] when the ioctl returns
the address of the read queue structure of the driver for the stream
corresponding to pv[1]. I think maybe you might want to do something
like . .

long foo;

fdi.ctlbuf.buf = &foo;
fdi.ctlbuf.len = sizeof(long);
fdi.offset = 0;

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
        Gilbert W. Pilz Jr.       gil@banyan.com
        Banyan Systems Inc.       (617) 898-1196
        115 Flanders Road
        Westboro, MA 01581
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-