Testing for a closed socket

后端 未结 3 1170
北荒
北荒 2021-01-04 19:45

I\'m trying to test for a closed socket that has been gracefully closed by the peer without incurring the latency hit of a double send to induce a SIGPIPE.

3条回答
  •  [愿得一人]
    2021-01-04 19:59

    OK, so I ran some more tests and this is what I found.

    I set my client up to send HTTP/1.1 Connection: close messages to the server causing the server to call close after it's last write of data. When my client finished reading data from a GET transaction it would test the socket to see if it was still open using the above method and then attempt to issue another GET.

    What I found is that approximately 30% of the time my test would occur before the server's FIN arrived leading to false-positives and failed operations.

    Probably the only way to make this reasonably reliable, say close to 99% would be to introduce artificial delays related to the connection latency between the last read and the attempted socket reuse - however, that would pretty much murder performance.

    So, I have to conclude that while this tool is useful, it's only marginally so.

提交回复
热议问题