Implement OnUnloadModule for postgres

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12627 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2010-03-13 01:41:35 +00:00
parent 11e45f2cb7
commit 1efedf9743
2 changed files with 36 additions and 14 deletions

View File

@ -1069,7 +1069,7 @@
# m_mssql.so is more complex than described here, see wiki for more # # m_mssql.so is more complex than described here, see wiki for more #
# info http://wiki.inspircd.org/Modules/mssql # # info http://wiki.inspircd.org/Modules/mssql #
# #
#<database name="db" username="user" password="pass" hostname="localhost" id="db1"> #<database module="mssql" name="db" username="user" password="pass" hostname="localhost" id="db1">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# MySQL module: Allows other SQL modules to access MySQL databases # 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 # # m_mysql.so is more complex than described here, see the wiki for #
# more: http://wiki.inspircd.org/Modules/mysql # # more: http://wiki.inspircd.org/Modules/mysql #
# #
#<database name="mydb" username="myuser" password="mypass" hostname="localhost" id="my_database2"> #<database module="mysql" name="mydb" username="myuser" password="mypass" hostname="localhost" id="my_database2">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Named Modes module: This module allows for the display and set/unset # 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 # # m_pgsql.so is more complex than described here, see the wiki for #
# more: http://wiki.inspircd.org/Modules/pgsql # # more: http://wiki.inspircd.org/Modules/pgsql #
# #
#<database name="mydb" username="myuser" password="mypass" hostname="localhost" id="my_database" ssl="no"> #<database module="pgsql" name="mydb" username="myuser" password="mypass" hostname="localhost" id="my_database" ssl="no">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# Muteban: Implements extended ban m:, which stops anyone matching # 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 # # m_sqlite.so is more complex than described here, see the wiki for #
# more: http://wiki.inspircd.org/Modules/sqlite3 # # more: http://wiki.inspircd.org/Modules/sqlite3 #
# #
#<database hostname="/full/path/to/database.db" id="anytext"> #<database module="sqlite" hostname="/full/path/to/database.db" id="anytext">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# SQLutils module: Provides some utilities to SQL client modules, such # SQLutils module: Provides some utilities to SQL client modules, such

View File

@ -124,19 +124,16 @@ class PgSQLresult : public SQLResult
*/ */
class SQLConn : public SQLProvider, public EventHandler class SQLConn : public SQLProvider, public EventHandler
{ {
private: public:
reference<ConfigTag> conf; /* The <database> entry */ reference<ConfigTag> conf; /* The <database> entry */
std::deque<SQLQuery*> queue; std::deque<SQLQuery*> queue;
PGconn* sql; /* PgSQL database connection handle */ PGconn* sql; /* PgSQL database connection handle */
SQLstatus status; /* PgSQL database connection status */ SQLstatus status; /* PgSQL database connection status */
SQLQuery* qinprog; /* If there is currently a query in progress */ 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) SQLConn(Module* Creator, ConfigTag* tag)
: SQLProvider(Creator, "SQL/" + tag->getString("id")), conf(tag), sql(NULL), status(CWRITE), qinprog(NULL) : SQLProvider(Creator, "SQL/" + tag->getString("id")), conf(tag), sql(NULL), status(CWRITE), qinprog(NULL)
{ {
idle = ServerInstance->Time();
if (!DoConnect()) if (!DoConnect())
{ {
ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id")); ServerInstance->Logs->Log("m_pgsql",DEFAULT, "WARNING: Could not connect to database " + tag->getString("id"));
@ -274,11 +271,6 @@ restart:
if (PQconsumeInput(sql)) 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)) if (PQisBusy(sql))
{ {
/* Nothing happens here */ /* 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 class ModulePgSQL : public Module
{ {
public: public:
@ -555,7 +554,30 @@ class ModulePgSQL : public Module
void OnUnloadModule(Module* mod) 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<SQLQuery*>::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() Version GetVersion()