This call should return after only a very short time, but on some machines it inexplicably takes very close to 1 second. Has anyone seen this issue. I am using the loopback address so the network should be out of the picture.
Asked
Active
Viewed 1,091 times
3
-
1Perhaps anti-virus / firewall software is interfering? – Harry Johnston Apr 05 '12 at 06:18
-
Not very useful antivirus / firewall software if it just adds a delay. I have my firewall turned off and no resident shield running for virus checker. Same behaviour. – Jesse Pepper Apr 05 '12 at 06:53
-
Some AV and security products have a tendency to introduce buggy behaviour. If you're otherwise stuck, it might be worth uninstalling them all - while off the network, of course! - to double-check. – Harry Johnston Apr 06 '12 at 04:34
-
By the same token, of course, the problem might be that the machines in question are infected with some form of malware. – Harry Johnston Apr 06 '12 at 04:37
1 Answers
0
The problem is probably somewhere inside the window sockets implementation. From the OS perspective calling closesocket
(or CloseHandle
) equivalent to releasing driver's "device" object. Mostly drivers process this request immediately (synchronously), aborting all the (potential) outstanding I/Os if necessary. However "silly" drivers may block you until something is completed.
That's what I'd do:
- Try to terminate your program (by task manager). Does it take time to terminate it? (if so - seems it's locked by the driver).
- If you're talking about stream socket (i.e. TCP or similar) - try to use
SO_DONTLINGER
option. That is, specify that you don't want to wait until all the pending data is sent to the peer.

valdo
- 12,632
- 2
- 37
- 67
-
It's a bit hard to tell if it takes 1 second to terminate the process using the task manager since there are other delays. SO_DONTLINGER shouldn't have any effect in this particular case, because no data is being sent over the socket, it just gets established and then closed down. SO_DONTLINGER is for waiting until all data is sent. – Jesse Pepper Apr 05 '12 at 14:40
-
@Jesse Pepper: Apart from sending an unsent data, in TCP there's a "ceremony" of closing a connection gracefully, which includes some ping-pong with `FIN` packets. I'm not sure, but maybe `SO_DONTLINGER` includes this as well. I.e. with this flag it aborts the connection with `RST` – valdo Apr 05 '12 at 16:02