summaryrefslogtreecommitdiff
path: root/src/socketengine.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-26 01:43:09 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-26 01:43:09 +0000
commit939cb0ba987f927f1ad900d45f98ba6d8e03e9d4 (patch)
treef35510ff56e01ece2a0417c9a6fbad17fb7acfee /src/socketengine.cpp
parentc8026bc2d73344e1df526f0a80694046efa4b22a (diff)
Clean up SocketEngine interface to allow edge-triggered I/O and sockets that do not force readability.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11760 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r--src/socketengine.cpp64
1 files changed, 49 insertions, 15 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index c0ae3f278..49624481f 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -62,40 +62,74 @@ SocketEngine::~SocketEngine()
{
}
-bool SocketEngine::HasFd(int fd)
+void SocketEngine::SetEventMask(EventHandler* eh, int mask)
{
- if ((fd < 0) || (fd > MAX_DESCRIPTORS))
- return false;
- return ref[fd];
+ eh->event_mask = mask;
}
-EventHandler* SocketEngine::GetRef(int fd)
+void SocketEngine::ChangeEventMask(EventHandler* eh, int change)
{
- if ((fd < 0) || (fd > MAX_DESCRIPTORS))
- return 0;
- return ref[fd];
+ int old_m = eh->event_mask;
+ int new_m = old_m;
+
+ // if we are changing read/write type, remove the previously set bit
+ if (change & FD_WANT_READ_MASK)
+ new_m &= ~FD_WANT_READ_MASK;
+ if (change & FD_WANT_WRITE_MASK)
+ new_m &= ~FD_WANT_WRITE_MASK;
+
+ // if adding a trial read/write, insert it into the set
+ if (change & FD_TRIAL_NOTE_MASK && !(old_m & FD_TRIAL_NOTE_MASK))
+ trials.insert(eh->GetFd());
+
+ new_m |= change;
+ if (new_m == old_m)
+ return;
+
+ eh->event_mask = new_m;
+ OnSetEvent(eh, old_m, new_m);
}
-int SocketEngine::GetMaxFds()
+void SocketEngine::DispatchTrialWrites()
{
- return 0;
+ std::vector<int> working_list;
+ working_list.reserve(trials.size());
+ working_list.assign(trials.begin(), trials.end());
+ trials.clear();
+ for(unsigned int i=0; i < working_list.size(); i++)
+ {
+ int fd = working_list[i];
+ EventHandler* eh = GetRef(fd);
+ if (!eh)
+ continue;
+ int mask = eh->event_mask;
+ eh->event_mask &= ~(FD_ADD_TRIAL_READ | FD_ADD_TRIAL_WRITE);
+ if ((mask & (FD_ADD_TRIAL_READ | FD_READ_WILL_BLOCK)) == FD_ADD_TRIAL_READ)
+ eh->HandleEvent(EVENT_READ, 0);
+ if ((mask & (FD_ADD_TRIAL_WRITE | FD_WRITE_WILL_BLOCK)) == FD_ADD_TRIAL_WRITE)
+ eh->HandleEvent(EVENT_WRITE, 0);
+ }
}
-int SocketEngine::GetRemainingFds()
+bool SocketEngine::HasFd(int fd)
{
- return 0;
+ if ((fd < 0) || (fd > GetMaxFds()))
+ return false;
+ return ref[fd];
}
-int SocketEngine::DispatchEvents()
+EventHandler* SocketEngine::GetRef(int fd)
{
- return 0;
+ if ((fd < 0) || (fd > GetMaxFds()))
+ return 0;
+ return ref[fd];
}
bool SocketEngine::BoundsCheckFd(EventHandler* eh)
{
if (!eh)
return false;
- if ((eh->GetFd() < 0) || (eh->GetFd() > MAX_DESCRIPTORS))
+ if ((eh->GetFd() < 0) || (eh->GetFd() > GetMaxFds()))
return false;
return true;
}