summaryrefslogtreecommitdiff
path: root/src/socketengines/socketengine_select.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-16 00:09:09 -0400
committerAdam <Adam@anope.org>2011-08-16 00:09:09 -0400
commit68e0d99f622f8fef8c5e7e839f5b7487b5a23495 (patch)
treeb2f588b8451f483d794d213faa1e10b3481073d4 /src/socketengines/socketengine_select.cpp
parentf43287f43dfc605e2138ba3bc30a38d40ea2e1c5 (diff)
Fixed select()ing 0 sockets on Windows
Diffstat (limited to 'src/socketengines/socketengine_select.cpp')
-rw-r--r--src/socketengines/socketengine_select.cpp22
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);