+ ServerInstance->Modules->UseInterface("SQLutils");
+
+ Conf = new ConfigReader(ServerInstance);
+ PublicServerInstance = ServerInstance;
+ currid = 0;
+ SQLModule = this;
+
+ MessagePipe = new Notifier(ServerInstance);
+
+ pthread_attr_t attribs;
+ pthread_attr_init(&attribs);
+ pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE);
+ if (pthread_create(&this->Dispatcher, &attribs, DispatcherThread, (void *)this) != 0)
+ {
+ throw ModuleException("m_mysql: Failed to create dispatcher thread: " + std::string(strerror(errno)));
+ }
+ pthread_attr_destroy(&attribs);
+
+ if (!ServerInstance->Modules->PublishFeature("SQL", this))
+ {
+ /* Tell worker thread to exit NOW */
+ int rc;
+ void *status;
+ giveup = true;
+ rc = pthread_join(Dispatcher, &status);
+ if (rc)
+ {
+ ServerInstance->Logs->Log("m_mysql",DEFAULT,"SQL: Error code from pthread_join() is %d", rc);
+ }
+ throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
+ }
+
+ ServerInstance->Modules->PublishInterface("SQL", this);
+ Implementation eventlist[] = { I_OnRehash, I_OnRequest };
+ ServerInstance->Modules->Attach(eventlist, this, 2);
+ }
+
+ virtual ~ModuleSQL()
+ {
+ int rc;
+ void *status;
+ giveup = true;
+ rc = pthread_join(Dispatcher, &status);
+ if (rc)
+ {
+ ServerInstance->Logs->Log("m_mysql",DEFAULT,"SQL: Error code from pthread_join() is %d", rc);
+ }
+ ClearAllConnections();
+ delete Conf;
+ ServerInstance->Modules->UnpublishInterface("SQL", this);
+ ServerInstance->Modules->UnpublishFeature("SQL");
+ ServerInstance->Modules->DoneWithInterface("SQLutils");