summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-05-09 20:44:31 +0000
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-05-09 20:44:31 +0000
commit9dadbc294e952c69c8bf502a4387ef39ac1f5d01 (patch)
treed72ce721824bea2647d99504e41251b774994824
parent1d12db188a7bf836e7bbec0f15de018daa9d4c6e (diff)
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
-rw-r--r--src/modules/extra/m_sqlite3.cpp81
1 files changed, 54 insertions, 27 deletions
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<classbase*> paramlist;
typedef std::deque<SQLite3Result*> 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)
-