Changeset 5510 for trackerd

Show
Ignore:
Timestamp:
05/08/08 23:50:09 (5 months ago)
Author:
morris
Message:

Do it like wired does it

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trackerd/trunk/trackerd/commands.c

    r5078 r5510  
    7979 
    8080 
    81 void wt_control_thread(wi_runtime_instance_t *argument) { 
     81void wt_command_loop_for_client(wt_client_t *client) { 
    8282        wi_pool_t                       *pool; 
    83         wt_client_t                     *client = argument; 
    8483        wi_string_t                     *string; 
    8584        wi_socket_state_t       state; 
    86         wi_uinteger_t           i = 0; 
    8785         
    8886        pool = wi_pool_init(wi_pool_alloc()); 
    89  
    90         wt_client_set(client); 
    9187 
    9288        while(client->state <= WT_CLIENT_STATE_SAID_HELLO) { 
     
    123119                wt_parse_command(string); 
    124120                 
    125                 if(++i % 10 == 0) 
    126                         wi_pool_drain(pool); 
     121                wi_pool_drain(pool); 
    127122        } 
    128123 
  • trackerd/trunk/trackerd/commands.h

    r5078 r5510  
    3030#define WT_COMMANDS_H 1 
    3131 
    32 void                                                    wt_control_thread(wi_runtime_instance_t *); 
     32void                                                    wt_command_loop_for_client(wt_client_t *); 
    3333 
    3434#endif /* WT_COMMANDS_H */ 
  • trackerd/trunk/trackerd/main.c

    r5362 r5510  
    392392 
    393393static void wt_signals_init(void) { 
    394         signal(SIGPIPE, SIG_IGN); 
    395394        signal(SIGILL, wt_signal_crash); 
    396395        signal(SIGABRT, wt_signal_crash); 
     
    403402 
    404403static 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); 
    406405} 
    407406 
     
    409408 
    410409static 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); 
    412411} 
    413412 
     
    425424                 
    426425                switch(signal) { 
     426                        case SIGPIPE: 
     427                                wi_log_warn(WI_STR("Signal PIPE received, ignoring")); 
     428                                break; 
     429 
    427430                        case SIGHUP: 
    428431                                wi_log_info(WI_STR("Signal HUP received, reloading configuration")); 
  • trackerd/trunk/trackerd/tracker.c

    r5430 r5510  
    4141 
    4242static void                                                     wt_listen_thread(wi_runtime_instance_t *); 
     43static void                                                     wt_accept_thread(wi_runtime_instance_t *); 
    4344static void                                                     wt_receive_thread(wi_runtime_instance_t *); 
    4445 
     
    224225        wi_socket_t                     *socket; 
    225226        wi_address_t            *address; 
    226         wi_string_t                     *ip; 
    227         wt_client_t                     *client; 
    228         wi_uinteger_t           i = 0; 
    229227         
    230228        pool = wi_pool_init(wi_pool_alloc()); 
    231229 
    232230        while(wt_running) { 
    233                 ip = NULL; 
    234  
    235                 /* accept new client */ 
     231                wi_pool_drain(pool); 
     232 
    236233                socket = wi_socket_accept_multiple(wt_tcp_sockets, 30.0, &address); 
    237234                 
     
    239236                        wi_log_err(WI_STR("Could not accept a connection: %m")); 
    240237                         
    241                         goto next; 
    242                 } 
    243                  
    244                 ip = wi_address_string(address); 
     238                        continue; 
     239                } 
    245240                 
    246241                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)); 
    248244                         
    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)); 
    254251                         
    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 
     261static 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 
     287end: 
    273288        wi_release(pool); 
    274289}