Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S


HP-UX 11i Version 3: February 2007

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index


shutdown — shut down a socket


#include <sys/socket.h>

int shutdown(int s, int how);


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.



SHUT_RD or 0

Further receives are disallowed

SHUT_WR or 1

Further sends are disallowed


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 condition. 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 sockets, if how is 1 or 2, the connection begins to be closed gracefully in addition to the normal actions. However, the shutdown() call does not wait for the completion of the graceful disconnection. 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. 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.


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.

X/Open Sockets Compilation Environment

See xopen_networking(7).


Upon successful completion, shutdown() returns 0; otherwise it returns -1 and errno is set to indicate the error.


shutdown() fails if any of the following conditions are encountered:


s is not a valid file descriptor.


The remote system or an intermediate system in the communications path does not support a protocol option sent by the local system. This option may have been set using a getsockopt or setsockopt() call, or set as a system parameter.


s is a valid file descriptor, but it is not a socket.


HP-UX BSD Sockets only. The specified socket is not connected.


X/Open Sockets only. The specified socket is not connected.


X/Open Sockets only. The how argument is invalid.


Linking binary objects compiled to X/Open Sockets specification and binary objects compiled to HP-UX BSD Sockets specification to the same executable may result in unexpected behavior, including application abnormal termination and unexpected socket errors. See xopen_networking(7) for details and remedy.


Currently, the default behavior is the HP-UX BSD Sockets; however, it might be changed to X/Open Sockets in a future release. At that time, any HP-UX BSD Sockets behavior that is incompatible with X/Open Sockets might be obsoleted. Applications that conform to the X/Open specification now will avoid migration problems (see xopen_networking(7)).


shutdown() was developed by HP and the University of California, Berkeley.


shutdown(): XPG4, UNIX 95, UNIX 03

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.