Why is writing a closed TCP socket worse than reading one?

前端 未结 4 1446
予麋鹿
予麋鹿 2020-11-29 07:02

When you read a closed TCP socket you get a regular error, i.e. it either returns 0 indicating EOF or -1 and an error code in errno which can be printed with pe

4条回答
  •  死守一世寂寞
    2020-11-29 07:39

    Usually if you're writing to a socket, you would expect the other end to be listening. This is sort of like a telephone call - if you're speaking, you wouldn't expect the other party to simply hang up the call.

    If you're reading from a socket, then you're expecting the other end to either (a) send you something, or (b) close the socket. Situation (b) would happen if you've just sent something like a QUIT command to the other end.

提交回复
热议问题