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
* 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)
{
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());
+ }
+ }
+ }
+ }
}
}
}
}
if ((fd_ref_table[thisfd] == u) && (fd_ref_table[thisfd]))
u->dns_done = true;
- pthread_exit(0);
+ log(DEBUG,"THREAD EXIT");
+ return NULL;
}
#endif