mirror of
https://github.com/anope/anope.git
synced 2026-06-29 08:16:39 +02:00
Fixed select()ing 0 sockets on Windows
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user