/* Evan Markensohn ( erm6 ) 04/06/00 ECES 338 - Assignment #6 Recitation section Monday @ 4:30 Operating System: SunOS 5.7 Compiler: gcc 2.8.1 - ( gcc producer.c prod_cons_clnt.c prod_cons_xdr.c -o Producer -lnsl ) */ #include #include #include #include /* include the rpcgen created header file. */ #include "prod_cons.h" #define RUNS 25 /* Let's take in the RPC server hostname from the command line */ int main( int argc, char *argv[] ) { CLIENT *client; int dummy, i, *value; char *server, *thetime; produce_parameters data; struct timeval time_struct; struct timezone time_zone_struct; struct hname my_name; /* Initialize stupid time buffer */ thetime = (char *) malloc( 65 ); /* User must supply command line argument */ if( argc != 2 ) { printf( "You must supply the hostname of the RPC server as\n" ); printf( "the only command line argument. Exitting....\n\n" ); exit( 2 ); } server = argv[1]; /* Create client handle */ if( ( client = clnt_create( server, DISPLAY_PRG, DISPLAY_VER, "tcp" ) ) == (CLIENT *) NULL ) { clnt_pcreateerror( server ); exit( 2 ); } /* Get my hostname */ if( gethostname( my_name.name, 257 ) == -1 ) { perror( "gethostname() failed" ); exit( 1 ); } /* Get the current time */ if( gettimeofday( &time_struct, &time_zone_struct ) == -1 ) { perror( "gettimeofday() failed" ); exit( 1 ); } /* Get human readable time and strip */ thetime = ctime( (time_t *) &time_struct.tv_sec ); thetime[strlen( thetime ) - 2] = '\0'; value = initialize_buffer_1( &my_name, client ); if( *value == 0 ) { printf( "<%s: %s> Buffer initialization attempt successful.\n\n", my_name.name, thetime ); } else { printf( "<%s: %s> Buffer initialization attempt failed.\n\n", my_name.name, thetime ); } /* Loop producing calls */ for( i = 0; i < RUNS; i++ ) { /* Get the current time */ if( gettimeofday( &time_struct, &time_zone_struct ) == -1 ) { perror( "gettimeofday() failed" ); exit( 1 ); } /* Get human readable time and strip */ thetime = ctime( (time_t *) &time_struct.tv_sec ); thetime[strlen( thetime ) - 2] = '\0'; value = element_index_to_produce_1( &my_name, client ); if( *value != -1 ) { printf( "<%s: %s> Producing for the index %i for buffer.\n", my_name.name, thetime, *value ); data.index = *value; data.value = rand() % 100; strcpy( data.name, my_name.name ); value = produce_buffer_element_1( &data, client ); printf( "<%s: %s> Inserting value %i into buffer[%i].\n\n", my_name.name, thetime, data.value, data.index ); } else { printf( "<%s: %s> Failed to produce( buffer full ).\n\n", my_name.name, thetime ); } sleep( rand() % 3 ); } /* Destroying client */ printf( "Destroying client...\n\n" ); clnt_destroy( client ); return( 0 ); }