The shutdown function disables the reception of data from a socket, and/or the transmission of data through a socket, and can be used on all types of sockets. The shutdown function does not close the socket. Any resources attached to the socket will not be freed until the closesocket function is called.
To ensure that all data is sent and received on a connected socket before it is closed, your program should use the shutdown function to close the connection before calling the closesocket function to close the socket. For example, to initiate a graceful disconnect:
The system include file WinSock2.inc contains the following declaration for the shutdown function:
function shutdown(s : SOCKET; how : integer) : integer; external dll='ws2_32.dll';
The first argument passed to the shutdown function is the socket that you want to disable, the reception of data from and/or disable the transmission of data through.
The second argument passed to the shutdown function specifies whether you want to disable the receptioin of data, the transmission of data or both, and can have the follow values:
The shutdown function returns a value of integer type that indicates whether the call was successful. A value of zero means that the call succeeded. A value of SOCKET_ERROR indicates that the called failed, and in this case you can use the WSAGetLastError function to retrieve a code that identifies the error that caused the call to fail. NOTE: The constants SO_LINGER, SD_RECEIVE, SD_SEND, SD_BOTH, and SOCKET_ERROR are declared in the system include file WinSock2.inc.
The authoritative source of information about the WinSock2 library is the Microsoft Developers Network (MSDN). You can access the MSDN on the Microsoft website at msdn.microsoft.com.