Changeset 5510
- Timestamp:
- 05/08/08 23:50:09 (1 week ago)
- Files:
-
- trackerd/trunk/trackerd/commands.c (modified) (2 diffs)
- trackerd/trunk/trackerd/commands.h (modified) (1 diff)
- trackerd/trunk/trackerd/main.c (modified) (4 diffs)
- trackerd/trunk/trackerd/tracker.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trackerd/trunk/trackerd/commands.c
r5078 r5510 79 79 80 80 81 void wt_co ntrol_thread(wi_runtime_instance_t *argument) {81 void wt_command_loop_for_client(wt_client_t *client) { 82 82 wi_pool_t *pool; 83 wt_client_t *client = argument;84 83 wi_string_t *string; 85 84 wi_socket_state_t state; 86 wi_uinteger_t i = 0;87 85 88 86 pool = wi_pool_init(wi_pool_alloc()); 89 90 wt_client_set(client);91 87 92 88 while(client->state <= WT_CLIENT_STATE_SAID_HELLO) { … … 123 119 wt_parse_command(string); 124 120 125 if(++i % 10 == 0) 126 wi_pool_drain(pool); 121 wi_pool_drain(pool); 127 122 } 128 123 trackerd/trunk/trackerd/commands.h
r5078 r5510 30 30 #define WT_COMMANDS_H 1 31 31 32 void wt_co ntrol_thread(wi_runtime_instance_t *);32 void wt_command_loop_for_client(wt_client_t *); 33 33 34 34 #endif /* WT_COMMANDS_H */ trackerd/trunk/trackerd/main.c
r5362 r5510 392 392 393 393 static void wt_signals_init(void) { 394 signal(SIGPIPE, SIG_IGN);395 394 signal(SIGILL, wt_signal_crash); 396 395 signal(SIGABRT, wt_signal_crash); … … 403 402 404 403 static void wt_block_signals(void) { 405 wi_thread_block_signals(SIGHUP, SIGINT, SIGTERM, SIGQUIT, 0);404 wi_thread_block_signals(SIGHUP, SIGINT, SIGTERM, SIGQUIT, SIGPIPE, 0); 406 405 } 407 406 … … 409 408 410 409 static int wt_wait_signals(void) { 411 return wi_thread_wait_for_signals(SIGHUP, SIGINT, SIGTERM, SIGQUIT, 0);410 return wi_thread_wait_for_signals(SIGHUP, SIGINT, SIGTERM, SIGQUIT, SIGPIPE, 0); 412 411 } 413 412 … … 425 424 426 425 switch(signal) { 426 case SIGPIPE: 427 wi_log_warn(WI_STR("Signal PIPE received, ignoring")); 428 break; 429 427 430 case SIGHUP: 428 431 wi_log_info(WI_STR("Signal HUP received, reloading configuration")); trackerd/trunk/trackerd/tracker.c
r5430 r5510 41 41 42 42 static void wt_listen_thread(wi_runtime_instance_t *); 43 static void wt_accept_thread(wi_runtime_instance_t *); 43 44 static void wt_receive_thread(wi_runtime_instance_t *); 44 45 … … 224 225 wi_socket_t *socket; 225 226 wi_address_t *address; 226 wi_string_t *ip;227 wt_client_t *client;228 wi_uinteger_t i = 0;229 227 230 228 pool = wi_pool_init(wi_pool_alloc()); 231 229 232 230 while(wt_running) { 233 ip = NULL; 234 235 /* accept new client */ 231 wi_pool_drain(pool); 232 236 233 socket = wi_socket_accept_multiple(wt_tcp_sockets, 30.0, &address); 237 234 … … 239 236 wi_log_err(WI_STR("Could not accept a connection: %m")); 240 237 241 goto next; 242 } 243 244 ip = wi_address_string(address); 238 continue; 239 } 245 240 246 241 if(!socket) { 247 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 242 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), 243 wi_address_string(address)); 248 244 249 goto next; 250 } 251 252 if(!wi_socket_accept_tls(socket, wt_socket_tls, 30.0)) { 253 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 245 continue; 246 } 247 248 if(!wi_thread_create_thread(wt_accept_thread, socket)) { 249 wi_log_err(WI_STR("Could not create a thread for %@: %m"), 250 wi_address_string(address)); 254 251 255 goto next; 256 } 257 258 wi_socket_set_direction(socket, WI_SOCKET_READ); 259 260 wi_log_info(WI_STR("Connect from %@"), ip); 261 262 /* spawn a client thread */ 263 client = wi_autorelease(wt_client_init_with_socket(wt_client_alloc(), socket)); 264 265 if(!wi_thread_create_thread(wt_control_thread, client)) 266 wi_log_err(WI_STR("Could not create a thread for %@: %m"), ip); 267 268 next: 269 if(++i % 100 == 0) 270 wi_pool_drain(pool); 271 } 272 252 continue; 253 } 254 } 255 256 wi_release(pool); 257 } 258 259 260 261 static void wt_accept_thread(wi_runtime_instance_t *argument) { 262 wi_pool_t *pool; 263 wi_socket_t *socket = argument; 264 wi_string_t *ip; 265 wt_client_t *client; 266 267 pool = wi_pool_init(wi_pool_alloc()); 268 269 ip = wi_address_string(wi_socket_address(socket)); 270 271 if(!wi_socket_accept_tls(socket, wt_socket_tls, 30.0)) { 272 wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip); 273 274 goto end; 275 } 276 277 wi_socket_set_direction(socket, WI_SOCKET_READ); 278 279 wi_log_info(WI_STR("Connect from %@"), ip); 280 281 client = wi_autorelease(wt_client_init_with_socket(wt_client_alloc(), socket)); 282 283 wt_client_set(client); 284 285 wt_command_loop_for_client(client); 286 287 end: 273 288 wi_release(pool); 274 289 }
