X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_mysql.cpp;h=2449b523866292ff0fa606216b37dca05db07b91;hb=59bd18f2a0b43b71ee32124add9d40d1d3a54919;hp=fe23eee8c60ae3baf4556f28ba5c62ccfdce0fd2;hpb=86f87784985faf4ec73b8dd9b0de61aca44461b3;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index fe23eee8c..2449b5238 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -594,9 +594,19 @@ void ConnectDatabases(InspIRCd* ServerInstance) } } +void ClearDatabases() +{ + ConnMap::iterator i; + while ((i = Connections.begin()) != Connections.end()) + { + Connections.erase(i); + delete i->second; + } +} + void LoadDatabases(ConfigReader* ThisConf, InspIRCd* ServerInstance) { - Connections.clear(); + ClearDatabases(); for (int j =0; j < ThisConf->Enumerate("database"); j++) { std::string db = ThisConf->ReadValue("database","name",j); @@ -715,6 +725,47 @@ class ModuleSQL : public Module pthread_t Dispatcher; int currid; + ModuleSQL(InspIRCd* Me) + : Module::Module(Me) + { + ServerInstance->UseInterface("SQLutils"); + + Conf = new ConfigReader(ServerInstance); + PublicServerInstance = ServerInstance; + currid = 0; + SQLModule = this; + + MessagePipe = new Notifier(ServerInstance); + ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",MessagePipe->GetPort()); + + pthread_attr_t attribs; + pthread_attr_init(&attribs); + pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED); + if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0) + { + throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno))); + } + + if (!ServerInstance->PublishFeature("SQL", this)) + { + /* Tell worker thread to exit NOW */ + giveup = true; + throw ModuleException("m_mysql: Unable to publish feature 'SQL'"); + } + + ServerInstance->PublishInterface("SQL", this); + } + + virtual ~ModuleSQL() + { + giveup = true; + ClearDatabases(); + DELETE(Conf); + ServerInstance->UnpublishInterface("SQL", this); + ServerInstance->DoneWithInterface("SQLutils"); + } + + void Implements(char* List) { List[I_OnRehash] = List[I_OnRequest] = 1; @@ -764,38 +815,6 @@ class ModuleSQL : public Module return NULL; } - ModuleSQL(InspIRCd* Me) - : Module::Module(Me) - { - - Conf = new ConfigReader(ServerInstance); - PublicServerInstance = ServerInstance; - currid = 0; - SQLModule = this; - - MessagePipe = new Notifier(ServerInstance); - ServerInstance->Log(DEBUG,"Bound notifier to 127.0.0.1:%d",MessagePipe->GetPort()); - - pthread_attr_t attribs; - pthread_attr_init(&attribs); - pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED); - if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0) - { - throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno))); - } - if (!ServerInstance->PublishFeature("SQL", this)) - { - /* Tell worker thread to exit NOW */ - giveup = true; - throw ModuleException("m_mysql: Unable to publish feature 'SQL'"); - } - } - - virtual ~ModuleSQL() - { - DELETE(Conf); - } - virtual void OnRehash(const std::string ¶meter) { /* TODO: set rehash bool here, which makes the dispatcher thread rehash at next opportunity */