diff options
author | Adam <Adam@anope.org> | 2014-01-23 19:17:22 -0500 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-02-04 22:39:12 +0100 |
commit | 3752b3f59d5216d7dc6221a361efc76b9ad2273d (patch) | |
tree | 540ec25c9c643f1739875aa0add1f8a87a334e3c /src/socketengine.cpp | |
parent | d7164e521b2bf961dab531dff3914a17dec88949 (diff) |
New socketengine stuff:
Use vectors that grow as necessary instead of mass allocating everything at once
Rework poll engine logic to make sense
Diffstat (limited to 'src/socketengine.cpp')
-rw-r--r-- | src/socketengine.cpp | 25 |
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]; } |