Wednesday, September 21, 2011

shutdown function in socket

socket shutdown (2) function

The following shows the function synopsis of the shutdown(2) function:

#include <sys/socket.h>
int shutdown(int s, int how);

The function shutdown(2) requires two arguments. They are
  • Socket descriptor s specifies the socket to be partially shut down. 
  • Argument how indicates how this socket should be shut down.
The returned value is zero if the function call succeeded. A failure is indicated by returning a value of -1, and the reason for the failure is posted to errno.

The permissible values for how are shown in Table 1.1.

Value
Macros
Description
0
SHUT_RD
No further reads will be allowed on the specified socket.
1
SHUT_WR
No further writes will be allowed on the specified socket.
2
SHUT_RDWR
No further reads or writes will be allowed on the specified socket.
Table 1.1: Permissible Values of the shutdown(2) how Argument
Value Macro Description

Notice that when the how value is supplied as 2, this function call becomes almost equivalent to a close(2) call.

No comments:

Post a Comment