-/* This function is a thread function which can be thought of as a lightweight process
- * to all you non-threaded people. In actuality its so much more, and pretty damn cool.
- * With threaded dns enabled, each user which connects gets a thread attached to their
- * user record when their DNS lookup starts. This function starts in parallel, and
- * commences a blocking dns lookup. Because its a seperate thread, this occurs without
- * actually blocking the main application. Once the dns lookup is completed, the thread
- * checks if the user is still around by checking their fd against the reference table,
- * and if they are, writes the hostname into the struct and terminates, after setting
- * userrec::dns_done to true. Because this is multi-threaded it can make proper use of
- * 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.
- */
-void* dns_task(void* arg)
-{
- userrec* u = (userrec*)arg;
- int thisfd = u->fd;
-
- log(DEBUG,"DNS thread for user %s",u->nick);
- DNS dns1;
- DNS dns2;
- std::string host;
- std::string ip;
- if (dns1.ReverseLookup(inet_ntoa(u->ip4),false))
- {
- while (!dns1.HasResult())
- usleep(100);
- host = dns1.GetResult();
- if (host != "")
- {
- if (dns2.ForwardLookup(host, false))
- {
- while (!dns2.HasResult())
- usleep(100);
- ip = dns2.GetResultIP();
- if (ip == std::string(inet_ntoa(u->ip4)))
- {
- 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);
-}
-#endif