summaryrefslogtreecommitdiff
path: root/src/socketengine_select.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-18 10:07:22 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-18 10:07:22 +0000
commit56cec38f3e7d3447b40076481c15e6d4a7e278d0 (patch)
tree92968b972ec14350326ad067842369cc6be7871e /src/socketengine_select.cpp
parent77a4fbd1c430767beb4ae8ac1b886d66c361f60e (diff)
Get rid of SocketEngine::Wait and array-copy, change to SocketEngine::DispatchEvents
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4944 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socketengine_select.cpp')
-rw-r--r--src/socketengine_select.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/socketengine_select.cpp b/src/socketengine_select.cpp
index ec242b76d..e0e47b8eb 100644
--- a/src/socketengine_select.cpp
+++ b/src/socketengine_select.cpp
@@ -92,14 +92,16 @@ int SelectEngine::GetRemainingFds()
return FD_SETSIZE - CurrentSetSize;
}
-int SelectEngine::Wait(EventHandler** fdlist)
+int SelectEngine::DispatchEvents()
{
int result = 0;
+ timeval tval;
+ int sresult = 0;
+ EventHandler* ev[MAX_DESCRIPTOR];
FD_ZERO(&wfdset);
FD_ZERO(&rfdset);
- timeval tval;
- int sresult;
+
for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
{
if (ref[a->second]->Readable())
@@ -120,10 +122,23 @@ int SelectEngine::Wait(EventHandler** fdlist)
for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++)
{
if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset)))
- fdlist[result++] = ref[a->second];
+ {
+ ev[result++] = ref[a->second];
+ }
}
}
+ /** An event handler may remove its own descriptor from the list, therefore it is not
+ * safe to directly iterate over the list and dispatch events there with STL iterators.
+ * Thats a shame because it makes this code slower and more resource intensive, but maybe
+ * the user should stop using select(), as select() smells anyway.
+ */
+ for (int i = 0; i < result; i++)
+ {
+ ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ev[i]->Readable() ? "read" : "write", ev[i]->GetFd());
+ ev[i]->HandleEvent(ev[i]->Readable() ? EVENT_READ : EVENT_WRITE);
+ }
+
return result;
}