[Interest] TCP Graceful shutdown: Socket shutdown() function missing
Jochen Baier
email at jochen-baier.de
Tue Apr 8 19:09:08 CEST 2014
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).aspx
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.
Thanks for any hint, Jochen
More information about the Interest
mailing list