This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Pipe Library


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

Attachment: pipelib.cdl
Description: Binary data

Attachment: pipelib.h
Description: Binary data

Attachment: pipelib.c
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]