From 1efedf9743fefe8269c2bcd292306de06a1b615e Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 13 Mar 2010 01:41:35 +0000 Subject: [PATCH] Implement OnUnloadModule for postgres git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12627 e03df62e-2008-0410-955e-edbf42e46eb7 --- docs/modules.conf.example | 8 +++---- src/modules/extra/m_pgsql.cpp | 42 ++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/docs/modules.conf.example b/docs/modules.conf.example index 3e405dcd3..1bd91c293 100644 --- a/docs/modules.conf.example +++ b/docs/modules.conf.example @@ -1069,7 +1069,7 @@ # m_mssql.so is more complex than described here, see wiki for more # # info http://wiki.inspircd.org/Modules/mssql # # -# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # MySQL module: Allows other SQL modules to access MySQL databases @@ -1085,7 +1085,7 @@ # m_mysql.so is more complex than described here, see the wiki for # # more: http://wiki.inspircd.org/Modules/mysql # # -# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Named Modes module: This module allows for the display and set/unset @@ -1328,7 +1328,7 @@ # m_pgsql.so is more complex than described here, see the wiki for # # more: http://wiki.inspircd.org/Modules/pgsql # # -# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Muteban: Implements extended ban m:, which stops anyone matching @@ -1680,7 +1680,7 @@ # m_sqlite.so is more complex than described here, see the wiki for # # more: http://wiki.inspircd.org/Modules/sqlite3 # # -# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # SQLutils module: Provides some utilities to SQL client modules, such diff --git a/src/modules/extra/m_pgsql.cpp b/src/modules/extra/m_pgsql.cpp index 85d092241..735ca2f5a 100644 --- a/src/modules/extra/m_pgsql.cpp +++ b/src/modules/extra/m_pgsql.cpp @@ -124,19 +124,16 @@ class PgSQLresult : public SQLResult */ class SQLConn : public SQLProvider, public EventHandler { - private: + public: reference conf; /* The entry */ std::deque queue; PGconn* sql; /* PgSQL database connection handle */ SQLstatus status; /* PgSQL database connection status */ SQLQuery* qinprog; /* If there is currently a query in progress */ - time_t idle; /* Time we last heard from the database */ - public: SQLConn(Module* Creator, ConfigTag* tag) : SQLProvider(Creator, "SQL/" + tag->getString("id")), conf(tag), sql(NULL), status(CWRITE), qinprog(NULL) { - idle = ServerInstance->Time(); if (!DoConnect()) { ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id")); @@ -274,11 +271,6 @@ restart: if (PQconsumeInput(sql)) { - /* We just read stuff from the server, that counts as it being alive - * so update the idle-since time :p - */ - idle = ServerInstance->Time(); - if (PQisBusy(sql)) { /* Nothing happens here */ @@ -487,6 +479,13 @@ restart: } }; +class DummyQuery : public SQLQuery +{ + public: + DummyQuery(Module* me) : SQLQuery(me, "") {} + void OnResult(SQLResult& result) {} +}; + class ModulePgSQL : public Module { public: @@ -555,7 +554,30 @@ class ModulePgSQL : public Module void OnUnloadModule(Module* mod) { - // TODO cancel queries that will have a bad vtable + SQLerror err(SQL_BAD_DBID); + for(ConnMap::iterator i = connections.begin(); i != connections.end(); i++) + { + SQLConn* conn = i->second; + if (conn->qinprog && conn->qinprog->creator == mod) + { + conn->qinprog->OnError(err); + delete conn->qinprog; + conn->qinprog = new DummyQuery(this); + } + std::deque::iterator j = conn->queue.begin(); + while (j != conn->queue.end()) + { + SQLQuery* q = *j; + if (q->creator == mod) + { + q->OnError(err); + delete q; + j = conn->queue.erase(j); + } + else + j++; + } + } } Version GetVersion() -- 2.39.5