1

I have a case to handle. There is one thread calling WSAPoll() to receive data from TCP connection. The code looks like this:

int result = WSAPoll(fdSocket, 1, timeout);
if (result == 0)
{
    // time out
}
else if (result == -1)
{
    // socket error
}

If I set timeout to be a negative number, the thread will wait indefinitely. However, I want to make this function return a value, such as 0, directly to this thread if I call a function StopWait() from another thread.

So what can I do to make this work? Add an asynchronous procedure call to this blocking thread through function StopWait() bu the other thread? If it is, what to add can make it return the value I want?

Thanks!

goalmad
  • 11
  • 3
  • There is no API to interrupt `WSAPoll()` while it is waiting. It blocks until a socket satisfies the wait or the timeout elapses. So don't use a negative timeout if you want to be able to interrupt it, use a loop with a small timeout instead. Otherwise, you have to use an additional socket, like a UDP socket, that you can signal as needed when you want to interrupt `WSAPoll()` (see [this](http://stackoverflow.com/a/384397/65863)). – Remy Lebeau Aug 13 '15 at 05:30
  • BTW, [`WSAPoll`() is broken](http://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken) (also see [this](http://curl.haxx.se/mail/lib-2012-07/0311.html)). Reported to Microsoft as "Windows 8 Bugs 309411 - WSAPoll does not report failed connections", and Microsoft's response is: "*Won't Fix. The recommendation for now is to **not use the WSAPoll function** it in case you encounter this issue, but rather the other Net-API functions.*" – Remy Lebeau Aug 13 '15 at 05:31
  • 3
    any suggestions for what other net-api function? nobody seems to have a workaround... the conversation always seems to end with that very quote you mention. – stu Sep 18 '17 at 14:35

0 Answers0