From: peavey Date: Fri, 9 May 2008 20:44:31 +0000 (+0000) Subject: Same fixes to make this module scale much better. Dont connect on each query, keep... X-Git-Tag: v2.0.23~3201 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=9dadbc294e952c69c8bf502a4387ef39ac1f5d01;p=user%2Fhenk%2Fcode%2Finspircd.git Same fixes to make this module scale much better. Dont connect on each query, keep open and send a byte like MySQL module. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9687 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index deff0fe06..8c191381a 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -16,7 +16,6 @@ #include "users.h" #include "channels.h" #include "modules.h" - #include "m_sqlv2.h" /* $ModDesc: sqlite3 provider */ @@ -34,7 +33,8 @@ typedef std::deque paramlist; typedef std::deque ResultQueue; ResultNotifier* resultnotify = NULL; - +ResultNotifier* resultdispatch = NULL; +int QueueFD = -1; class ResultNotifier : public BufferedSocket { @@ -73,7 +73,18 @@ class ResultNotifier : public BufferedSocket virtual int OnIncomingConnection(int newsock, char* ip) { - Dispatch(); + resultdispatch = new ResultNotifier(Instance, mod, newsock, ip); + return true; + } + + virtual bool OnDataReady() + { + char data = 0; + if (Instance->SE->Recv(this, &data, 1, 0) > 0) + { + Dispatch(); + return true; + } return false; } @@ -427,32 +438,36 @@ class SQLConn : public classbase void SendNotify() { - int QueueFD; - if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1) + if (QueueFD < 0) { - /* crap, we're out of sockets... */ - return; - } + if ((QueueFD = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1) + { + /* crap, we're out of sockets... */ + return; + } - insp_sockaddr addr; + insp_sockaddr addr; #ifdef IPV6 - insp_aton("::1", &addr.sin6_addr); - addr.sin6_family = AF_FAMILY; - addr.sin6_port = htons(resultnotify->GetPort()); + insp_aton("::1", &addr.sin6_addr); + addr.sin6_family = AF_FAMILY; + addr.sin6_port = htons(resultnotify->GetPort()); #else - insp_inaddr ia; - insp_aton("127.0.0.1", &ia); - addr.sin_family = AF_FAMILY; - addr.sin_addr = ia; - addr.sin_port = htons(resultnotify->GetPort()); + insp_inaddr ia; + insp_aton("127.0.0.1", &ia); + addr.sin_family = AF_FAMILY; + addr.sin_addr = ia; + addr.sin_port = htons(resultnotify->GetPort()); #endif - if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1) - { - /* wtf, we cant connect to it, but we just created it! */ - return; + if (connect(QueueFD, (sockaddr*)&addr,sizeof(addr)) == -1) + { + /* wtf, we cant connect to it, but we just created it! */ + return; + } } + char id = 0; + send(QueueFD, &id, 1, 0); } }; @@ -488,11 +503,24 @@ class ModuleSQLite3 : public Module { ClearQueue(); ClearAllConnections(); - resultnotify->SetFd(-1); - resultnotify->state = I_ERROR; - resultnotify->OnError(I_ERR_SOCKET); - resultnotify->ClosePending = true; - delete resultnotify; + + ServerInstance->SE->DelFd(resultnotify); + resultnotify->Close(); + ServerInstance->BufferedSocketCull(); + + if (QueueFD >= 0) + { + shutdown(QueueFD, 2); + close(QueueFD); + } + + if (resultdispatch) + { + ServerInstance->SE->DelFd(resultdispatch); + resultdispatch->Close(); + ServerInstance->BufferedSocketCull(); + } + ServerInstance->Modules->UnpublishInterface("SQL", this); ServerInstance->Modules->UnpublishFeature("SQL"); ServerInstance->Modules->DoneWithInterface("SQLutils"); @@ -653,4 +681,3 @@ void ResultNotifier::Dispatch() } MODULE_INIT(ModuleSQLite3) -