-};
-
-/** 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 (ServerInstance->SE->Recv(this, &data, 1, 0) > 0)
- {
- Parent->ConnMutex.Lock();
- ConnMap::iterator iter = GetCharId(data);
- Parent->ConnMutex.Unlock();
- if (iter != Connections.end())
- {
- Parent->ResultsMutex.Lock();
- ResultQueue::iterator n = iter->second->rq.begin();
- Parent->ResultsMutex.Unlock();
-
- (*n)->Send();
- delete (*n);
-
- Parent->ResultsMutex.Lock();
- iter->second->rq.pop_front();
- Parent->ResultsMutex.Unlock();
-
- return true;
- }
- /* No error, but unknown id */
- return true;
- }
-
- /* Erk, error on descriptor! */
- return false;
- }
-};
-
-/** Spawn sockets from a listener
- */
-class MySQLListener : public ListenSocketBase
-{
- ModuleSQL* Parent;
- irc::sockets::insp_sockaddr sock_us;
- socklen_t uslen;
- FileReader* index;
-
- public:
- MySQLListener(ModuleSQL* P, InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr), Parent(P)
- {
- uslen = sizeof(sock_us);
- if (getsockname(this->fd,(sockaddr*)&sock_us,&uslen))
- {
- throw ModuleException("Could not getsockname() to find out port number for ITC port");
- }
- }
-
- virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
- {
- // XXX unsafe casts suck
- new Notifier(this->Parent, this->ServerInstance, nfd, (char *)ipconnectedto.c_str());
- }
-
- /* Using getsockname and ntohs, we can determine which port number we were allocated */
- int GetPort()
- {
-#ifdef IPV6
- return ntohs(sock_us.sin6_port);
-#else
- return ntohs(sock_us.sin_port);
-#endif
- }