static void dgram_chargen( const struct server *serp ) { char buf[ BUFFER_SIZE ] ; char *p ; unsigned int len ; union xsockaddr lsin ; socklen_t sin_len = 0 ; int fd = SERVER_FD( serp ) ; unsigned int left = sizeof( buf ) ; const char *func = "dgram_chargen"; if ( SC_IPV4( SVC_CONF( SERVER_SERVICE( serp ) ) ) ) sin_len = sizeof( struct sockaddr_in ); else if ( SC_IPV6( SVC_CONF( SERVER_SERVICE( serp ) ) ) ) sin_len = sizeof( struct sockaddr_in6 ); if ( recvfrom( fd, buf, sizeof( buf ), 0, SA( &lsin ), &sin_len ) == -1 ) return ; #if BUFFER_SIZE < LINE_LENGTH+2 bad_variable = 1 ; /* this will cause a compilation error */ #endif for ( p = buf ; left > 2 ; left -= len, p += len ) { len = min( LINE_LENGTH+2, left ) ; if ( generate_line( p, len ) == NULL ) break ; } (void) sendto( fd, buf, p-buf, 0, SA( &lsin ), sin_len ) ; }
static void stream_chargen( const struct server *serp ) { char line_buf[ LINE_LENGTH+2 ] ; int descriptor = SERVER_FD( serp ) ; struct service *svc = SERVER_SERVICE( serp ); if( SVC_WAITS( svc ) ) { descriptor = accept(descriptor, NULL, NULL); if ( descriptor == -1 ) { if ((errno == EMFILE) || (errno == ENFILE)) cps_service_stop(svc, "no available descriptors"); return; } } (void) shutdown( descriptor, 0 ) ; close_all_svc_descriptors(); for ( ;; ) { if ( generate_line( line_buf, sizeof( line_buf ) ) == NULL ) break ; if ( write_buf( descriptor, line_buf, sizeof( line_buf ) ) == FAILED ) break ; } if( SVC_WAITS( svc ) ) /* Service forks, so close it */ Sclose(descriptor); }
void generate_set(struct passed_args *args, struct set *ya_set, long index) { /* Function to generate a cache set */ char number_of_lines = args->associativity_num; struct cache_line *lines = malloc(number_of_lines * sizeof(struct cache_line)); int i; ya_set->index = index; ya_set->number_of_lines = number_of_lines; /* Generating and initializing lines of cache set */ for (i = 0; i < number_of_lines; i++) { generate_line(args, &lines[i], i); } ya_set->lines = lines; }
void test_strings_construct(test_strings *ts, int num_strings, int min_len, int max_len, int min_wait, int max_wait) { int i; int last_wait=0; ts->num_strings=num_strings; ts->strings=(test_string*)malloc(sizeof(test_string)*num_strings); ts->buf=(char*)malloc(max_len*num_strings); ts->next_send=0; ts->next_receive=0; for(i=0; i<ts->num_strings; i++) { ts->strings[i].len=rand_range(min_len, max_len); last_wait+=rand_range(min_wait, max_wait); ts->strings[i].time=start_time+last_wait; ts->strings[i].str=ts->buf+(max_len*i); generate_line(ts->strings[i].str, ts->strings[i].len); } }