From 117bfa37dee01e4df8820cbc21b1e40305df3ab3 Mon Sep 17 00:00:00 2001 From: peavey Date: Fri, 29 Dec 2006 15:38:04 +0000 Subject: Fix for rehash/load/unload. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6158 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_pgsql.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index eac70714d..7d669137f 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -537,7 +537,9 @@ public: virtual ~ModulePgSQL() { DELETE(sqlsuccess); + ClearConnections(); ServerInstance->UnpublishInterface("SQL", this); + ServerInstance->UnpublishFeature("SQL"); ServerInstance->DoneWithInterface("SQLutils"); } @@ -547,21 +549,24 @@ public: List[I_OnUnloadModule] = List[I_OnRequest] = List[I_OnRehash] = List[I_OnUserRegister] = List[I_OnCheckReady] = List[I_OnUserDisconnect] = 1; } - virtual void OnRehash(const std::string ¶meter) + void ClearConnections() { - ConfigReader conf(ServerInstance); - - /* Delete all the SQLConn objects in the connection lists, - * this will call their destructors where they can handle - * closing connections and such. - */ - for(ConnMap::iterator iter = connections.begin(); iter != connections.end(); iter++) + ConnMap::iterator iter; + while ((iter = connections.begin()) != connections.end()) { + connections.erase(iter); DELETE(iter->second); } + } + + virtual void OnRehash(const std::string ¶meter) + { - /* Empty out our list of connections */ - connections.clear(); + ServerInstance->Log(DEBUG, "<*********> OnRehash parameter: " + parameter); + + ConfigReader conf(ServerInstance); + + ClearConnections(); for(int i = 0; i < conf.Enumerate("database"); i++) { @@ -693,7 +698,6 @@ SQLConn::SQLConn(InspIRCd* SI, ModulePgSQL* self, const SQLhost& hi) Instance->Log(DEBUG,"No need to resolve %s", this->host); - if(!this->DoConnect()) { throw ModuleException("Connect failed"); @@ -764,6 +768,10 @@ void SQLConn::Close() { Instance->Log(DEBUG,"SQLConn::Close"); + if (!this->Instance->SE->DelFd(this)) + { + Instance->Log(DEBUG, "PQsocket cant be removed from the socket engine!"); + } this->fd = -1; this->state = I_ERROR; this->OnError(I_ERR_SOCKET); @@ -774,8 +782,6 @@ void SQLConn::Close() PQfinish(sql); sql = NULL; } - - return; } bool SQLConn::DoPoll() @@ -1239,4 +1245,4 @@ class ModulePgSQLFactory : public ModuleFactory extern "C" void * init_module( void ) { return new ModulePgSQLFactory; -} +i} -- cgit v1.2.3