From: Andre Noll Date: Sat, 20 Jul 2013 12:22:04 +0000 (+0200) Subject: audiod: Force status dump every 5 seconds. X-Git-Tag: v0.5.1~11^2~1 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=d80f5d3ac72591069728fd786d9a0fd96ccfd06f;p=paraslash.git audiod: Force status dump every 5 seconds. Without this, para_audiod might not notice for a long time when a stat client went away. Also avoid to dump the status twice. --- diff --git a/audiod.c b/audiod.c index dcf2c147..9ed319f4 100644 --- a/audiod.c +++ b/audiod.c @@ -1031,18 +1031,21 @@ 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}; + struct timeval tmp, delay = {5, 0}; + bool force = false; tv_add(&last_status_dump, &delay, &tmp); if (tv_diff(&tmp, now, NULL) < 0) { - audiod_status_dump(); last_status_dump = *now; + force = true; } ret = handle_connect(ct->fd, &s->rfds); if (ret < 0) PARA_ERROR_LOG("%s\n", para_strerror(-ret)); - audiod_status_dump(); + else if (ret > 0) + force = true; + audiod_status_dump(force); return 0; } @@ -1066,7 +1069,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 */ diff --git a/audiod.h b/audiod.h index 6a1e8f6d..5485b424 100644 --- a/audiod.h +++ b/audiod.h @@ -68,7 +68,7 @@ extern int audiod_status; void __noreturn clean_exit(int status, const char *msg); int handle_connect(int accept_fd, fd_set *rfds); -void audiod_status_dump(void); +void audiod_status_dump(bool force); char *get_time_string(int slot_num); struct btr_node *audiod_get_btr_root(void); diff --git a/audiod_command.c b/audiod_command.c index 118c22a0..07b2c81c 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -486,8 +486,10 @@ out: /** * Send the current audiod status to all connected stat clients. + * + * \param force Whether to write unchanged items. */ -void audiod_status_dump(void) +void audiod_status_dump(bool force) { int slot_num = get_play_time_slot_num(); char *old, *new; @@ -495,7 +497,7 @@ void audiod_status_dump(void) old = stat_item_values[SI_PLAY_TIME]; new = get_time_string(slot_num); if (new) { - if (!old || strcmp(old, new)) { + if (force || !old || strcmp(old, new)) { free(old); stat_item_values[SI_PLAY_TIME] = new; stat_client_write_item(SI_PLAY_TIME); @@ -505,7 +507,7 @@ void audiod_status_dump(void) new = get_server_uptime_str(now); old = stat_item_values[SI_AUDIOD_UPTIME]; - if (!old || strcmp(old, new)) { + if (force || !old || strcmp(old, new)) { free(old); stat_item_values[SI_AUDIOD_UPTIME] = new; stat_client_write_item(SI_AUDIOD_UPTIME); @@ -514,7 +516,7 @@ void audiod_status_dump(void) old = stat_item_values[SI_AUDIOD_STATUS]; new = audiod_status_string(); - if (!old || strcmp(old, new)) { + if (force || !old || strcmp(old, new)) { free(old); stat_item_values[SI_AUDIOD_STATUS] = new; stat_client_write_item(SI_AUDIOD_STATUS); @@ -523,7 +525,7 @@ void audiod_status_dump(void) old = stat_item_values[SI_DECODER_FLAGS]; new = decoder_flags(); - if (!old || strcmp(old, new)) { + if (force || !old || strcmp(old, new)) { free(old); stat_item_values[SI_DECODER_FLAGS] = new; stat_client_write_item(SI_DECODER_FLAGS);