I asked the other day if data integrity (of flushed data) is kept
even when there are more than one PIPEs streaming into
localhost’s STDIN. The answer is NO if the data flushed is large.
Data integrity question when collecting STDOUTs from multiple remote hosts over SSH
But I would like to guarantee every line flushed on each end is
passed to the single STDIN in full and won’t be mixed up with
data from other pipes. Is there any way to do so? How can that be done?
(Note that it can be done if I create multiple STDINs locally.
But it is more convenient if I can process line streams through a
single STDIN. So my question focuses on the case when there is
only one STDIN at localhost with multiple (STDOUT) PIPEs into it.)
This can be done via a congestion-backoff system like that used in Ethernet.
First, assign each pipe a unique delimiter. This delimiter cannot appear unescaped in the contents of any pipe. Now, use the following pseudocode:
This will ensure that, although you will have some junk, every whole message will eventually get through.