- fcntl(mImpl.fd, F_SETFL, flags | (value ? O_NONBLOCK : 0));
-#else
- ioctl(mImpl.fd, FIONBIO, value);
+ flags = isBlocking ? (flags & ~O_NONBLOCK) : (flags | O_NONBLOCK);
+ fcntl(mImpl.fd, F_SETFL, flags);
+#elif defined(_WIN32)
+ u_long value = isBlocking;
+ ioctlsocket(mImpl.fd, FIONBIO, &value);