Why does the read end of a pipe read EOF only if the write end is closed?

后端 未结 2 1823
予麋鹿
予麋鹿 2021-01-02 17:32

I don\'t really understand the difference between \"closing the write end of the pipe\" and \"not writing anything to the pipe\". If I don\'t write anything to the pipe and

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 17:53

    Reading an EOF from a pipe (or from anything) indicates that there's no more input, and that there won't be any more input in the future.

    If there's no input available at the moment, but the pipe hasn't been closed, then the reader will (by default) block waiting for input; if the writer then writes to the pipe, that data will become available to the reader. An EOF would tell the reader to stop trying to read any more data.

提交回复
热议问题