For my suggestion, please read the last section: “When to use SO_LINGER with timeout 0”. Before we come to that a little lecture about: Normal TCP termination TIME_WAIT FIN, ACK and RST Normal TCP termination The normal TCP termination sequence looks like this (simplified): We have two peers: A and B A calls close() A sends FIN to B A goes into FIN_WAIT_1 state B receives FIN B sends ACK to A B go
![When is TCP option SO_LINGER (0) required?](https://cdn-ak-scissors.b.st-hatena.com/image/square/98d6f053a97a87156775f60757c60865d0f2c47d/height=288;version=1;width=512/https%3A%2F%2Fcdn.sstatic.net%2FSites%2Fstackoverflow%2FImg%2Fapple-touch-icon%402.png%3Fv%3D73d79a89bded)