Ignore:
Timestamp:
07/31/08 01:34:55 (5 years ago)
Author:
pterjan
Message:
  • Factorize some code in attach.c
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/main.c

    r2613 r2614  
    261261            for(i=0; sockets[i]; i++); 
    262262            i--; 
    263             screen_list->s_socket_path = strdup(sockets[i]); 
    264             session = connect_server(screen_list); 
     263            screen_list->socket_path[SOCK_SERVER] = strdup(sockets[i]); 
     264            session = connect_socket(screen_list, SOCK_SERVER); 
    265265            while(!session && i > 0) 
    266266            { 
    267                 free(screen_list->s_socket_path); 
     267                free(screen_list->socket_path[SOCK_SERVER]); 
    268268                i--; 
    269                 screen_list->s_socket_path = strdup(sockets[i]); 
    270                 session = connect_server(screen_list); 
     269                screen_list->socket_path[SOCK_SERVER] = strdup(sockets[i]); 
     270                session = connect_socket(screen_list, SOCK_SERVER); 
    271271            } 
    272272            debug("Connected to session %s", session); 
     
    280280                caca_set_cursor(screen_list->dp, 1); 
    281281 
    282                 screen_list->c_socket_path = build_socket_path(screen_list->socket_dir, session, 1); 
    283                 create_client_socket(screen_list); 
     282                screen_list->socket_path[SOCK_CLIENT] = 
     283                    build_socket_path(screen_list->socket_dir, session, SOCK_CLIENT); 
     284                create_socket(screen_list, SOCK_CLIENT); 
    284285                request_attach(screen_list); 
    285286                if(screen_list->session_name) 
     
    290291            { 
    291292                fprintf(stderr, "Failed to attach!\n"); 
    292                 free(screen_list->s_socket_path); 
    293                 screen_list->s_socket_path = NULL; 
     293                free(screen_list->socket_path[SOCK_SERVER]); 
     294                screen_list->socket_path[SOCK_SERVER] = NULL; 
    294295                attach = 0; 
    295296            } 
     
    320321        } 
    321322    } 
    322     if(!screen_list->c_socket_path) 
    323         screen_list->c_socket_path = 
    324             build_socket_path(screen_list->socket_dir, screen_list->session_name, 1); 
    325  
    326     if(!screen_list->s_socket_path) 
    327         screen_list->s_socket_path = 
    328             build_socket_path(screen_list->socket_dir, screen_list->session_name, 0); 
     323    if(!screen_list->socket_path[SOCK_CLIENT]) 
     324        screen_list->socket_path[SOCK_CLIENT] = 
     325            build_socket_path(screen_list->socket_dir, screen_list->session_name, SOCK_CLIENT); 
     326 
     327    if(!screen_list->socket_path[SOCK_SERVER]) 
     328        screen_list->socket_path[SOCK_SERVER] = 
     329            build_socket_path(screen_list->socket_dir, screen_list->session_name, SOCK_SERVER); 
    329330 
    330331    /* Fork the server if needed */ 
     
    365366            return server_main(to_grab, to_start, screen_list); 
    366367        } 
    367         create_client_socket(screen_list); 
    368         while((sess = connect_server(screen_list)) == NULL) 
     368        create_socket(screen_list, SOCK_CLIENT); 
     369        while((sess = connect_socket(screen_list, SOCK_SERVER)) == NULL) 
    369370            usleep(100); 
    370371        free(sess); 
     
    389390        char buf[128*1024]; 
    390391 
    391         if (screen_list->c_socket && (n = read(screen_list->c_socket, buf, sizeof(buf)-1)) > 0) 
     392        if (screen_list->socket[SOCK_CLIENT] && (n = read(screen_list->socket[SOCK_CLIENT], buf, sizeof(buf)-1)) > 0) 
    392393        { 
    393394            buf[n] = 0; 
     
    445446        } 
    446447 
    447         if(screen_list->s_socket_path) 
    448             free(screen_list->s_socket_path); 
    449  
    450         if(screen_list->c_socket_path) 
    451         { 
    452             unlink(screen_list->c_socket_path); 
    453             free(screen_list->c_socket_path); 
    454         } 
    455  
    456         if(screen_list->c_socket) 
    457             close(screen_list->c_socket); 
    458  
    459         if(screen_list->s_socket) 
    460             close(screen_list->s_socket); 
     448        if(screen_list->socket_path[SOCK_SERVER]) 
     449            free(screen_list->socket_path[SOCK_SERVER]); 
     450 
     451        if(screen_list->socket_path[SOCK_CLIENT]) 
     452        { 
     453            unlink(screen_list->socket_path[SOCK_CLIENT]); 
     454            free(screen_list->socket_path[SOCK_CLIENT]); 
     455        } 
     456 
     457        if(screen_list->socket[SOCK_CLIENT]) 
     458            close(screen_list->socket[SOCK_CLIENT]); 
     459 
     460        if(screen_list->socket[SOCK_SERVER]) 
     461            close(screen_list->socket[SOCK_SERVER]); 
    461462 
    462463        if(screen_list->screen) 
     
    529530    screen_list->lock_offset = 0; 
    530531    screen_list->attached = 1; 
    531     screen_list->s_socket = 0; 
    532     screen_list->c_socket = 0; 
     532    screen_list->socket[SOCK_SERVER] = 0; 
     533    screen_list->socket[SOCK_CLIENT] = 0; 
    533534    screen_list->socket_dir    = NULL; 
    534     screen_list->s_socket_path = NULL; 
    535     screen_list->c_socket_path = NULL; 
     535    screen_list->socket_path[SOCK_SERVER] = NULL; 
     536    screen_list->socket_path[SOCK_CLIENT] = NULL; 
    536537    screen_list->session_name  = NULL; 
    537538    screen_list->default_shell = NULL; 
Note: See TracChangeset for help on using the changeset viewer.