X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=5ef5778107e22dd44e44402f2961cc0f6192a594;hp=dcf2c14738d3336bcce19dbc9a2fcd565dcded7a;hb=db3534991b7c1d72f9ceed435ecbcba39660a758;hpb=e34e5f6ddb04a9c4fb0aa8e21bb2aeb7c03d687a diff --git a/audiod.c b/audiod.c index dcf2c147..5ef57781 100644 --- a/audiod.c +++ b/audiod.c @@ -1031,19 +1031,35 @@ static int command_post_select(struct sched *s, struct task *t) int ret; struct command_task *ct = container_of(t, struct command_task, task); static struct timeval last_status_dump; - struct timeval tmp, delay = {0, 500 * 1000}; - - tv_add(&last_status_dump, &delay, &tmp); - if (tv_diff(&tmp, now, NULL) < 0) { - audiod_status_dump(); - last_status_dump = *now; - } + struct timeval tmp, delay; + bool force = true; ret = handle_connect(ct->fd, &s->rfds); if (ret < 0) PARA_ERROR_LOG("%s\n", para_strerror(-ret)); - audiod_status_dump(); - return 0; + else if (ret > 0) + goto dump; + + /* if last status dump was less than 500ms ago, do nothing */ + delay.tv_sec = 0; + delay.tv_usec = 500 * 1000; + tv_add(&last_status_dump, &delay, &tmp); + if (tv_diff(now, &tmp, NULL) < 0) + return 0; + + /* + * If last status dump was more than 5s ago, force update. Otherwise, + * update only those items that have changed. + */ + delay.tv_sec = 5; + delay.tv_usec = 0; + tv_add(&last_status_dump, &delay, &tmp); + if (tv_diff(now, &tmp, NULL) < 0) + force = false; +dump: + audiod_status_dump(force); + last_status_dump = *now; + return 1; } static void init_command_task(struct command_task *ct) @@ -1066,7 +1082,7 @@ static void close_stat_pipe(void) stat_task->offset_seconds = 0; stat_task->vss_status = 0; stat_task->current_audio_format_num = -1; - audiod_status_dump(); + audiod_status_dump(true); } /* avoid busy loop if server is down */