Just answered the same question here , so copy-paste here in the hope that this will help:
Previously, you could call WSAIsBlocking to determine this. If you are running outdated code, this might be an option.
Otherwise, you can write a simple abstraction layer over the socket API. Since all sockets are blocked by default, you can support the internal flag and force all socket operations through your API so that you always know the state.
Here is a cross-platform snippet to set / get lock mode, although it doesnβt do exactly what you want on Windows:
/// @author Stephen Dunn /// @date 10/12/15 bool set_blocking_mode(const int &socket, bool is_blocking) { bool ret = true;
source share