The Windows Sockets shutdown function disables sends and/or receives on a socket.

int shutdown (


int how




[in] A descriptor identifying a socket.


[in] A flag that describes what types of operation will no longer be allowed.


is used on all types of sockets to disable reception, transmission, or both.

If how is SD_RECEIVE, subsequent receives on the socket will be disallowed. This has no effect on the lower protocol layers. For TCP sockets, if there is still data queued on the socket waiting to be received, or data arrives subsequently, the connection is reset, since the data cannot be delivered to the user. For UDP sockets, incoming datagrams are accepted and queued. In no case will an ICMP error packet be generated.

If how is SD_SEND, subsequent sends are disallowed. For TCP sockets, a FIN will be sent.

Setting how to SD_BOTH disables both sends and receives as described above.

Note that shutdown does not close the socket, and resources attached to the socket will not be freed until closesocket is invoked.

To assure that all data is sent and received on a connected socket before it is closed, an application should use shutdown to close connection before calling closesocket. For example, to initiate a graceful disconnect, an application could:

  1. call WSAAsyncSelect to register for FD_CLOSE notification,

  2. call shutdown with how=SD_SEND,

  3. when FD_CLOSE received, call recv until zero returned, or SOCKET_ERROR, and

  4. call closesocket,


does not block regardless of the SO_LINGER setting on the socket.

An application should not rely on being able to re-use a socket after it has been shut down. In particular, a Windows Sockets provider is not required to support the use of connect on such a socket.

Return Values

If no error occurs, shutdown returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Error Codes

A successful WSAStartup must occur before using this function.
The network subsystem has failed.
how is not valid, or is not consistent with the socket type, for example, SD_SEND is used with a UNI_RECV socket type.
The descriptor is not a socket.

See Also

, socket

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database