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


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

 int shutdown(int socket_descriptor,
              int how)

  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes



  UNIX 98 Compatible Syntax
  #define _XOPEN_SOURCE 520
  #include <sys/socket.h>

 int shutdown(int socket_descriptor,
              int how)

  Service Program Name: QSOSRV1

  Default Public Authority: *USE

  Threadsafe: Yes


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

There are two versions of the API, as shown above. The base i5/OS API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.


Parameters

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

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

Authorities

No authorization is required.


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:

  • The socket pointed to by the socket_descriptor parameter is using a connection-oriented transport service. Also, the transport service is in a state in which sends and receives are disallowed (for example, connection has been reset by peer).

  • The how parameter specifies a value that is not valid.
Start of change [ENOTCONN] The specified descriptor does not reference a connected socket. End of change

[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

Message ID Error Message Text
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. Start of change If the socket is being shared across multiple processes, any blocking input operations are deblocked by this action.End of change

  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. Start of change 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]. End of change

  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() on socket connected through a SOCKS server is not supported.

  5. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the shutdown() API is mapped to qso_shutdown98().

Related Information



API introduced: V3R1
Top | UNIX-Type APIs | APIs by category