Hello,
in my winsock server program I use the following codes to send something to the client-end:
ioctlsocket(fd,...); // Enable the blocking mode. The fd attribute is inheritted from the main fd in the main listener set by non-blocking mode
setsockopt(fd,...); // 3 lines of codes, to set time-out for recv() / send(), and "LINGER" mode with time-out for closesocket()
send(fd,...);
send(fd,...);
...
Sleep(100); // I have to set this before closesocket()
closesocket(fd);
--------------------------
If I don't the "Sleep()", sometimes the client-end may can't receive all data and lost connection under an unstable state. If I always use it, everything looks smooth but it causes the thread delaying a little to exit. In some other places, I always needn't use it before closesocket() to avoid such issue. however in those codes, I just send more or less data without any setting changed during the transmitting.
This issue bores me and I can't find out the answer. Please feel free to comment. Thanks!