What causes the ENOTCONN error?

前端 未结 5 1214
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 05:20

I\'m currently maintaining some web server software and I need to perform a lot of I/O operations. The read(), write(), close() and

5条回答
  •  生来不讨喜
    2021-02-01 05:59

    It's because, at the moment of shutting() the socket, you have data in the socket's buffer waiting to be delivered to the remote party which has closed() or shutted down() its receiving socket. I don't finish understanding how sockets work, I am rather a noob, and I've failed to even find the files where this "shutdown" function is implemented, but seeing that there's practically no user manual for the whole sockets thing I started trying all possibilities until I got the error in a "controlled" environment. It could be something else, but after much trying these are the explanations I settled for:

    • If you sent data after the remote side closed the connection, when you shutdown(), you get the error.
    • If you sent data before the remote side closed the connection but it didn't get received() on the other end, you can shutdown() once, the next time you try to shutdown(), you get the error.
    • If you didn't send any data, you can shutdown all the times you want, as long as the remote side doesn't shutdown(); once the remote side has shutdown(), if you try to shutdown() and the socket was already shutdown(), you get the error.

提交回复
热议问题