views:

47

answers:

1

Before disconnect the client, the server wants to send some info to the client - why do I(server) disconnect you(client).

If I send packet to the info and close the client socket immediately, closesocket() returns -1 and if I use linger option to work closesocket() successfully, the info cannot be sent completely.

How can I complete this and is it possible to know socket buffer is empty(means my packet sent all)?

thx.

+1  A: 

try to call shutdown() on socket first.

http://msdn.microsoft.com/en-us/library/ms740481%28VS.85%29.aspx

http://www.opengroup.org/onlinepubs/000095399/functions/shutdown.html

zed_0xff
Yes, do shutdown() before close(). I noticed long time ago, when it comes to windows docs about this the often forget shutdown(). While the linux docs talk about the importance.
jpyllman
if i call shutdown() and closesocket() immediately, both return -1. asynchronous socket and TCP.
Hongseok Yoon
@xopht, if you read the first link from zed_0xff you will see you have to wait for all to finish. There are two ways to do it according to that link.
jpyllman