fifo - reading in a loop

后端 未结 2 1925
失恋的感觉
失恋的感觉 2021-02-20 18:52

I want to use os.mkfifo for simple communication between programs. I have a problem with reading from the fifo in a loop.

Consider this toy example, where I have a reade

2条回答
  •  北海茫月
    2021-02-20 19:32

    A FIFO works (on the reader side) exactly this way: it can be read from, until all writers are gone. Then it signals EOF to the reader.

    If you want the reader to continue reading, you'll have to open again and read from there. So your snippet is exactly the way to go.

    If you have mutliple writers, you'll have to ensure that each data portion written by them is smaller than PIPE_BUF on order not to mix up the messages.

提交回复
热议问题