diff options
author | erdgeist <> | 2012-04-25 05:48:16 +0000 |
---|---|---|
committer | erdgeist <> | 2012-04-25 05:48:16 +0000 |
commit | 914e0ac3020b7c842f2a1fd975217f70fa705449 (patch) | |
tree | feb12cf179fe21873966f2c7f51b890e3aa4a3f5 | |
parent | ae413a675b1d7e040997cb8f655672d144832a6f (diff) |
Add functionality to distribute udp to several workers
-rw-r--r-- | opentracker.c | 11 | ||||
-rw-r--r-- | opentracker.conf.sample | 9 | ||||
-rw-r--r-- | ot_udp.c | 31 | ||||
-rw-r--r-- | ot_udp.h | 3 |
4 files changed, 51 insertions, 3 deletions
diff --git a/opentracker.c b/opentracker.c index 0c535ec..c735393 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -46,6 +46,7 @@ int g_self_pipe[2]; | |||
46 | 46 | ||
47 | static char * g_serverdir; | 47 | static char * g_serverdir; |
48 | static char * g_serveruser; | 48 | static char * g_serveruser; |
49 | static unsigned int g_udp_workers; | ||
49 | 50 | ||
50 | static void panic( const char *routine ) { | 51 | static void panic( const char *routine ) { |
51 | fprintf( stderr, "%s: %s\n", routine, strerror(errno) ); | 52 | fprintf( stderr, "%s: %s\n", routine, strerror(errno) ); |
@@ -328,7 +329,11 @@ static int64_t ot_try_bind( ot_ip6 ip, uint16_t port, PROTO_FLAG proto ) { | |||
328 | 329 | ||
329 | io_setcookie( sock, (void*)proto ); | 330 | io_setcookie( sock, (void*)proto ); |
330 | 331 | ||
331 | io_wantread( sock ); | 332 | if( (proto == FLAG_UDP) && g_udp_workers ) { |
333 | io_block( sock ); | ||
334 | udp_init( sock, g_udp_workers ); | ||
335 | } else | ||
336 | io_wantread( sock ); | ||
332 | 337 | ||
333 | #ifdef _DEBUG | 338 | #ifdef _DEBUG |
334 | fputs( " success.\n", stderr); | 339 | fputs( " success.\n", stderr); |
@@ -416,6 +421,10 @@ int parse_configfile( char * config_filename ) { | |||
416 | if( !scan_ip6_port( p+11, tmpip, &tmpport )) goto parse_error; | 421 | if( !scan_ip6_port( p+11, tmpip, &tmpport )) goto parse_error; |
417 | ot_try_bind( tmpip, tmpport, FLAG_UDP ); | 422 | ot_try_bind( tmpip, tmpport, FLAG_UDP ); |
418 | ++bound; | 423 | ++bound; |
424 | } else if(!byte_diff(p,18,"listen.udp.workers" ) && isspace(p[18])) { | ||
425 | char *value = p + 18; | ||
426 | while( isspace(*value) ) ++value; | ||
427 | scan_uint( value, &g_udp_workers ); | ||
419 | #ifdef WANT_ACCESSLIST_WHITE | 428 | #ifdef WANT_ACCESSLIST_WHITE |
420 | } else if(!byte_diff(p, 16, "access.whitelist" ) && isspace(p[16])) { | 429 | } else if(!byte_diff(p, 16, "access.whitelist" ) && isspace(p[16])) { |
421 | set_config_option( &g_accesslist_filename, p+17 ); | 430 | set_config_option( &g_accesslist_filename, p+17 ); |
diff --git a/opentracker.conf.sample b/opentracker.conf.sample index f5d88d3..db45122 100644 --- a/opentracker.conf.sample +++ b/opentracker.conf.sample | |||
@@ -7,6 +7,15 @@ | |||
7 | # If no listen option is given (here or on the command line), opentracker | 7 | # If no listen option is given (here or on the command line), opentracker |
8 | # listens on 0.0.0.0:6969 tcp and udp. | 8 | # listens on 0.0.0.0:6969 tcp and udp. |
9 | # | 9 | # |
10 | # The next variable determines if udp sockets are handled in the event | ||
11 | # loop (set it to 0, the default) or are handled in blocking reads in | ||
12 | # dedicated worker threads. You have to set this value before the | ||
13 | # listen.tcp_udp or listen.udp statements before it takes effect, but you | ||
14 | # can re-set it for each listen statement. Normally you should keep it at | ||
15 | # the top of the config file. | ||
16 | # | ||
17 | # listen.udp.workers 4 | ||
18 | # | ||
10 | # listen.tcp_udp 0.0.0.0 | 19 | # listen.tcp_udp 0.0.0.0 |
11 | # listen.tcp_udp 192.168.0.1:80 | 20 | # listen.tcp_udp 192.168.0.1:80 |
12 | # listen.tcp_udp 10.0.0.5:6969 | 21 | # listen.tcp_udp 10.0.0.5:6969 |
@@ -4,6 +4,8 @@ | |||
4 | $id$ */ | 4 | $id$ */ |
5 | 5 | ||
6 | /* System */ | 6 | /* System */ |
7 | #include <stdlib.h> | ||
8 | #include <pthread.h> | ||
7 | #include <string.h> | 9 | #include <string.h> |
8 | #include <arpa/inet.h> | 10 | #include <arpa/inet.h> |
9 | #include <stdio.h> | 11 | #include <stdio.h> |
@@ -120,8 +122,35 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { | |||
120 | return 1; | 122 | return 1; |
121 | } | 123 | } |
122 | 124 | ||
123 | void udp_init( ) { | 125 | static void* udp_worker( void * args ) { |
126 | int64 sock = (int64)args; | ||
127 | struct ot_workstruct ws; | ||
128 | memset( &ws, 0, sizeof(ws) ); | ||
129 | |||
130 | ws.inbuf=malloc(G_INBUF_SIZE); | ||
131 | ws.outbuf=malloc(G_OUTBUF_SIZE); | ||
132 | #ifdef _DEBUG_HTTPERROR | ||
133 | ws.debugbuf=malloc(G_DEBUGBUF_SIZE); | ||
134 | #endif | ||
135 | |||
136 | while( g_opentracker_running ) | ||
137 | handle_udp6( sock, &ws ); | ||
138 | |||
139 | free( ws.inbuf ); | ||
140 | free( ws.outbuf ); | ||
141 | #ifdef _DEBUG_HTTPERROR | ||
142 | free( ws.debugbuf ); | ||
143 | #endif | ||
144 | return NULL; | ||
145 | } | ||
124 | 146 | ||
147 | void udp_init( int64 sock, unsigned int worker_count ) { | ||
148 | pthread_t thread_id; | ||
149 | #ifdef _DEBUG | ||
150 | fprintf( stderr, " installing %d workers on udp socket %ld", worker_count, (unsigned long)sock ); | ||
151 | #endif | ||
152 | while( worker_count-- ) | ||
153 | pthread_create( &thread_id, NULL, udp_worker, (void *)sock ); | ||
125 | } | 154 | } |
126 | 155 | ||
127 | const char *g_version_udp_c = "$Source$: $Revision$\n"; | 156 | const char *g_version_udp_c = "$Source$: $Revision$\n"; |
@@ -6,6 +6,7 @@ | |||
6 | #ifndef __OT_UDP_H__ | 6 | #ifndef __OT_UDP_H__ |
7 | #define __OT_UDP_H__ | 7 | #define __OT_UDP_H__ |
8 | 8 | ||
9 | int handle_udp6( int64 serversocket, struct ot_workstruct *ws ); | 9 | void udp_init( int64 sock, unsigned int worker_count ); |
10 | int handle_udp6( int64 serversocket, struct ot_workstruct *ws ); | ||
10 | 11 | ||
11 | #endif | 12 | #endif |