WinSock closesocket() call takes one second on some computers

1k views Asked by At

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.

1

There are 1 answers

2
valdo On

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.