Linux Socket – Clear the flag set by shutdown() systemcall


How to clear the flag set by shutdown() system call in Linux socket program?

I want to enable writes to the socket which is right now locked for writes with a shutdown(sockfd, SHUT_WR) call.


Unfortunately what you ask is impossible.

Issuing shutdown( sockfd, SHUT_WR );, in fact, forces FIN packet to be sent.

Have a look to the TCP state machine:

TCP State Machine

As you can see, when a FIN packet is sent from an active socket (state ESTABLISHED) the state CLOSE_WAIT is reached, and it is a transition that cannot be "undone" in any way.

So it is not a matter of "removing a flag": the socket is set to an irreversible path tha leads to its closure, waiting just for a last ACK to complete its "life".

Answered By – Roberto Caboni

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published