Search code examples
clinuxsocketstcp

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.


Solution

  • 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".