%!Mode:: "TeX:UTF-8"

\section{Socket Error Handling}

\href{http://my.oschina.net/costaxu/blog/127394}{几种TCP连接中出现RST的情况}


\href{http://russelltao.iteye.com/blog/1405349}{从TCP协议的原理来谈谈rst复位攻击}

\subsection{graceful shutdown of sockets}

 It is important to distinguish the difference between \emph{shutting down a
 socket connection} and \emph{closing a socket}.


Shutting down a socket connection involves an exchange of protocol messages between the two endpoints,
hereafter referred to as a shutdown sequence. 
Two general classes of shutdown sequences are defined: graceful and abortive (also called hard).
In a graceful shutdown sequence, any data that has been queued, but not yet transmitted can be sent prior to the connection being closed. 
In an abortive shutdown, any unsent data is lost. 
The occurrence of a shutdown sequence (graceful or abortive) can also be used to provide an FD_CLOSE indication to the associated applications signifying that a shutdown is in progress.

Closing a socket, on the other hand, causes the socket handle to become
deallocated so that the application can no longer reference or use the socket in any manner.


When you have finished using a socket, you can simply close its file descriptor with close. 
If there is still data waiting to be transmitted over the connection, normally close tries to complete this transmission. 
You can control this behavior using the SO\_LINGER socket option to specify a timeout period. 
You can also shut down only reception or transmission on a connection by calling shutdown




