Pipe Library

Cameron Taylor ctaylor@waverider.com
Fri Dec 24 18:28:00 GMT 2004


We have developed a pipe implementation which we find useful for
interprocess communication. It is also the basis for the pty implementation
in the following submission.

As seems appropriate for an embedded system, pipes are instantiated
statically. The same mechanism is used as for other devices: an entry is
made in the DEVTAB for each pipe the application wishes to use. An arbitrary
number of pipes can be created. The application then uses open(), write(),
read(), select(), etc. to access the pipe. Both read and write selects are
supported.

One option implemented is a timeout applied to reads and writes set on
instantiation: FOREVER, NO_WAIT or a timeout in ticks (this is separate from
the select timeout).

The pipe can also be purged (pipelib_purge just calls fsync which discards
any content).

We have inserted the attached files in packages/io/pipe/... and made the
following entry in ecos.db

package CYGPKG_IO_PIPELIB {
    alias        { "Pipe Driver Library"}
    directory    io/pipe
    script       pipelib.cdl
    description  "This package contains a device driver for pipes."
}

Examples of use (without error checks, etc):

#include <cyg/io/pipelib.h>

// Instantiate a pipe device (the application supplies the buffer space) at
file scope
static char buf[500];
PIPELIB_DEVICE(pipe0, "/dev/pipe0", buf, sizeof(buf),
PIPE_TIMEOUT_WAIT_FOREVER);

main()
{
	// Open the pipe
	int pipeFd;
	pipeFd = open("/dev/pipe0", O_RDWR);

	// optionally clear the pipe by dumping any current content
	pipelib_purge(pipeFd);

	// write to the pipe
	write(pipeFd, "stuff", 5);

	// select on reading from the pipe
	fd_set fds;
	FD_ZERO(&fds);
	FD_SET(pipeFd, &fds);
	select(FD_SETSIZE, &fds, NULL, NULL, NULL);

	// read from the pipe
	char readbuf[10];
	read(pipeFd, readbuf, sizeof(readbuf));
}

Comments, questions and suggestions are appreciated. This is intended as a
starting point for discussion as some documentation and test cases will also
be required. Hopefully this will be useful to others as well.

Cameron Taylor
WaveRider Communications
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pipelib.cdl
Type: application/octet-stream
Size: 2640 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/ecos-patches/attachments/20041224/5e73742c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pipelib.h
Type: application/octet-stream
Size: 6632 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/ecos-patches/attachments/20041224/5e73742c/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pipelib.c
Type: application/octet-stream
Size: 14186 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/ecos-patches/attachments/20041224/5e73742c/attachment-0002.obj>


More information about the Ecos-patches mailing list