]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/dns.cpp
Move this to m_mysql.cpp - dont even bother reading this yet its unchanged from m_sql
[user/henk/code/inspircd.git] / src / dns.cpp
index a6e41307170d513938cba0f29795373935c5a97c..1ea9abd555bf3c336d91e3ea466ec932d21f7817 100644 (file)
@@ -475,6 +475,9 @@ char* DNS::dns_getresult_s(const int cfd, char *res) { /* retrieve result of DNS
        if (n_iter == connections.end())
        {
                log(DEBUG,"DNS: got a response for a query we didnt send with fd=%d",cfd);
+#ifdef THREADED_DNS
+               pthread_mutex_unlock(&connmap_lock);
+#endif
                return NULL;
        }
        else
@@ -872,6 +875,12 @@ std::string DNS::GetResultIP()
  * SMP setups (like the one i have here *grin*).
  * This is in comparison to the non-threaded dns, which must monitor the thread sockets
  * in a nonblocking fashion, consuming more resources to do so.
+ *
+ * NB: Yes this does scale, thank you. Even with large numbers of connecting clients
+ * in any one timeframe, they wont all connect *at the same time* therefore any argument
+ * of "but there will be thousands of threads it'll blow up" is moot, ive tested this and
+ * there will only ever be somewhere around the listen backlog in number of pending
+ * lookups at any one time. This is significant on any modern SMP system.
  */
 void* dns_task(void* arg)
 {
@@ -879,34 +888,52 @@ void* dns_task(void* arg)
        int thisfd = u->fd;
 
        log(DEBUG,"DNS thread for user %s",u->nick);
-       DNS dns1;
-       DNS dns2;
+       DNS dns1(Config->DNSServer);
+       DNS dns2(Config->DNSServer);
        std::string host;
        std::string ip;
+       int iterations = 0;
+
        if (dns1.ReverseLookup(inet_ntoa(u->ip4),false))
        {
-               while (!dns1.HasResult())
+               /* FIX: Dont make these infinite! */
+               while ((!dns1.HasResult()) && (++iterations < 20))
                        usleep(100);
-               host = dns1.GetResult();
-               if (host != "")
+
+               if (iterations < 20)
                {
-                       if (dns2.ForwardLookup(host, false))
+                       if (dns1.GetFD() != -1)
                        {
-                               while (!dns2.HasResult())
-                                       usleep(100);
-                               ip = dns2.GetResultIP();
-                               if (ip == std::string(inet_ntoa(u->ip4)))
+                               host = dns1.GetResult();
+                               if (host != "")
                                {
-                                       if (host.length() < 65)
+                                       if (dns2.ForwardLookup(host, false))
                                        {
-                                               if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+                                               iterations = 0;
+                                               while ((!dns2.HasResult()) && (++iterations < 20))
+                                                       usleep(100);
+
+                                               if (iterations < 20)
                                                {
-                                                       if (!u->dns_done)
+                                                       if (dns2.GetFD() != -1)
                                                        {
-                                                               strcpy(u->host,host.c_str());
-                                                               if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+                                                               ip = dns2.GetResultIP();
+                                                               if (ip == std::string(inet_ntoa(u->ip4)))
                                                                {
-                                                                       strcpy(u->dhost,host.c_str());
+                                                                       if (host.length() < 65)
+                                                                       {
+                                                                               if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+                                                                               {
+                                                                                       if (!u->dns_done)
+                                                                                       {
+                                                                                               strcpy(u->host,host.c_str());
+                                                                                               if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
+                                                                                               {
+                                                                                                       strcpy(u->dhost,host.c_str());
+                                                                                               }
+                                                                                       }
+                                                                               }
+                                                                       }
                                                                }
                                                        }
                                                }
@@ -917,6 +944,7 @@ void* dns_task(void* arg)
        }
        if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
                u->dns_done = true;
+       log(DEBUG,"THREAD EXIT");
        return NULL;
 }
 #endif