Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!att!chinet!les From: les@chinet.chi.il.us (Leslie Mikesell) Newsgroups: comp.unix.wizards Subject: Re: preserving message boundaries on named pipes - System V Message-ID: <8486@chinet.chi.il.us> Date: 18 May 89 20:07:34 GMT References: <571@lehi3b15.csee.Lehigh.EDU> Reply-To: les@chinet.chi.il.us (Leslie Mikesell) Organization: Chinet - Public Access Unix Lines: 24 In article <571@lehi3b15.csee.Lehigh.EDU> murrey@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