Search code examples
winsockblockingrecv

Check if data is available before using recv()


Is there a way you can use select() on an single socket, without involving fd_set?

I want to make sure there is something to read before using recv() so it doesn't block. Alternatively use recv() if it immediately can return when there is nothing to read in.


Solution

  • Unfortunately, no.

    The only way to use select() without involving at least one fd_set is to supply 3 nullptrs (NULLs) to select which effectively turns the select call into a sleep using the timeout argument.