diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-08 20:34:31 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-09-08 20:34:31 +0000 |
commit | b745471954b542170cc20e69dc049ff8d027da6c (patch) | |
tree | 3ce60a5e9d653e3a47ee7c5ca3144e43a2e1dab3 /src | |
parent | e2175e1b1a215010be1c3b960610c849c6090718 (diff) |
(Attempt to) convert MySQL to using listener base.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10473 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/extra/m_mysql.cpp | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 5e5e97113..9f9db7595 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -72,7 +72,7 @@ class Notifier; typedef std::map<std::string, SQLConnection*> ConnMap; -static Notifier* MessagePipe = NULL; +static MySQLListener *MessagePipe = NULL; int QueueFD = -1; class DispatcherThread; @@ -657,33 +657,34 @@ class DispatcherThread : public Thread virtual void Run(); }; -/** Used by m_mysql to notify one thread when the other has a result +/** Spawn HTTP sockets from a listener */ -class Notifier : public BufferedSocket +class MySQLListener : public ListenSocketBase { - insp_sockaddr sock_us; - socklen_t uslen; - ModuleSQL* Parent; + FileReader* index; public: - - /* Create a socket on a random port. Let the tcp stack allocate us an available port */ -#ifdef IPV6 - Notifier(InspIRCd* SI, ModuleSQL* Creator) : BufferedSocket(SI, "::1", 0, true, 3000), Parent(Creator) -#else - Notifier(InspIRCd* SI, ModuleSQL* Creator) : BufferedSocket(SI, "127.0.0.1", 0, true, 3000), Parent(Creator) -#endif + HttpListener(InspIRCd* Instance, int port, char* addr) : ListenSocketBase(Instance, port, addr) { - uslen = sizeof(sock_us); - if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen)) - { - throw ModuleException("Could not create random listening port on localhost"); - } + this->index = idx; } - Notifier(InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip) + virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip) { + new Notifier(this->ServerInstance, nfd, (char)ipconnectedto.c_str()); // XXX unsafe casts suck } +}; + +/** Used by m_mysql to notify one thread when the other has a result + */ +class Notifier : public BufferedSocket +{ + insp_sockaddr sock_us; + socklen_t uslen; + ModuleSQL* Parent; + + public: + Notifier(InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip) { } /* Using getsockname and ntohs, we can determine which port number we were allocated */ int GetPort() @@ -695,13 +696,6 @@ class Notifier : public BufferedSocket #endif } - virtual int OnIncomingConnection(int newsock, char* ip) - { - Notifier* n = new Notifier(this->Instance, newsock, ip); - n = n; /* Stop bitching at me, GCC */ - return true; - } - virtual bool OnDataReady() { char data = 0; @@ -745,6 +739,16 @@ ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false) MessagePipe = new Notifier(ServerInstance, this); + /* Create a socket on a random port. Let the tcp stack allocate us an available port */ +#ifdef IPV6 + MessagePipe = new MySQLListener(SI, 0, "::1"); +#else + MessagePipe = new MySQLListener(SI, 0, "127.0.0.1"); +#endif + + if (MessagePipe->GetFd()) + throw ModuleException("m_mysql: unable to create ITC pipe"); + Dispatcher = new DispatcherThread(ServerInstance, this); ServerInstance->Threads->Create(Dispatcher); |