diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-07 18:31:21 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-07 18:31:21 +0000 |
commit | 61fed23a3e9a62f19c2f88208585b31356c986ef (patch) | |
tree | 1b87a0cade91abc4347785879b8506276732f702 | |
parent | f7bfee1e9210b83d0cb544ce14aa52f8637bdf21 (diff) |
Start moving IO hooking from being bufferedsocket based to residing in EventHandler, this will pave the way for a generic listener type, and also simplifies a lot of code.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10447 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/configreader.h | 24 | ||||
-rw-r--r-- | include/socket.h | 2 | ||||
-rw-r--r-- | include/socketengine.h | 20 | ||||
-rw-r--r-- | src/configreader.cpp | 31 | ||||
-rw-r--r-- | src/socketengine.cpp | 21 |
5 files changed, 43 insertions, 55 deletions
diff --git a/include/configreader.h b/include/configreader.h index 5e437d153..af9c33533 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -607,10 +607,6 @@ class CoreExport ServerConfig : public Extensible */ std::vector<ListenSocket*> ports; - /** socket objects that are attached to by modules - */ - std::map<BufferedSocket*, Module*> SocketIOHookModule; - /** The 005 tokens of this server (ISUPPORT) * populated/repopulated upon loading or unloading * modules. @@ -823,26 +819,6 @@ class CoreExport ServerConfig : public Extensible void ValidateNoSpaces(const char* p, const std::string &tag, const std::string &val); - /** Get a pointer to the module which has hooked the given BufferedSocket class. - * @parameter port Port number - * @return Returns a pointer to the hooking module, or NULL - */ - Module* GetIOHook(BufferedSocket* is); - - /** Hook a module to an BufferedSocket class, so that it can receive notifications - * of low-level socket activity. - * @param iomod The module to hook to the socket - * @param is The BufferedSocket to attach to - * @return True if the hook was successful. - */ - bool AddIOHook(Module* iomod, BufferedSocket* is); - - /** Delete a module hook from an BufferedSocket. - * @param is The BufferedSocket to detatch from. - * @return True if the unhook was successful - */ - bool DelIOHook(BufferedSocket* is); - /** Returns the fully qualified path to the inspircd directory * @return The full program directory */ diff --git a/include/socket.h b/include/socket.h index a26c1256d..105984f74 100644 --- a/include/socket.h +++ b/include/socket.h @@ -139,6 +139,8 @@ namespace irc } } + + /** This class handles incoming connections on client ports. * It will create a new User for every valid connection * and assign it a file descriptor. diff --git a/include/socketengine.h b/include/socketengine.h index f16ec3fea..127a2fd90 100644 --- a/include/socketengine.h +++ b/include/socketengine.h @@ -68,8 +68,28 @@ class CoreExport EventHandler : public Extensible * other forms of IPC. */ int fd; + + /** Pointer to the module which has hooked the given EventHandler for IO events. + */ + Module *IOHook; public: + /** Return the current hooker of IO events for this socket, or NULL. + * @return Hooker module, if set, or NULL. + */ + Module *GetIOHook(); + + /** Set a module as hooking IO events on this socket. + * @param IOHooker The module hooking IO + * @return True if the hook could be added, false otherwise. + */ + bool AddIOHook(Module *IOHooker); + + /** Remove IO hooking from a module + * @return True if hooking was successfully removed, false otherwise. + */ + bool DelIOHook(); + /** Get the current file descriptor * @return The file descriptor of this handler */ diff --git a/src/configreader.cpp b/src/configreader.cpp index 1e8e0a7e9..cce362ed2 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -65,37 +65,6 @@ void ServerConfig::ClearStack() include_stack.clear(); } -Module* ServerConfig::GetIOHook(BufferedSocket* is) -{ - std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is); - return (x != SocketIOHookModule.end() ? x->second : NULL); -} - -bool ServerConfig::AddIOHook(Module* iomod, BufferedSocket* is) -{ - if (!GetIOHook(is)) - { - SocketIOHookModule[is] = iomod; - is->IsIOHooked = true; - return true; - } - else - { - throw ModuleException("BufferedSocket derived class already hooked by another module"); - } -} - -bool ServerConfig::DelIOHook(BufferedSocket* is) -{ - std::map<BufferedSocket*,Module*>::iterator x = SocketIOHookModule.find(is); - if (x != SocketIOHookModule.end()) - { - SocketIOHookModule.erase(x); - return true; - } - return false; -} - void ServerConfig::Update005() { std::stringstream out(data005); diff --git a/src/socketengine.cpp b/src/socketengine.cpp index c7188b55a..74f8c1861 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -41,6 +41,27 @@ #include "inspircd.h" #include "socketengine.h" +bool EventHandler::AddIOHook(Module *IOHooker) +{ + if (this->IOHook) + return false; + + this->IOHook = IOHooker; +} + +bool EventHandler::DelIOHook() +{ + if (!this->IOHook) + return false + + this->IOHook = false; +} + +Module *EventHandler::GetIOHook() +{ + return this->IOHook; +} + int EventHandler::GetFd() { return this->fd; |