- return i;
- }
- }
- return 0;
-}
-
-ConnMap::iterator GetCharId(char id)
-{
- char i = 1;
- for (ConnMap::iterator iter = Connections.begin(); iter != Connections.end(); ++iter, ++i)
- {
- if (i == id)
- return iter;
- }
- return Connections.end();
-}
-
-void NotifyMainThread(SQLConnection* connection_with_new_result)
-{
- /* Here we write() to the socket the main thread has open
- * and we connect()ed back to before our thread became active.
- * The main thread is using a nonblocking socket tied into
- * the socket engine, so they wont block and they'll receive
- * nearly instant notification. Because we're in a seperate
- * thread, we can just use standard connect(), and we can
- * block if we like. We just send the connection id of the
- * connection back.
- *
- * NOTE: We only send a single char down the connection, this
- * way we know it wont get a partial read at the other end if
- * the system is especially congested (see bug #263).
- * The function FindCharId translates a connection name into a
- * one character id, and GetCharId translates a character id
- * back into an iterator.
- */
- char id = FindCharId(connection_with_new_result->GetID());
- send(QueueFD, &id, 1, 0);
-}
-
-class ModuleSQL;
-
-class DispatcherThread : public Thread
-{
- private:
- ModuleSQL* Parent;
- InspIRCd* ServerInstance;
- public:
- DispatcherThread(InspIRCd* Instance, ModuleSQL* CreatorModule) : Thread(), Parent(CreatorModule), ServerInstance(Instance) { }
- ~DispatcherThread() { }
- virtual void Run();
-};
-
-/** Used by m_mysql to notify one thread when the other has a result
- */
-class Notifier : public BufferedSocket
-{
- ModuleSQL* Parent;
-
- public:
- Notifier(ModuleSQL* P, InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip), Parent(P) { }
-
- virtual bool OnDataReady()
- {
- char data = 0;
- /* NOTE: Only a single character is read so we know we
- * cant get a partial read. (We've been told that theres
- * data waiting, so we wont ever get EAGAIN)
- * The function GetCharId translates a single character
- * back into an iterator.
- */
- if (Instance->SE->Recv(this, &data, 1, 0) > 0)
- {
- ConnMap::iterator iter = GetCharId(data);
- if (iter != Connections.end())