Changeset 718

Show
Ignore:
Timestamp:
02/25/08 07:55:25 (9 months ago)
Author:
dsallings
Message:

Refactored connection setup into a separate function.

This loop *probably* shouldn't've gone into main in the first place, but
copying and pasting it made it especially terrible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/binary/server/memcached.c

    r717 r718  
    33393339} 
    33403340 
     3341static void setup_listening_conns(int *l_socket, int count, const int prot) { 
     3342    /* create the initial listening connection */ 
     3343    int x; 
     3344    int *l_socket_ptr; 
     3345    conn *next = listen_conn; 
     3346    for (l_socket_ptr= l_socket, x = 0; x < count; l_socket_ptr++, x++) { 
     3347        conn *listen_conn_add; 
     3348        if (*l_socket_ptr > -1 ) { 
     3349            if (!(listen_conn_add = conn_new(*l_socket_ptr, conn_listening, 
     3350                                             EV_READ | EV_PERSIST, 
     3351                                             1, prot, main_base))) { 
     3352                fprintf(stderr, "failed to create listening connection\n"); 
     3353                exit(EXIT_FAILURE); 
     3354            } 
     3355 
     3356            if (listen_conn == NULL) { 
     3357                next = listen_conn = listen_conn_add; 
     3358            } else { 
     3359                next->next= listen_conn_add; 
     3360            } 
     3361        } 
     3362    } 
     3363} 
    33413364 
    33423365static void sig_handler(const int sig) { 
     
    33473370int main (int argc, char **argv) { 
    33483371    int c; 
    3349     int x; 
    33503372    bool lock_memory = false; 
    33513373    bool daemonize = false; 
     
    36333655        exit(EXIT_FAILURE); 
    36343656    } 
    3635     /* create the initial listening connection */ 
    3636     int *l_socket_ptr; 
    3637     conn *next = NULL; 
    3638     for (l_socket_ptr= l_socket, x = 0; x < l_socket_count; l_socket_ptr++, x++) { 
    3639         conn *listen_conn_add; 
    3640         if (*l_socket_ptr > -1 ) { 
    3641             if (!(listen_conn_add = conn_new(*l_socket_ptr, conn_listening, 
    3642                                              EV_READ | EV_PERSIST, 1, ascii_prot, main_base))) { 
    3643                 fprintf(stderr, "failed to create listening connection\n"); 
    3644                 exit(EXIT_FAILURE); 
    3645             } 
    3646  
    3647             if (listen_conn == NULL) { 
    3648                 next = listen_conn = listen_conn_add; 
    3649             } else { 
    3650                 next->next= listen_conn_add; 
    3651             } 
    3652         } 
    3653     } 
    3654  
    3655     for (l_socket_ptr= bl_socket, x = 0; x < bl_socket_count; l_socket_ptr++, x++) { 
    3656         conn *listen_conn_add; 
    3657         if (*l_socket_ptr > -1 ) { 
    3658             if (!(listen_conn_add = conn_new(*l_socket_ptr, conn_listening, 
    3659                                              EV_READ | EV_PERSIST, 1, binary_prot, main_base))) { 
    3660                 fprintf(stderr, "failed to create listening connection\n"); 
    3661                 exit(EXIT_FAILURE); 
    3662             } 
    3663  
    3664             if (listen_conn == NULL) { 
    3665                 next = listen_conn = listen_conn_add; 
    3666             } else { 
    3667                 next->next= listen_conn_add; 
    3668             } 
    3669         } 
    3670     } 
     3657    /* Set up all of the listening connections */ 
     3658    setup_listening_conns(l_socket, l_socket_count, ascii_prot); 
     3659    setup_listening_conns(bl_socket, bl_socket_count, binary_prot); 
    36713660 
    36723661    /* start up worker threads if MT mode */