Chapter 7, Developing applications over TCP/IP using Internet sockets
Closing sockets and discarding queued data (Internet domain)

Closing sockets and discarding queued data (Internet domain)

A process can discard a socket that is no longer of use by calling close(S):

   close(s);
If data is associated with a stream socket, which promises reliable delivery, the system continues to attempt to transfer the data. Data still undelivered after a long period of time is discarded. A client process can abort cause all data queued for transfer to be discarded immediately by calling shutdown(SSC) on the socket before closing it:

shutdown(s, how);

The variable how is one of:

0
if the user no longer wishes to read data

1
if no more data will be sent

2
if no data is to be sent or received.