summaryrefslogtreecommitdiff
path: root/src/socketengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r--src/socketengine.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp
index 219d154f2..c2a357b38 100644
--- a/src/socketengine.cpp
+++ b/src/socketengine.cpp
@@ -94,16 +94,33 @@ void SocketEngine::DispatchTrialWrites()
}
}
-bool SocketEngine::HasFd(int fd)
+bool SocketEngine::AddFd(EventHandler* eh)
{
- if ((fd < 0) || (fd > GetMaxFds()))
+ int fd = eh->GetFd();
+ if (HasFd(fd))
return false;
- return (ref[fd] != NULL);
+
+ while (static_cast<unsigned int>(fd) >= ref.size())
+ ref.resize(ref.empty() ? 1 : (ref.size() * 2));
+ ref[fd] = eh;
+ return true;
+}
+
+void SocketEngine::DelFd(EventHandler *eh)
+{
+ int fd = eh->GetFd();
+ if (GetRef(fd) == eh)
+ ref[fd] = NULL;
+}
+
+bool SocketEngine::HasFd(int fd)
+{
+ return GetRef(fd) != NULL;
}
EventHandler* SocketEngine::GetRef(int fd)
{
- if ((fd < 0) || (fd > GetMaxFds()))
+ if (fd < 0 || static_cast<unsigned int>(fd) >= ref.size())
return 0;
return ref[fd];
}