Description |
![](../../img/s.gif) |
The shutdown system call is used to shut down
a socket. The s parameter is the socket descriptor of the socket
to be shut down. In the case of a full-duplex connection, shutdown
can be used to either partially or fully shut down the socket, depending
on the value of how.
If how=0, the socket can still send data, but it cannot receive
data. Remaining data can be sent and new data can be sent; however,
all further recv() calls return an end-of-file condition.
If how=1, further sends by the user will return an EPIPE error. A
SIGPIPE signal will be sent to the user unless the user has used ioctl()
to ignore the signal. Note that data already queued by a previous
send call will still be sent.
If how=2, a socket cannot send remaining or new data or receive
data. This is the same as doing a shutdown of 0 and a shutdown of
1 simultaneously.
Once the socket has been shut down for receives, all further recv
calls return an end-of-file condition.
A shutdown on a connection-less socket, such as SOCK_DGRAM,
only marks the socket unable to do further sends or receives, depending
on how. Once this type of socket has been disabled for both
sending and receiving data, it becomes fully shut down.
For SOCK_STREAM sockets, if how is 1 or 2, the
connection begins a graceful disconnect. The disconnection is complete
when both sides of the connection have done a shutdown
with how equal to 1 or 2. Once the connection has been completely
terminated, the socket becomes fully shut down.
Note the difference between the close and shutdown
calls. Close makes the socket descriptor invalid while
shutdown is used to partially or fully shutdown the I/O
on the socket. The user can call close after a shutdown
to make the socket descriptor unusable. The SO_LINGER option does
not have any meaning for the shutdown call, but does
for the close call. (Refer to setsockopt.)
Return Value |
![](../../img/s.gif) |
If the call is successful, a 0 is returned. If it fails, a -1 is returned,
and an error code is stored in errno.