Graceful Shutdown, Linger Options, and Socket Closure
Graceful Shutdown, Linger Options, and Socket Closure - Win32 apps | Microsoft Docs
Graceful Shutdown, Linger Options, and Socket Closure - Win32 apps
Graceful Shutdown, Linger Options, and Socket Closure In this article --> The following material is provided as clarification for the subject of shutting down socket connections closing the sockets. It is important to distinguish the difference between shu
docs.microsoft.com
Shutting down a socket connection involves an exchange of protocol messages between the two endpoints, hereafter referred to as a shutdown sequence. Two general classes of shutdown sequences are defined: graceful and abortive (also called hard). In a graceful shutdown sequence, any data that has been queued, but not yet transmitted can be sent prior to the connection being closed. In an abortive shutdown, any unsent data is lost. The occurrence of a shutdown sequence (graceful or abortive) can also be used to provide an FD_CLOSE indication to the associated applications signifying that a shutdown is in progress.
Closing a socket, on the other hand, causes the socket handle to become deallocated so that the application can no longer reference or use the socket in any manner.
One technique that can be used to minimize the chance of problems occurring during connection teardown is to avoid relying on an implicit shutdown being initiated by closesocket. Instead, use one of the two explicit shutdown functions, shutdown or WSASendDisconnect. This in turn causes an FD_CLOSE indication to be received by the peer application indicating that all pending data has been received.