]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_mysql.cpp
not test compiled yet: sql modules werent working because someone chopped out the...
[user/henk/code/inspircd.git] / src / modules / extra / m_mysql.cpp
index 9f9db7595eac1cfa486e736bc310cf33b7ed1e7f..ae66e44bb5377eb7ed26b535e3c07adcbc07c004 100644 (file)
@@ -68,7 +68,7 @@
 
 
 class SQLConnection;
-class Notifier;
+class MySQLListener;
 
 
 typedef std::map<std::string, SQLConnection*> ConnMap;
@@ -657,45 +657,15 @@ class DispatcherThread : public Thread
        virtual void Run();
 };
 
-/** Spawn HTTP sockets from a listener
- */
-class MySQLListener : public ListenSocketBase
-{
-       FileReader* index;
-
- public:
-       HttpListener(InspIRCd* Instance, int port, char* addr) : ListenSocketBase(Instance, port, addr)
-       {
-               this->index = idx;
-       }
-
-       virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip)
-       {
-               new Notifier(this->ServerInstance, nfd, (char)ipconnectedto.c_str()); // XXX unsafe casts suck
-       }
-};
-
 /** Used by m_mysql to notify one thread when the other has a result
  */
 class Notifier : public BufferedSocket
 {
-       insp_sockaddr sock_us;
-       socklen_t uslen;
        ModuleSQL* Parent;
 
  public:
        Notifier(InspIRCd* SI, int newfd, char* ip) : BufferedSocket(SI, newfd, ip) { }
 
-       /* 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
-       }
-
        virtual bool OnDataReady()
        {
                char data = 0;
@@ -728,6 +698,39 @@ class Notifier : public BufferedSocket
        }
 };
 
+/** Spawn sockets from a listener
+ */
+class MySQLListener : public ListenSocketBase
+{
+       insp_sockaddr sock_us;
+       socklen_t uslen;
+       FileReader* index;
+
+ public:
+       MySQLListener(InspIRCd* Instance, int port, const std::string &addr) : ListenSocketBase(Instance, port, addr)
+       {
+               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)
+       {
+               new Notifier(this->ServerInstance, nfd, (char *)ipconnectedto.c_str()); // XXX unsafe casts suck
+       }
+
+       /* 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
+       }
+};
 
 ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false)
 {
@@ -737,17 +740,17 @@ ModuleSQL::ModuleSQL(InspIRCd* Me) : Module(Me), rehashing(false)
        PublicServerInstance = ServerInstance;
        currid = 0;
 
-       MessagePipe = new Notifier(ServerInstance, this);
-
        /* Create a socket on a random port. Let the tcp stack allocate us an available port */
 #ifdef IPV6
-       MessagePipe = new MySQLListener(SI, 0, "::1");
+       MessagePipe = new MySQLListener(ServerInstance, 0, "::1");
 #else
-       MessagePipe = new MySQLListener(SI, 0, "127.0.0.1");
+       MessagePipe = new MySQLListener(ServerInstance, 0, "127.0.0.1");
 #endif
 
-       if (MessagePipe->GetFd())
+       if (MessagePipe->GetFd() == -1)
                throw ModuleException("m_mysql: unable to create ITC pipe");
+       else
+               ServerInstance->Logs->Log("m_mysql", DEBUG, "MySQL: Interthread comms port is %d", MessagePipe->GetPort());
 
        Dispatcher = new DispatcherThread(ServerInstance, this);
        ServerInstance->Threads->Create(Dispatcher);