0

(Working on win32/c++ environment)

I have a function that calls ReadFile (synchronously) with a fixed size of one byte to read from a SOCKET resource (of WINSOCK). There's multiple threads running this function. The data is written to sockets externally, and is not on my control. whenever the data is yet to be written, I find my exe consuming nearly 80% of CPU, and the usage divide relatively equally among the mentioned threads (there are typically 4 of them).

as ReadFile is an OS api, I would have expected it to be implemented asynchronously internally to avoid such as issue. My question is why is this happening, and what can I do to avoid it.

1 Answers1

0

it's been a very long time since I did Win32 programming, but I seem to remember that the ReadFile returns an error when there is no data to read from the socket. It might be returning 0 bytes read, or something.

Zagrev
  • 2,000
  • 11
  • 8