title: close() socket directly after send(): unsafe?
body: <p>Is it wise/safe to <code>close()</code> a socket directly after the last <code>send()</code>?</p>
  
  <p>I know that TCP is supposed to try to deliver all remaining data in the send buffer even after closing the socket, but can I really count on that?</p>
  
  <p>I'm making sure that there is no remaining data in my receive buffer so that no RST will be sent following my close.</p>
  
  <hr>
  
  <p>In my case, the close is actually the very last statement of code before calling <code>exit()</code>.</p>
  
  <p>Will the TCP stack really continue to try and transmit the data even after the process sending it has terminated? Is that as reliable as waiting for an arbitrary timeout myself before calling <code>close()</code> by setting SO_LINGER?</p>
  
  <p>That is, do the same TCP timeouts apply, or are they shorter? With a big send buffer and a slow connection, the time to actually transfer all the buffered data could be substantial, after all.</p>
  
  <hr>
  
  <p>I'm not interested at all in being notified of the last byte sent; I just want them to eventually arrive at the remote host as reliably as possible.</p>
  
  <p>Application layer acknowledgements are not an option (the protocol is HTTP, and I'm writing a small server).</p>