I am implementing a simple proxy application in which I always receive data from one end and send to the other end.
In such a case, once I am sure that I am done with receiving all the data from the incoming leg, can I call directly close( ) without calling shutdown( )? If I do so, will close( ) ensure that all the data is delivered to the destination on the outgoing leg and received by the application at the destination?
Or in such a case, is it mandatory that I initiate a shutdown before I initiate a close?
You can.
shutdownis only necessary if you would like to half-close the connection (i.e. read or write end).closedoes in the background what a blockingsenddoes, no more, no less. If that backgroundsendfails though, you will not get any error indication.There is also
SO_LINGERsocket option you can tweak if necessary: