diff options
author | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-05-09 20:35:37 +0000 |
---|---|---|
committer | peavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-05-09 20:35:37 +0000 |
commit | 1d12db188a7bf836e7bbec0f15de018daa9d4c6e (patch) | |
tree | e462b0003f554b3dcbba01a7a30410a996c444a6 | |
parent | 9a6a031fc30617a0932af27b21bdc613625cbf0e (diff) |
Fixes to make this module scale much better. Dont connect on each query, keep open and send a byte like MySQL module. Now with cleanup of bufferedsocket thanks to w00t <3
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9686 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modules/extra/m_mssql.cpp | 79 |
1 files changed, 54 insertions, 25 deletions
diff --git a/src/modules/extra/m_mssql.cpp b/src/modules/extra/m_mssql.cpp index 03f83b5a1..972130396 100644 --- a/src/modules/extra/m_mssql.cpp +++ b/src/modules/extra/m_mssql.cpp @@ -33,7 +33,8 @@ typedef std::deque<classbase*> paramlist; typedef std::deque<MsSQLResult*> ResultQueue; ResultNotifier* resultnotify = NULL; - +ResultNotifier* resultdispatch = NULL; +int QueueFD = -1; class ResultNotifier : public BufferedSocket { @@ -72,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; } @@ -561,32 +573,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); } }; @@ -622,11 +638,24 @@ class ModuleMsSQL : 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"); |