Can a socket be made non-blocking only for the recv() function?
c, c++, sockets, windows
Solution
There is no way to make the socket non-blocking just for the `recv()` function.
However there is something close to that (but flawed), which is by using `ioctlsocket()` with the `FIONREAD` flag. For example:
unsigned long l;
ioctlsocket(s, FIONREAD, &l);
This function will return (immediately without blocking) how many bytes is available to be read, although not quite accurate (but we don't care about that, because we are using it to know if there is data to be read and not to know exactly how many bytes are there).
As I have mentioned earlier, this approach is flawed, because it doesn't tell you when the other end has disconnected, because `recv()` returns `0` on disconnect, and this function will return `0` if no data is available!
Problem
I want to be able to call `recv()` without having to block, so I want to make it non-blocking, but I do not want it to be non blocking when sending data. So can a socket be made non-blocking only for the `recv()` function, or does the blocking/non-blocking mode affects all of the socket functions?