* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * InspIRCd: (C) 2002-2008 InspIRCd Development Team
* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
/* $CompileFlags: exec("mysql_config --include") */
/* $LinkerFlags: exec("mysql_config --libs_r") rpath("mysql_config --libs_r") */
/* $ModDep: m_sqlv2.h */
+/* $NoPedantic */
/* THE NONBLOCKING MYSQL API!
*
typedef std::map<std::string, SQLConnection*> ConnMap;
bool giveup = false;
+bool threadfinished = false;
static Module* SQLModule = NULL;
static Notifier* MessagePipe = NULL;
int QueueFD = -1;
int rows;
public:
- MySQLresult(Module* self, Module* to, MYSQL_RES* res, int affected_rows, unsigned int id) : SQLresult(self, to, id), currentrow(0), fieldmap(NULL)
+ MySQLresult(Module* self, Module* to, MYSQL_RES* res, int affected_rows, unsigned int rid) : SQLresult(self, to, rid), currentrow(0), fieldmap(NULL)
{
/* A number of affected rows from from mysql_affected_rows.
*/
}
}
- MySQLresult(Module* self, Module* to, SQLerror e, unsigned int id) : SQLresult(self, to, id), currentrow(0)
+ MySQLresult(Module* self, Module* to, SQLerror e, unsigned int rid) : SQLresult(self, to, rid), currentrow(0)
{
rows = 0;
error = e;
{
if (!HostInConf(conf, i->second->GetConfHost()))
{
- DELETE(i->second);
+ delete i->second;
safei = i;
--i;
Connections.erase(safei);
while ((i = Connections.begin()) != Connections.end())
{
Connections.erase(i);
- DELETE(i->second);
+ delete i->second;
}
}
{
/* XXX: MUTEX */
pthread_mutex_lock(&logging_mutex);
- ServerInstance->Log(DEFAULT,"SQL: Failed to connect database "+i->second->GetHost()+": Error: "+i->second->GetError());
+ ServerInstance->Logs->Log("m_mysql",DEFAULT,"SQL: Failed to connect database "+i->second->GetHost()+": Error: "+i->second->GetError());
i->second->SetEnable(false);
pthread_mutex_unlock(&logging_mutex);
}
/** Used by m_mysql to notify one thread when the other has a result
*/
-class Notifier : public InspSocket
+class Notifier : public BufferedSocket
{
insp_sockaddr sock_us;
socklen_t uslen;
/* Create a socket on a random port. Let the tcp stack allocate us an available port */
#ifdef IPV6
- Notifier(InspIRCd* SI) : InspSocket(SI, "::1", 0, true, 3000)
+ Notifier(InspIRCd* SI) : BufferedSocket(SI, "::1", 0, true, 3000)
#else
- Notifier(InspIRCd* SI) : InspSocket(SI, "127.0.0.1", 0, true, 3000)
+ Notifier(InspIRCd* SI) : BufferedSocket(SI, "127.0.0.1", 0, true, 3000)
#endif
{
uslen = sizeof(sock_us);
}
}
- Notifier(InspIRCd* SI, int newfd, char* ip) : InspSocket(SI, newfd, ip)
+ Notifier(InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip)
{
}
ModuleSQL(InspIRCd* Me)
: Module::Module(Me), rehashing(false)
{
- ServerInstance->UseInterface("SQLutils");
+ ServerInstance->Modules->UseInterface("SQLutils");
Conf = new ConfigReader(ServerInstance);
PublicServerInstance = ServerInstance;
pthread_attr_t attribs;
pthread_attr_init(&attribs);
- pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_DETACHED);
+ 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->PublishFeature("SQL", this))
+ 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 " + rc);
+ }
throw ModuleException("m_mysql: Unable to publish feature 'SQL'");
}
- ServerInstance->PublishInterface("SQL", this);
+ 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 " + rc);
+ }
ClearAllConnections();
- DELETE(Conf);
- ServerInstance->UnpublishInterface("SQL", this);
- ServerInstance->UnpublishFeature("SQL");
- ServerInstance->DoneWithInterface("SQLutils");
+ delete Conf;
+ ServerInstance->Modules->UnpublishInterface("SQL", this);
+ ServerInstance->Modules->UnpublishFeature("SQL");
+ ServerInstance->Modules->DoneWithInterface("SQLutils");
}
- void Implements(char* List)
- {
- List[I_OnRehash] = List[I_OnRequest] = 1;
- }
unsigned long NewID()
{
return ++currid;
}
- char* OnRequest(Request* request)
+ virtual const char* OnRequest(Request* request)
{
if(strcmp(SQLREQID, request->GetId()) == 0)
{
ConnMap::iterator iter;
- char* returnval = NULL;
+ const char* returnval = NULL;
if((iter = Connections.find(req->dbid)) != Connections.end())
{
return NULL;
}
- virtual void OnRehash(userrec* user, const std::string ¶meter)
+ virtual void OnRehash(User* user, const std::string ¶meter)
{
rehashing = true;
}
/* XXX: Unlock */
}
- usleep(50);
+ usleep(1000);
}
- return NULL;
+ pthread_exit((void *) 0);
}
-MODULE_INIT(ModuleSQL);
-
+MODULE_INIT(ModuleSQL)