shutdown() — Shut down all or part of a duplex connection

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

X/Open:
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/socket.h>

int shutdown(int socket, int how);
Berkeley sockets:
#define _OE_SOCKETS
#include <sys/socket.h>

long shutdown(int *s, int how);

General description

The shutdown() function shuts down all or part of a duplex connection.
Parameter
Description
socket
The socket descriptor.
how
The condition of the shutdown. The values 0, 1, or 2 set the condition. how sets the condition for shutting down the connection to the socket indicated by socket.
how can have a value of:
  • SHUT_RD, which ends communication from the socket indicated by socket.
  • SHUT_WR, which ends communication to the socket indicated by socket.
  • SHUT_RDWR, which ends communication both to and from the socket indicated by socket.
Note: You should issue a shutdown() call before you issue a close() call for a socket.

Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.

Returned value

If successful, shutdown() returns 0.

If unsuccessful, shutdown() returns -1 and sets errno to one of the following values:
Error Code
Description
EBADF
socket is not a valid socket descriptor.
EINVAL
The how parameter was not set to one of the valid values.
ENOBUFS
Insufficient system resources are available to complete the call.
ENOTCONN
The socket is not connected.
ENOTSOCK
The descriptor is for a file, not for a socket.

Related information