shutdown()--End Receiving and/or Sending of Data on Socket


Syntax
#include <sys/types.h>
#include <sys/socket.h>

int shutdown(int socket_descriptor,
             int how)


Threadsafe: Yes

The shutdown() function is used to disable reading, writing, or reading and writing on a socket.

Parameters

socket_descriptor
(Input) The descriptor of the socket to be shut down.

how
(Input) The data flow path to be disabled:
0
No more data can be received.
1
No more data can be sent.
2
No more data can be sent or received.

Return Value

shutdown() returns an integer. Possible values are:

Error Conditions

When shutdown() fails, errno can be set to one of the following:

[EBADF]
Descriptor not valid.
[EINVAL]
Parameter not valid.

This error code indicates one of the following:

[ENOTSOCK]
The specified descriptor does not reference a socket.
[EIO]
Input/output error.
[EUNATCH]
The protocol required to support the specified address family is not available at this time.

Note: This errno is not returned if the how parameter is 0.

[EUNKNOWN]
Unknown system state.

Error Messages

CPE3418 E
Possible APAR condition or hardware failure.
CPF9872 E
Program or service program &1 in library &2 ended. Reason code &3.
CPFA081 E
Unable to set return value or error code.

Usage Notes

  1. Issuing a shutdown() with a how parameter of 0 causes any new data received for the socket to be discarded. Any input functions for this socket complete with a 0, meaning that end-of-file has been reached. On a BSD implementation, if the socket is being shared across multiple processes, any blocking input operations are deblocked by this action. However, the OS/400 sockets implementation of shutdown() does not cause these blocked functions to be deblocked.

  2. Issuing a shutdown() with a how parameter of 1 results in all output functions being failed with an error of [EPIPE]. The process issuing the output operation will receive a synchronous SIGPIPE signal. This also sends a normal close sequence to the partner program. Receive operations issued by the partner program receive a return value of 0 once all previous data has been received. On a BSD implementation, if the socket is being shared across multiple processes or threads, any blocking output functions are deblocked with a return value of -1 and an error code of [EPIPE]. However, the OS/400 sockets implementation of shutdown() does not cause these blocked functions to be deblocked.

  3. Issuing a shutdown() with a how parameter of 2 results in the actions listed for a how parameter of 0 being performed first, followed by the actions listed for a how parameter of 1.

  4. Issuing a shutdown() with a how parameter of 1 or 2 has the same effect as using AF_NS SPX. The connection will be taken down.

  5. Issuing a shutdown() on socket connected through a SOCKS server is not supported.

Related Information
close()--Close File or Socket Descriptor


Top | Sockets APIs | APIs by category


[Information Center Home Page | Feedback ] [Legal | AS/400 Glossary]