Is there a way to detect that TCP socket has been closed by the remote peer, without reading from it?

前端 未结 6 1430
灰色年华
灰色年华 2020-12-09 17:27

First, a little background to explain the motivation: I\'m working on a very simple select()-based TCP \"mirror proxy\", that allows two firewalled clients to talk to each

6条回答
  •  执笔经年
    2020-12-09 17:54

    It appears the answer to my question is "no, not unless you are willing and able to modify your TCP stack to get access to the necessary private socket-state information".

    Since I'm not able to do that, my solution was to redesign the proxy server to always read data from all clients, and throw away any data that arrives from a client whose partner hasn't connected yet. This is non-optimal, since it means that the TCP streams going through the proxy no longer have the stream-like property of reliable in-order delivery that TCP-using programs expect, but it will suffice for my purpose.

提交回复
热议问题