Xref: utzoo comp.unix.wizards:18310 comp.unix.i386:551
Path: utzoo!attcan!uunet!ginosko!gem.mps.ohio-state.edu!apple!bionet!ames!pacbell!belltec!jom
From: jom@belltec.UUCP (Jerry Merlaine)
Newsgroups: comp.unix.wizards,comp.unix.i386
Subject: Stream Pipes: how to use them on V.3/386
Keywords: Sysv /dev/spx: ask and ye shall receive
Message-ID: <405@belltec.UUCP>
Date: 23 Sep 89 23:47:14 GMT
Organization: Bell Technologies, Fremont, CA
Lines: 42

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

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;
}