Blocking pipes and reading whole message at once looks ok to me.
But, think on this, pipes are just buffers, usually 4K at each end; and data is not passed to the reading process until a full 4K is available. (And setting line buffering won't change that.)
This is easily demonstrated. The following code writes 122 byte lines every tenth of a second, but you will see no output for 3.35 seconds because that's how long it takes to fill the 4k buffer. It then produces batches of lines every 3.35 seconds until the writer closes the pipe:
perl -E"select('','','',0.1),say 'test'x30 for 1 ..200" | perl -ple1
And if your messages are not some exact multiple of 4K, the last line of every 4k block will be a partial message, and your wrapper will therefore block until the next 4k block has been filled and passed through, before that message will be completed.
|Replies are listed 'Best First'.|
Re^4: sysread/syswrite wrappers
by vsespb (Chaplain) on Oct 12, 2016 at 14:44 UTC