i am learning to use SO_SNDTIMEO and SO_RCVTIMEO to check the timeout. It is easy to use with read socket. But when i want to check write timeout, it always return successful. Here is what i did:(all in blocking mode)
- close the client read socket and exit before server start write
- terminate the client before server start write
- unplug the cable of server after accept but before write
well, it seems all these case write just return sucessfully. I think the reason should be that port is resource managed by os, and at the client side, after program gone, the tcp connection still shows FIN_WAIT2 state.
so, is there any convenient way to simulate some cases that write can receive errors such as EPIPE, EAGAIN?