Unix Network Programming Manual
Socket Closing
When a server or client finishes processing, it should execute a close
command on each socket that it has opened. This is simply good
programming practice. However, before closing the socket, you might
want to perform a shutdown. The shutdown indicates to the operating
system that the socket is not to be destroyed, but that its use should
restricted. There are many cases where a client or server
might be ready to terminate, but it does not want to miss any
communications that might come in. The shutdown syntax is:
err = shutdown (socket, how)
int err, socket, how
The how parameter can be 0 to disable all further receives, 1 to
disable all further sends and 2 to disable both sends and receives.
For example, a server might shutdown a socket with a how of 0 so that
the client can no longer send, but the server can send messages
indicating the status of the connection. In example1, a shutdown
value of 1 will stop the client from sending any additional data,
but will still allows receives to be made if there are any.
shutdown returns zero if successful and -1 it there is an error.