Search code examples
multithreadingdelphiwinapiwinsockterminate

What can happen when I forcly terminate thread at Winsock connect function?


What can happen when I use TerminateThread while Winsock connect function is in progress? I need to immediately shutdown the thread which is currently connecting to the socket but I don't know what can happen to the network adapter.

The connect function has unfortunately no timeout parameter and the default system timeout value is too high. So is there any risk to interrupt this API function?

I've used Delphi tag just because I'm writing my application in Delphi, but it's much more Winsock and Windows API question.

Thanks


Solution

  • The only way to abort a connect() call is to close the socket from another thread context. Otherwise, use ConnectEx() with overlapped I/O, like Martin said.