From: Michal Sojka Date: Thu, 10 Jul 2008 09:51:25 +0000 (+0200) Subject: Fixes for demo X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fwp.git/commitdiff_plain/4cd6a5c25c208275571a1d561923d7d2fdd2129d Fixes for demo --- diff --git a/wme_test/wclient.c b/wme_test/wclient.c index e744159..ce04207 100644 --- a/wme_test/wclient.c +++ b/wme_test/wclient.c @@ -37,7 +37,7 @@ char *opt_interface; unsigned opt_jitter = 0; char *opt_output = "delay_stats"; unsigned opt_count_sec = 0; -unsigned opt_def_bandwidth = 200; +unsigned opt_def_bandwidth = 50; unsigned opt_def_period_msec = 0; int opt_granularity_usec = MIN_GRANULARITY; bool opt_wait_for_queue_is_full; /* Don't gather any statistics until any queue is full */ @@ -46,6 +46,8 @@ char *opt_comment = NULL; bool some_queue_is_full = false; struct timespec reset_timestamp; +bool some_contract_not_accepted = false; + /* Locked when some queue is full to prevent multiple resets of statstics. */ pthread_mutex_t queue_full_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -53,6 +55,7 @@ pthread_mutex_t queue_full_mutex = PTHREAD_MUTEX_INITIALIZER; int ac_sockfd[AC_NUM]; struct receiver { + bool valid; pthread_t thread; unsigned received, last_received; }; @@ -95,6 +98,8 @@ struct stream { #ifndef WITH_FWP struct sockaddr_in rem_addr; #else + fwp_contract_d_t contract_send; + fwp_contract_d_t contract_resp; fwp_endpoint_d_t endpoint; fwp_endpoint_d_t resp_endpoint; fwp_vres_d_t vres; @@ -155,8 +160,10 @@ void stopper() /* Interrupt all receivers */ #ifdef WITH_FWP for (i=0; i < nr_streams; i++) { - pthread_kill(streams[i].receiver.thread, SIGUSR1); - } + if (streams[i].receiver.valid) pthread_kill(streams[i].receiver.thread, SIGUSR1); + if (streams[i].contract_send) fwp_contract_cancel(streams[i].contract_send); + if (streams[i].contract_resp)fwp_contract_cancel(streams[i].contract_resp); + } #else for (i=0; i < AC_NUM; i++) { pthread_kill(receivers[i].thread, SIGUSR1); @@ -599,7 +606,6 @@ out: static int negotiate_contract_for_stream_fwp(struct stream *stream) { fwp_contract_t contract; - fwp_contract_d_t contract_d; fwp_vres_d_t vres2; int ret; @@ -609,11 +615,12 @@ static int negotiate_contract_for_stream_fwp(struct stream *stream) contract.period_usec = stream->period_usec; contract.deadline_usec = 3*stream->period_usec; - contract_d = fwp_contract_create(&contract); - ret = fwp_contract_negotiate(contract_d, &stream->vres); + stream->contract_send = fwp_contract_create(&contract); + ret = fwp_contract_negotiate(stream->contract_send, &stream->vres); if (ret != 0) { - fprintf(stderr, "Send contract was not accepted\n"); - exit(1); + stream->contract_send = NULL; + fprintf(stderr, "Send contract was not accepted\n\n\n"); + return ret; } /* Contract for server->client stream */ @@ -622,11 +629,12 @@ static int negotiate_contract_for_stream_fwp(struct stream *stream) contract.period_usec = stream->period_usec; contract.deadline_usec = 3*stream->period_usec; - contract_d = fwp_contract_create(&contract); - ret = fwp_contract_negotiate(contract_d, &vres2); + stream->contract_resp = fwp_contract_create(&contract); + ret = fwp_contract_negotiate(stream->contract_resp, &vres2); if (ret != 0) { - fprintf(stderr, "Receive contract was not accepted\n"); - exit(1); + stream->contract_resp = NULL; + fprintf(stderr, "Receive contract was not accepted\n\n\n"); + return ret; } /* We don't use the vres at server, since the server doesn't @@ -672,13 +680,13 @@ static void create_stream_endpoint_fwp(struct stream *stream) unsigned int port; fwp_endpoint_get_params(stream->resp_endpoint, NULL, &port, NULL); stream->resp_port = port; - printf("resp_port = %d\n", port); ret = pthread_create(&stream->receiver.thread, NULL, receiver, (void*)stream); if (ret) { perror("Error while creating receiver\n"); exit(1); } + stream->receiver.valid = true; } else { char str[100]; @@ -757,8 +765,9 @@ calc_stream_params(struct stream *stream) } else { char buf[200]; stream_to_text(buf, sizeof(buf), stream, 0); - fprintf(stderr, "Contract hasn't been accepted: %s\n", buf); + fprintf(stderr, "Contract hasn't been accepted:\n%s\n\n", buf); stream->bandwidth_bps = 0; + some_contract_not_accepted = true; } } @@ -887,7 +896,7 @@ void print_status(int seconds) for (i = 0; i <= nr_streams; i++) { if (i>0) s = &streams[i-1]; - y=i+3; + y=i; x=0; addfield("Stream", "%d", i); addfield("Bandwidth", "%s", bandwidth_to_text(s1, s->bandwidth_bps)); @@ -895,7 +904,7 @@ void print_status(int seconds) addfield("Period ", "%s", usec_to_text(s1, s->period_usec)); addfield("AC ", "%s", ac_to_text[s->ac]); addfield("Worst-case delay", "%s", usec_to_text(s1, s->wc_delay)); - addfield("Received responses", "%d", s->received); + addfield("Received responses", "%lld", s->received); } refresh(); } @@ -1060,6 +1069,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error while creating receiver %d\n",rc); return 1; } + receivers[ac].valid = true; } #endif @@ -1088,19 +1098,24 @@ int main(int argc, char *argv[]) } } - init_gui(); - - seconds = 0; - while (!exit_flag) { - sleep(1); - seconds++; - print_status(seconds); - if (seconds == opt_count_sec) - stopper(); + if (some_contract_not_accepted) { + stopper(); + } else { + init_gui(); + + seconds = 0; + while (!exit_flag) { + sleep(1); + seconds++; + print_status(seconds); + if (seconds == opt_count_sec) + stopper(); + } } #ifdef WITH_FWP endwin(); + fwp_done(); #endif fprintf(stderr, "\nWaiting for threads to finish\n"); wait_for_all_threads_to_finish();