int Join(char *server, int port, char *real, char *nick, char *display, unsigned version) { signal(SIGINT, sigcatch); signal(SIGTERM, sigcatch); signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); if (Client_init(server, version) == -1) { return -1; } if (Net_init(server, port) == -1) { Client_cleanup(); return -1; } if (Net_verify(real, nick, display) == -1) { Net_cleanup(); Client_cleanup(); return -1; } if (Net_setup() == -1) { Net_cleanup(); Client_cleanup(); return -1; } if (Client_setup() == -1) { Net_cleanup(); Client_cleanup(); return -1; } if (Net_start() == -1) { errno = 0; error("Network start failed"); Net_cleanup(); Client_cleanup(); return -1; } if (Client_start() == -1) { errno = 0; error("Window init failed"); Net_cleanup(); Client_cleanup(); return -1; } Input_loop(); Net_cleanup(); Client_cleanup(); return 0; }
void Prot_init(void) { int i, num_bcast, num_token; channel *bcast_channels; channel *token_channels; Mem_init_object( PACK_HEAD_OBJ, sizeof( packet_header ), MAX_PACKETS_IN_STRUCT, 0 ); Mem_init_object( PACKET_BODY, sizeof( packet_body ), MAX_PACKETS_IN_STRUCT, 0 ); Mem_init_object( TOKEN_HEAD_OBJ, sizeof( token_header ), 10, 0 ); Mem_init_object( TOKEN_BODY_OBJ, sizeof( token_body ), 10, 0 ); Mem_init_object( SCATTER, sizeof( scatter ), 200+MAX_PROCS_RING, 0 ); My = Conf_my(); My_index = Conf_proc_by_id( My.id, &My ); GlobalStatus.my_id = My.id; GlobalStatus.packet_delivered = 0; for( i=0; i < MAX_PROCS_RING+1; i++ ) Up_queue[i].exist = 0; for( i=0; i < MAX_PACKETS_IN_STRUCT; i++ ) Packets[i].exist = 0; if ( Conf_debug_initial_sequence() ) { Highest_seq = INITIAL_SEQUENCE_NEAR_WRAP; Highest_fifo_seq = INITIAL_SEQUENCE_NEAR_WRAP; My_aru = INITIAL_SEQUENCE_NEAR_WRAP; Aru = INITIAL_SEQUENCE_NEAR_WRAP; Set_aru = INITIAL_SEQUENCE_NEAR_WRAP -1; Last_discarded = INITIAL_SEQUENCE_NEAR_WRAP; Last_delivered = INITIAL_SEQUENCE_NEAR_WRAP; } else { Highest_seq = 0; Highest_fifo_seq = 0; My_aru = 0; Aru = 0; Set_aru = -1; Last_discarded = 0; Last_delivered = 0; } New_pack.num_elements = 2; New_pack.elements[0].len = sizeof(packet_header); New_pack.elements[0].buf = (char *) new(PACK_HEAD_OBJ); New_pack.elements[1].len = sizeof(packet_body); New_pack.elements[1].buf = (char *) new(PACKET_BODY); New_token.num_elements = 2; New_token.elements[0].len = sizeof(token_header); New_token.elements[0].buf = (char *) new(TOKEN_HEAD_OBJ); New_token.elements[1].len = sizeof(token_body); New_token.elements[1].buf = (char *) new(TOKEN_BODY_OBJ); Send_pack.num_elements = 2; Send_pack.elements[0].len = sizeof(packet_header); Token = (token_header *)New_token.elements[0].buf; Last_token = new(TOKEN_HEAD_OBJ); Last_token->type = 0; Last_token->seq = 0; Last_token->aru = 0; Last_token->flow_control = 0; Last_token->conf_hash = 0; Hurry_pack.num_elements = 1; Hurry_pack.elements[0].len = sizeof(packet_header); Hurry_pack.elements[0].buf = (char *) new(PACKET_BODY); Hurry_head = (packet_header *)Hurry_pack.elements[0].buf; Hurry_head->proc_id = My.id; Hurry_head->type = HURRY_TYPE; Net_init(); bcast_channels = Net_bcast_channel(); token_channels = Net_token_channel(); Net_num_channels( &num_bcast, &num_token); for ( i = 0; i < num_bcast; i++) { E_attach_fd( *bcast_channels, READ_FD, Prot_handle_bcast, 0, NULL, HIGH_PRIORITY ); bcast_channels++; } for ( i = 0; i < num_token; i++) { E_attach_fd( *token_channels, READ_FD, Prot_handle_token, 0, NULL, MEDIUM_PRIORITY ); token_channels++; } FC_init( ); Memb_init(); Net_set_membership( Reg_membership ); }