preserving message boundaries on named pipes - System V

Leslie Mikesell les at chinet.chi.il.us
Fri May 19 06:07:34 AEST 1989


In article <571 at lehi3b15.csee.Lehigh.EDU> murrey at lehi3b15.csee.Lehigh.EDU (Erik Murrey) writes:

>System V.3.1 Unix

>Is it possible to preserve message boundaries on named pipes under
>System V?  For instance, if a process sends two separate messages (via
>two write()'s) down a named pipe, how can the receiver read those as
>two separate messages?  It seems that right now, if the reading
>process unblocks after both writes have completed, then it gets *both*
>messages in one read.

>I really don't wan't to muck with terminating null characters, and
>the like...

The easy way is to use fixed length write()'s and matching read()'s.
If the input is sufficiently varied that this approach would impose
a lot of overhead you might precede the data with a length value.  This
should be done as a single write() if multiple processes are writing
to the same FIFO to avoid the possibility of interleaving between the
length and data.  The reader would do a fixed length read() to find
out the size the next read() should be for the data.


Les Mikesell



More information about the Comp.unix.wizards mailing list