[Interest] TCP Graceful shutdown: Socket shutdown() function missing

Thiago Macieira thiago.macieira at intel.com
Tue Apr 8 20:02:02 CEST 2014


Em ter 08 abr 2014, às 19:09:08, Jochen Baier escreveu:
> Hi,
> 
> I have to gracefully close a TCP socket on the client side: Send data,
> initialize the finish handshake and wait until the the server has
> finished the handshake. It works without Qt like this:
> 
> Call shutdown with how=SD_SEND.
> Call recv() until the function completes with success and indicates
> zero bytes were received. If SOCKET_ERROR is returned, then the graceful
> disconnect is not possible.
> Call closesocket().
> 
> from:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).as
> px more infos:
> http://blog.netherlabs.nl/articles/2009/01/18/the-ultimate-so_linger-page-or
> -why-is-my-tcp-not-reliable
> 
> I tried it with:
> 
>      disconnectFromHost ();
>      read();
> 
> But this doesn’t work of course. Is this possible with QTcpSocket?
> disconnectFromHost() only uses closesocket(). So if the connnection link
> is lost all functions will still return success but zero data will be send.

QTcpSocket does not use shutdown() anywhere.

disconnectFromHost() will put the socket in Closing state if it still has 
unsent bytes. While it's in that state, the reading end is still active and we 
will receive data. Once the last byte has been sent, we do a full-duplex 
close.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list