From 914e0ac3020b7c842f2a1fd975217f70fa705449 Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 25 Apr 2012 05:48:16 +0000 Subject: Add functionality to distribute udp to several workers --- ot_udp.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'ot_udp.c') diff --git a/ot_udp.c b/ot_udp.c index e891494..d3fb82a 100644 --- a/ot_udp.c +++ b/ot_udp.c @@ -4,6 +4,8 @@ $id$ */ /* System */ +#include +#include #include #include #include @@ -120,8 +122,35 @@ int handle_udp6( int64 serversocket, struct ot_workstruct *ws ) { return 1; } -void udp_init( ) { +static void* udp_worker( void * args ) { + int64 sock = (int64)args; + struct ot_workstruct ws; + memset( &ws, 0, sizeof(ws) ); + + ws.inbuf=malloc(G_INBUF_SIZE); + ws.outbuf=malloc(G_OUTBUF_SIZE); +#ifdef _DEBUG_HTTPERROR + ws.debugbuf=malloc(G_DEBUGBUF_SIZE); +#endif + + while( g_opentracker_running ) + handle_udp6( sock, &ws ); + + free( ws.inbuf ); + free( ws.outbuf ); +#ifdef _DEBUG_HTTPERROR + free( ws.debugbuf ); +#endif + return NULL; +} +void udp_init( int64 sock, unsigned int worker_count ) { + pthread_t thread_id; +#ifdef _DEBUG + fprintf( stderr, " installing %d workers on udp socket %ld", worker_count, (unsigned long)sock ); +#endif + while( worker_count-- ) + pthread_create( &thread_id, NULL, udp_worker, (void *)sock ); } const char *g_version_udp_c = "$Source$: $Revision$\n"; -- cgit v1.2.3