You can interrupt it by queuing an APC to it via QueueUserAPC
. However, it's most likely unsafe to terminate the thread in the APC. Queuing an APC doesn't end the recv
, it just interrupts it; once the APC returns, it will go back to waiting on recv
again.
If you want to stop the recv
completely, you should be using select
with a timeout to wait until data is available. You can then check whether you should keep waiting for data or continue at each timeout.