diff options
author | Adam <Adam@anope.org> | 2012-05-23 15:09:41 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-05-23 15:09:41 -0400 |
commit | bf7d1a55afd4e082813e995fd967ad1dae8df26d (patch) | |
tree | 550696d1c6c3e56e52fdea08c925f877c76b0dc1 /modules/database/db_sql.cpp | |
parent | 1f73e27870d4d08b5c5d1644b817437ece3bc65a (diff) |
Fixed some problems found by Robby
Diffstat (limited to 'modules/database/db_sql.cpp')
-rw-r--r-- | modules/database/db_sql.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index ef272c3f0..b4b81375c 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -58,6 +58,7 @@ class DBSQL : public Module, public Pipe SQLSQLInterface sqlinterface; Anope::string prefix; std::set<dynamic_reference<Serializable> > updated_items; + bool shutting_down; void RunBackground(const SQLQuery &q, SQLInterface *iface = NULL) { @@ -81,16 +82,16 @@ class DBSQL : public Module, public Pipe } public: - DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this) + DBSQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sql("", ""), sqlinterface(this), shutting_down(false) { this->SetAuthor("Anope"); - Implementation i[] = { I_OnReload, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate }; + Implementation i[] = { I_OnReload, I_OnShutdown, I_OnRestart, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); this->OnReload(); } - + void OnNotify() anope_override { for (std::set<dynamic_reference<Serializable> >::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it) @@ -125,6 +126,17 @@ class DBSQL : public Module, public Pipe this->prefix = config.ReadValue("db_sql", "prefix", "anope_db_", 0); } + void OnShutdown() anope_override + { + this->shutting_down = true; + this->OnNotify(); + } + + void OnRestart() anope_override + { + this->OnShutdown(); + } + EventReturn OnLoadDatabase() anope_override { if (!this->sql) @@ -167,6 +179,8 @@ class DBSQL : public Module, public Pipe void OnSerializableConstruct(Serializable *obj) anope_override { + if (this->shutting_down) + return; this->updated_items.insert(obj); this->Notify(); } @@ -178,7 +192,7 @@ class DBSQL : public Module, public Pipe void OnSerializableUpdate(Serializable *obj) anope_override { - if (obj->IsTSCached()) + if (this->shutting_down || obj->IsTSCached()) return; obj->UpdateTS(); this->updated_items.insert(obj); |