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 /ot_udp.c | |
parent | ae413a675b1d7e040997cb8f655672d144832a6f (diff) |
Add functionality to distribute udp to several workers
Diffstat (limited to 'ot_udp.c')
-rw-r--r-- | ot_udp.c | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -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"; |