I have some code that seems to not handle it well when a TCP connection is closed via the RST flag instead of a normal handshake for closing the connection. The “connection reset by peer” situation. I’d like to write a TCP server that always closes via RST so that I can reproduce the bug and write some unit tests for this. So…
How do I send a RST instead of a normal close, for testing?
You can get a RST by modifying your SO_LINGER setting. You want l_onoff set to non-zero and l_linger set to zero. Once you do that, closing the socket will cause a reset.