Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cmcl2!phri!marob!cowan From: cowan@marob.MASA.COM (John Cowan) Newsgroups: comp.unix.wizards Subject: Re: preserving message boundaries on named pipes - System V Message-ID: <680@marob.MASA.COM> Date: 19 May 89 19:42:33 GMT References: <571@lehi3b15.csee.Lehigh.EDU> <683@maxim.erbe.se> Reply-To: cowan@marob.masa.com (John Cowan) Organization: ESCC New York City Lines: 28 In article <683@maxim.erbe.se> prc@maxim.UUCP (Robert Claeson) writes: >In article <571@lehi3b15.csee.Lehigh.EDU> murrey@lehi3b15.csee.Lehigh.EDU (Erik Murrey) writes: > >>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? > >You can't, as far as I know. I'd suggest you to take a look at message >queues instead. They are also more efficient than pipes since they don't >deal with the file system at all. Claeson is technically correct. However, it is an undocumented, but reliable, property of the 'write' system call on a pipe that it is atomic if the number of bytes written is less than a certain magic number, typically 10240. Therefore, a message protocol can be superimposed on the regular named pipe bytestream by some such scheme as "prefix each message by its length" or "delimit each message with a reserved character". No mixing of messages will occur, as long as the above length restriction is observed. These remarks apply equally to named and regular pipes, and to all versions of Unix, modulo the exact value of the magic number. -- John Cowan or UUCP mailers: ...!uunet!hombre!{marob,magpie}!cowan Fidonet (last resort): 1:107/711 Aiya elenion ancalima!