tags:

views:

267

answers:

3

I'm using a synchronous wininet request and calling InternetReadFileEx() with the IRF_NO_WAIT flag, but the function still blocks waiting for data. Why is that?

A: 

What IRF_NO_WAIT means is to not wait for all of the requested data buffer to be filled. However, it will still wait for some data to arrive. If no data is arriving, it blocks.

+1  A: 

In the MSDN docs, the meaning of IRF_NO_WAIT is described as:

Do not wait for data. If there is data available, the function returns either the amount of data requested or the amount of data available (whichever is smaller).

Mysteriously, it leaves the case where there is not data available undefined. Apparently, if there is no data, it blocks until there is some.

chaos
A: 

A possible workaround is to use InternetQueryOption() to get an INTERNET_DIAGNOSTIC_SOCKET_INFO structure, and then pass the SOCKET handle to ::select() with a timeout of {0, 0} to determine if data is available without blocking.