void main() { int ret; E_init(); system("clear"); sp_time test_timeout; test_timeout.sec = 5; test_timeout.usec = 0; strncpy(Spread_name, "10080", 5); ret = SP_connect_timeout( Spread_name, User, 0, 1, &Mbox, Private_group, test_timeout ); if( ret != ACCEPT_SESSION ) { SP_error( ret ); Bye(); } printf("Connected to %s with private group %s\n", Spread_name, Private_group ); E_attach_fd( 0, READ_FD, User_command, 0, NULL, LOW_PRIORITY ); E_attach_fd( Mbox, READ_FD, Read_message, 0, NULL, HIGH_PRIORITY ); show_menu(); for(;;) { E_handle_events(); User_command(); } exit (0); }
int main( int argc, char *argv[] ) { int ret; int mver, miver, pver; sp_time test_timeout; test_timeout.sec = 5; test_timeout.usec = 0; server_num = 0; set_max_msgs(25); if (!SP_version( &mver, &miver, &pver)) { printf("main: Illegal variables passed to SP_version()\n"); Bye(); } printf("Spread library version is %d.%d.%d\n", mver, miver, pver); ret = SP_connect_timeout( SPREAD_NAME, NULL, 0, 1, &Mbox, Private_group, test_timeout ); if( ret != ACCEPT_SESSION ) { SP_error( ret ); Bye(); } printf("Client: connected to %s with private group %s\n", SPREAD_NAME, Private_group ); E_init(); E_attach_fd( 0, READ_FD, User_command, 0, NULL, LOW_PRIORITY ); E_attach_fd( Mbox, READ_FD, Read_message, 0, NULL, HIGH_PRIORITY ); Print_menu(); printf("\n > "); fflush(stdout); E_handle_events(); return( 0 ); }
void setup(struct initializers *i) { /* Sets up all ports */ /* and waits for the start_mcast message to start the actual process */ int mcast_addr; int start = 0; int bytes; int num, c, num_groups, r, ret; int service_type = 0; int responded=0; int16 mess_type; int endian_mismatch=0; int response[10]; struct timeval timeout; unsigned char ttl_val; char target_groups[MAX_MEMBERS][MAX_GROUP_NAME]; char logfilename[10]; char sender[MAX_GROUP_NAME]; char groups[10][MAX_GROUP_NAME]; char mess_buf[MAX_MESS_LEN]; sp_time test_timeout; struct packet_structure *p=malloc(sizeof(struct packet_structure)); snprintf(logfilename, 10, "%d.out", machine_index); logfile = fopen(logfilename, "w"); ret = SP_connect_timeout( Spread_name, User, 0, 1, &Mbox, Private_group, test_timeout ); if( ret != ACCEPT_SESSION ) { SP_error( ret ); Bye(); } printf("User: connected to %s with private group %s\n", Spread_name, Private_group ); E_init(); ret = SP_join(Mbox, group); printf("Join group %s:%d\n", group, ret); if (machine_index == 1) { for (c=1; c <= total_machines; c++) { response[c] = 0; completed[c] = 0; } /* Collect up the users, and send start message when everyone is in the group */ response[1]=1; while (responded < 1) { ret = SP_receive( Mbox, &service_type, sender, 100, &num_groups, target_groups, &mess_type, &endian_mismatch, sizeof(mess_buf), mess_buf ); p = (struct packet_structure *)mess_buf; if (p->type == 4) { printf("ret = %d Got machine id %d\n", ret, p->machine_index); /* Add this machine to the array and check to see if we are done */ response[p->machine_index] = 1; printf("Got response from %d\n", p->machine_index); r = 1; for (c=1; c <= total_machines; c++) { if (response[c] == 0) r =0; } if (r==1) responded = 1; } else if (p->type == 3 && machine_index == 1) { completed[p->machine_index] = 1; } } /* Send start sending message to everyone */ if (r=1) /*All ready */ { p->type= 2; printf("Ready to go..\n"); ret= SP_multicast( Mbox, AGREED_MESS, group, 1, sizeof(struct packet_structure), (char *)p ); } } else { /*We are not machine index 1*/ /*Send ready to begin message */ p->type = 4; p->machine_index = machine_index; ret= SP_multicast( Mbox, AGREED_MESS, group, 1, sizeof(struct packet_structure), (char *)p ); printf("Join=%d, group %s\n", ret, group); if( ret < 0 ) { SP_error( ret ); Bye(); } else { printf("Sent: %d\n", ret); } } };
int main( int argc, char *argv[] ) { int ret; #ifdef SPREAD_VERSION int mver, miver, pver; #endif sp_time test_timeout; test_timeout.sec = 5; test_timeout.usec = 0; Usage( argc, argv ); #ifdef SPREAD_VERSION if (!SP_version( &mver, &miver, &pver)) { printf("main: Illegal variables passed to SP_version()\n"); Bye(); } printf("Spread library version is %d.%d.%d\n", mver, miver, pver); #else printf("Spread library version is %1.2f\n", SP_version() ); #endif #ifdef ENABLE_PASSWORD if (Use_Pword) { strncpy(Pword_user.username, Pword_username, 32); Pword_user.username[32] = '\0'; strncpy(Pword_user.password, Pword_password, 8); Pword_user.password[8] = '\0'; SP_set_auth_method("PWORD", pword_authenticate, &Pword_user); } #endif ret = SP_connect_timeout( Spread_name, User, 0, 1, &Mbox, Private_group, test_timeout ); if( ret != ACCEPT_SESSION ) { SP_error( ret ); Bye(); } printf("User: connected to %s with private group %s\n", Spread_name, Private_group ); #ifndef _REENTRANT E_init(); E_attach_fd( 0, READ_FD, User_command, 0, NULL, LOW_PRIORITY ); E_attach_fd( Mbox, READ_FD, Read_message, 0, NULL, HIGH_PRIORITY ); #endif /* _REENTRANT */ Print_menu(); printf("\nUser> "); fflush(stdout); Num_sent = 0; #ifdef _REENTRANT #ifndef ARCH_PC_WIN95 ret = pthread_create( &Read_pthread, NULL, Read_thread_routine, 0 ); #else /* ARCH_PC_WIN95 */ Read_pthread = CreateThread( NULL, 0, Read_thread_routine, NULL, 0, &ret ); #endif /* ARCH_PC_WIN95 */ for(;;) { User_command(); #ifdef __bsdi__ /* bug in BSDI */ sched_yield(); #endif } #else /* _REENTRANT */ #ifndef ARCH_PC_WIN95 E_handle_events(); #else /* ARCH_PC_WIN95 */ for(;;) User_command(); #endif /* ARCH_PC_WIN95 */ #endif /* _REENTRANT */ return( 0 ); }