summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-02 09:41:39 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-02 09:41:39 +0000
commit001e00ba23962648cf0f8bfa1e1c50685ba6a15d (patch)
treeb11fa12443541ccb218871e42863b7628af59e81
parent270f1f8d19779a20231a4228286da5e5bf8b2be9 (diff)
Made threading optional
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2108 e03df62e-2008-0410-955e-edbf42e46eb7
-rwxr-xr-xconfigure15
-rw-r--r--include/users.h4
-rw-r--r--src/commands.cpp8
-rw-r--r--src/inspircd.cpp11
-rw-r--r--src/users.cpp4
5 files changed, 39 insertions, 3 deletions
diff --git a/configure b/configure
index b32d35a39..49782e4f4 100755
--- a/configure
+++ b/configure
@@ -30,6 +30,7 @@ $config{MAXI_MODES} = "20"; # Default Max.
$config{HAS_STRLCPY} = "false"; # strlcpy Check.
$config{USE_KQUEUE} = "y"; # kqueue enabled
$config{USE_EPOLL} = "y"; # epoll enabled
+$config{THREADED_DNS} = "n"; # threaded dns (experimental)
$config{STATIC_LINK} = "no"; # are doing static modules?
chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`); # FD Limit
chomp($config{GCCVER} = `gcc -dumpversion | cut -c 1`); # Major GCC Version
@@ -250,6 +251,9 @@ if (!$chose_hiperf)
print "not to enable one. Defaulting to select() engine.\n\n";
}
+yesno(THREADED_DNS,"Would you like to enable the experimental multi-threaded DNS lookup?");
+print "\n";
+
print "\nThe following questions will ask you for various figures relating\n";
print "To your IRCd install. Please note that these should usually be left\n";
print "as defaults unless you have a real reason to change them. If they\n";
@@ -498,6 +502,7 @@ print "\033[0mGCC Version Found:\033[1;32m\t\t$config{GCCVER}.$config{GCC34}\n";
print "\033[0mOptimatizaton Flag:\033[1;32m\t\t$config{OPTIMISATI}\033[0m\n";
print "\033[0mCompiler program:\033[1;32m\t\t$config{CC}\033[0m\n";
print "\033[0mStatic modules:\033[1;32m\t\t\t$config{STATIC_LINK}\033[0m\n\n";
+print "\033[0mMultithread DNS:\033[1;32m\t\t\t$config{THREADED_DNS}\033[0m\n\n";
makecache();
writefiles();
@@ -611,7 +616,7 @@ sub dir_check {
sub getosflags {
if ($config{OSNAME} =~ /BSD$/) {
- $config{LDLIBS} = "-Ldl -lstdc++ -pthread";
+ $config{LDLIBS} = "-Ldl -lstdc++";
$config{FLAGS} = "-fPIC -frtti $OPTIMISATI -Wall -Woverloaded-virtual $config{OPTIMISATI}";
$config{MAKEPROG} = "gmake";
if ($config{OSNAME} eq "OpenBSD") {
@@ -626,7 +631,7 @@ sub getosflags {
}
}
} else {
- $config{LDLIBS} = "-ldl -lstdc++ -pthread";
+ $config{LDLIBS} = "-ldl -lstdc++";
$config{FLAGS} = "-fPIC -frtti $OPTIMISATI -Wall -Woverloaded-virtual $config{OPTIMISATI}";
$config{MAKEPROG} = "make";
if ($config{OSNAME} =~ /CYGWIN/) {
@@ -734,6 +739,9 @@ EOF
if ($config{HAS_STRLCPY} eq "true") {
print FILEHANDLE "#define HAS_STRLCPY\n";
}
+ if ($config{THREADED_DNS} =~ /y/i) {
+ print FILEHANDLE "#define THREADED_DNS\n";
+ }
my $use_hiperf = 0;
if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
print FILEHANDLE "#define USE_KQUEUE\n";
@@ -775,6 +783,9 @@ EOF
}
opendir(DIRHANDLE, $this);
+ if ($config{THREADED_DNS} =~ /y/i) {
+ $config{LDLIBS} = $config{LDLIBS} . " -pthread";
+ }
foreach $name (sort readdir(DIRHANDLE)) {
if ($name =~ /^\.(.+)\.inc$/)
{
diff --git a/include/users.h b/include/users.h
index 388977359..0e5937667 100644
--- a/include/users.h
+++ b/include/users.h
@@ -19,7 +19,9 @@
#include "inspstring.h"
#include "connection.h"
#include <string>
+#ifdef THREADED_DNS
#include <pthread.h>
+#endif
#ifndef __USERS_H__
#define __USERS_H__
@@ -320,7 +322,9 @@ class userrec : public connection
virtual ~userrec();
+#ifdef THREADED_DNS
pthread_t dnsthread;
+#endif
};
/** A lightweight userrec used by WHOWAS
diff --git a/src/commands.cpp b/src/commands.cpp
index f02c4bfcc..e47680702 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -50,7 +50,9 @@ using namespace std;
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#ifdef THREADED_DNS
#include <pthread.h>
+#endif
#ifndef RUSAGE_SELF
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN -1
@@ -1724,11 +1726,17 @@ void handle_nick(char **parameters, int pcnt, userrec *user)
//if (user->dns_done)
// log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+#ifdef THREADED_DNS
// initialize their dns lookup thread
if (pthread_create(&user->dnsthread, NULL, dns_task, (void *)user) != 0)
{
log(DEBUG,"Failed to create DNS lookup thread for user %s",user->nick);
}
+#else
+ user->dns_done = (!lookup_dns(user->nick));
+ if (user->dns_done)
+ log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+#endif
}
if (user->registered == 3)
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 65b43fa37..271332f70 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -51,7 +51,9 @@ using namespace std;
#include <vector>
#include <deque>
#include <sched.h>
+#ifdef THREADED_DNS
#include <pthread.h>
+#endif
#include "users.h"
#include "ctables.h"
#include "globals.h"
@@ -1330,6 +1332,7 @@ void AddWhoWas(userrec* u)
}
}
+#ifdef THREADED_DNS
void* dns_task(void* arg)
{
userrec* u = (userrec*)arg;
@@ -1372,6 +1375,7 @@ void* dns_task(void* arg)
u->dns_done = true;
return NULL;
}
+#endif
/* add a client connection to the sockets list */
void AddClient(int socket, char* host, int port, bool iscached, char* ip)
@@ -1610,7 +1614,12 @@ std::string GetVersionString()
v2 = strtok_r(s1," ",&savept);
s1 = savept;
char socketengine[] = engine_name;
- snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s (O=%lu) [SE=%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,socketengine);
+#ifdef THREADED_DNS
+ char dnsengine[] = "multithread";
+#else
+ char dnsengine[] = "singlethread";
+#endif
+ snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,socketengine,dnsengine);
return versiondata;
}
diff --git a/src/users.cpp b/src/users.cpp
index c78eb4793..19d6a37f4 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -22,8 +22,10 @@ using namespace std;
#include "users.h"
#include "inspircd.h"
#include <stdio.h>
+#ifdef THREADED_DNS
#include <pthread.h>
#include <signal.h>
+#endif
#include "inspstring.h"
#include "helperfuncs.h"
@@ -64,11 +66,13 @@ userrec::userrec()
userrec::~userrec()
{
+#ifdef THREADED_DNS
// for local clients, clean up their dns thread
if (!strcmp(this->server,ServerName))
{
pthread_kill(this->dnsthread,9);
}
+#endif
}
void userrec::CloseSocket()