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.
This commit is contained in:
parent
f0894e9d35
commit
02ab3634c4
@ -2,6 +2,7 @@
|
|||||||
// Created by fred on 09/12/16.
|
// Created by fred on 09/12/16.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
#include "frnetlib/SocketSelector.h"
|
#include "frnetlib/SocketSelector.h"
|
||||||
|
|
||||||
namespace fr
|
namespace fr
|
||||||
@ -27,6 +28,16 @@ namespace fr
|
|||||||
|
|
||||||
bool SocketSelector::wait(std::chrono::milliseconds timeout)
|
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;
|
timeval wait_time;
|
||||||
wait_time.tv_sec = 0;
|
wait_time.tv_sec = 0;
|
||||||
wait_time.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
|
wait_time.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(timeout).count();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user