Delphi-Cross-Socket
Delphi-Cross-Socket copied to clipboard
Very slow shutdown when connection attempt running
Using the cross-socket on the client-side, I noticed that the shutdown (StopLoop) hangs for several seconds when there is at least 1 connection attempt running.
This is because the sockets that are trying to connect do not receive the TSocketAPI.CloseSocket in StopLoop, because it is not yet in the list of FConnections, which will only be added after a successful connection, but not during attempts. So basically StopLoop is waiting for the timeout of this connection attempt to finish completely (and this can be several seconds).
My tests were done only at IOCP, so I don't know if the same problem occurs on Epoll or Kqueue.
There are several solutions to this, one of which would be to add the sockets created in Connect to an FConnectionsAttempt list and remove them at the end of the attempt and then override CloseAll to add the TSocketAPI.CloseSocket to each socket of FConnectionsAttempt.