diff options
Diffstat (limited to 'src/socketengines/socketengine_select.cpp')
-rw-r--r-- | src/socketengines/socketengine_select.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index 99a0fefe1..34a86f680 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -1,12 +1,14 @@ #include "module.h" static int MaxFD; +static unsigned FDCount; static fd_set ReadFDs; static fd_set WriteFDs; void SocketEngine::Init() { MaxFD = 0; + FDCount = 0; FD_ZERO(&ReadFDs); FD_ZERO(&WriteFDs); } @@ -22,10 +24,6 @@ void SocketEngine::Shutdown() delete s; } Sockets.clear(); - - MaxFD = 0; - FD_ZERO(&ReadFDs); - FD_ZERO(&WriteFDs); } void SocketEngine::AddSocket(Socket *s) @@ -34,6 +32,7 @@ void SocketEngine::AddSocket(Socket *s) MaxFD = s->GetFD(); FD_SET(s->GetFD(), &ReadFDs); Sockets.insert(std::make_pair(s->GetFD(), s)); + ++FDCount; } void SocketEngine::DelSocket(Socket *s) @@ -43,6 +42,7 @@ void SocketEngine::DelSocket(Socket *s) FD_CLR(s->GetFD(), &ReadFDs); FD_CLR(s->GetFD(), &WriteFDs); Sockets.erase(s->GetFD()); + --FDCount; } void SocketEngine::MarkWritable(Socket *s) @@ -68,6 +68,20 @@ void SocketEngine::Process() tval.tv_sec = Config->ReadTimeout; tval.tv_usec = 0; +#ifdef _WIN32 + /* We can use the socket engine to "sleep" services for a period of + * time between connections to the uplink, which allows modules, + * timers, etc to function properly. Windows, being as useful as it is, + * does not allow to select() on 0 sockets and will immediately return error. + * Thus: + */ + if (FDCount == 0) + { + sleep(Config->ReadTimeout); + return; + } +#endif + int sresult = select(MaxFD + 1, &rfdset, &wfdset, &efdset, &tval); Anope::CurTime = time(NULL); |