From 02ab3634c486340af1beeae78c9ad323bba636f3 Mon Sep 17 00:00:00 2001 From: Cloaked9000 Date: Fri, 6 Jan 2017 16:15:04 +0000 Subject: [PATCH] Fixed Windows SocketSelector Exception In Windows, if fr::SocketSelector::wait(...) was called, and the socket selector was empty, then an exception would be thrown as a result of Windows behaving differently to UNIX sockets. Now, the call will sleep for timeout before returning false, to match UNIX behaviour. --- src/SocketSelector.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/SocketSelector.cpp b/src/SocketSelector.cpp index de12a8d..75d4a0e 100644 --- a/src/SocketSelector.cpp +++ b/src/SocketSelector.cpp @@ -2,6 +2,7 @@ // Created by fred on 09/12/16. // +#include #include "frnetlib/SocketSelector.h" namespace fr @@ -27,6 +28,16 @@ namespace fr bool SocketSelector::wait(std::chrono::milliseconds timeout) { + //Windows will crash if we pass an empty set. Do a check. +#ifdef _WIN32 + if(listen_set.fd_count == 0) + { + //It's empty. Emulate UNIX behaviour by sleeping for timeout. + std::this_thread::sleep_for(timeout); + return false; + } +#endif + timeval wait_time; wait_time.tv_sec = 0; wait_time.tv_usec = std::chrono::duration_cast(timeout).count();