in reply to Named pipes missing connections

hello, It seems like your OS (Linux here) is buffering all successive open-write-close sequences together and lumping all data together that can be read with a single open-read-close sequence. Here is a trace of the system calls for both the writer (first) and the reader (second).
# this is the writer trace # this sequence is repeated 4 times open("tst.fifo", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3 fstat64(3, {st_mode=S_IFIFO|0644, st_size=0, ...}) = 0 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0 fstat64(3, {st_mode=S_IFIFO|0644, st_size=0, ...}) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, +-1, 0) = 0x40016000 write(3, "This is some silly,\n", 20) = 20 close(3) = 0 munmap(0x40016000, 4096) = 0
# this is the reader trace # notice how we got all 82 bytes at one shot write(1, "Opening pipe: ", 14) = 14 open("tst.fifo", O_RDONLY|O_LARGEFILE) = 3 fstat64(3, {st_mode=S_IFIFO|0644, st_size=0, ...}) = 0 fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0 write(1, "got pipe, reading:\n", 19) = 19 fstat64(3, {st_mode=S_IFIFO|0644, st_size=0, ...}) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, +-1, 0) = 0x40017000 read(3, "This is some silly,\nstuff to be "..., 4096) = 82 read(3, "", 4096) = 0 write(1, ": This is some silly,\n", 22) = 22 write(1, ": stuff to be sent\n", 19) = 19 write(1, ": to the pipe where hopefully\n", 30) = 30 write(1, ": it will be read.\n", 19) = 19 write(1, "Pipe done, closing: ", 20) = 20 close(3) = 0 munmap(0x40017000, 4096) = 0 write(1, "done.\n", 6) = 6 write(1, "Taking a long time... ", 22) = 22 time([1009160476]) = 1009160476
So, is this a bug? Dunno, since I'm not familiar with the POSIX specs on pipes.

Hope this helps.

Aziz,,,

Update:

From the pipe(4) man page:

Under Linux, opening a FIFO for read and write will suc? ceed both in blocking and non-blocking mode. POSIX leaves this behaviour undefined. This can be used to open a FIFO for writing while there are no readers available. A pro? cess that uses both ends of the connection in order to communicate with itself should be very careful to avoid deadlocks.
So, I guess under linux, the kernel choses to buffer the input when there are multiple succesive writes to a named pipe.

Hope this helps...

Replies are listed 'Best First'.
(bbfu) (in the OS) Re2: Named pipes missing connections
by bbfu (Curate) on Dec 24, 2001 at 05:21 UTC

    Alas, it seems you are correct and my problem is within the OS. Unfortunately, that means there's not really anything I can do about it, and must look for an alternative solution.

    Ah, well. C'est la vie. Thanks for your help (and termix, as well, for your suggestions)!

    <update>Thanks, premchai21. Never could speel... Especially not French. ;-)</update>

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

      Well, if your data is well structured enough, you could use some sort of delimited, either using $/ or just reading byte-by-byte and determining limits yourself. You then have to make sure that the delimiter never occurs in the data, though.

      Ah, well. Se la vi.

      I believe it's "C'est la vie" -- that's life. :-)