Wednesday, September 21, 2011

when not to use shutdown function

Knowing When Not to Use shutdown(2)

The shutdown(2) function is documented to return the errors shown in Table 1.2.


Given socket is not a valid file descriptor.

Given file descriptor is not a socket.

The specified socket is not connected.

Table 1.2: Possible errors returned by shutdown(2)

From Table 1.2, you can see that you should only call shutdown(2) for connected sockets. Otherwise, the error code ENOTCONN is returned.

The shutdown(2) function does not release the socket's file unit number, even when SHUT_RDWR is used. The socket's file descriptor remains valid and in use until the function close(2) is called to release it. Note also that shutdown(2) can be called more.

No comments:

Post a Comment