shutdown.2 (2010 09)

s
shutdown(2) shutdown(2)
NAME
shutdown() - shut down a socket
SYNOPSIS
#include <sys/socket.h>
int shutdown(int s, int how);
DESCRIPTION
The shutdown() system call is used to shut down a socket. In the case of a full-duplex connection,
shutdown() can be used to either partially or fully shut down the socket, depending upon the value of
how.
how Interpretation
SHUT_RD or 0 Further receives are disallowed
SHUT_WR or 1 Further sends are disallowed
SHUT_RDWR or 2 Further sends and receives are disallowed
The s parameter is a socket descriptor for the socket to be shut down.
Once the socket has been shut down for receives, all further
recv() calls return an end-of-file condi-
tion. A socket that has been shut down for sending causes further
send() calls to return an [EPIPE]
error and send the
SIGPIPE signal. After a socket has been fully shut down, operations other than
recv() and send() return appropriate errors, and the only other thing that can be done to the socket
is a close().
Multiple shutdowns on a connected socket and shutdowns on a socket that is not connected may not
return errors.
A
shutdown() on a connectionless socket, such as
SOCK_DGRAM, only marks the socket as unable to
do further
send() or recv() calls, depending upon the value of how. Once this type of socket has
been disabled for both sending and receiving data, it becomes fully shut down. For SOCK_STREAM
sock-
ets, if how is
1 or 2, the connection begins to be closed gracefully in addition to the normal actions. How-
ever, the shutdown() call does not wait for the completion of the graceful disconnection. The discon-
nection 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. The
SO_LINGER option (see socket (2)) does not have any meaning for the shutdown() call, but does for
the close() call. For more information on how the close() call interacts with sockets, see socket (2).
If a
shutdown() is performed on a SOCK_STREAM socket that has a listen() pending on it, that
socket becomes fully shut down when how = 1.
AF_CCITT only
The how parameter behaves differently if the socket is of the
AF_CCITT address family. If how is set to
0, the specified socket can no longer receive data. The SVC is not cleared and remains intact. However,
if data is subsequently received on the SVC, it is cleared. The connection is not completely down until
either side executes a close() or shutdown() with how set to 1 or 2.
If how is set to
1 or 2, the SVC can no longer send or receive data and the SVC is cleared. The socket’s
resources are maintained so that data arriving prior to the shutdown() call can still be read.
SCTP Only:
SCTP differs from TCP in that SCTP does not have half closed semantics. Hence the
shutdown() call
for SCTP is an approximation of the TCP shutdown() call and solves some different problems. Full
TCP-compatibility is not provided, so developers porting TCP applications to SCTP may need to re-code
sections that use shutdown(). You can achieve the same results as half closed semantics in SCTP by
using SCTP streams.
These are the possible SCTP
shutdown() operations:
SHUT_RD Disables further receive operations. No SCTP protocol action is taken.
SHUT_WR Disables further send operations and initiates the SCTP shutdown sequence.
SHUT_RDWR Disables further send and receive operations and initiates the SCTP shutdown
sequence.
The major difference between SCTP and TCP
shutdown() is that SCTP SHUT_WR initiates immediate
and full protocol shutdown, whereas TCP SHUT_WR causes TCP to go into the half closed state.
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)