]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
audiod: Force status dump every 5 seconds.
authorAndre Noll <maan@systemlinux.org>
Sat, 20 Jul 2013 12:22:04 +0000 (14:22 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 22 Sep 2013 00:29:19 +0000 (02:29 +0200)
Without this, para_audiod might not notice for a long time when
a stat client went away.

Also avoid to dump the status twice.

audiod.c
audiod.h
audiod_command.c

index dcf2c14738d3336bcce19dbc9a2fcd565dcded7a..9ed319f4c27ab7e202082552f1a0ffa9328fe60f 100644 (file)
--- 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;
        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) {
 
        tv_add(&last_status_dump, &delay, &tmp);
        if (tv_diff(&tmp, now, NULL) < 0) {
-               audiod_status_dump();
                last_status_dump = *now;
                last_status_dump = *now;
+               force = true;
        }
 
        ret = handle_connect(ct->fd, &s->rfds);
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        }
 
        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;
 }
 
        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;
        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 */
 }
 
 /* avoid busy loop if server is down */
index 6a1e8f6dd1dea59df24ec69a5caba6fc53f89306..5485b4243d56399b804cb368048b0f715a05ed66 100644 (file)
--- 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 __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);
 
 char *get_time_string(int slot_num);
 struct btr_node *audiod_get_btr_root(void);
 
index 118c22a00351504f5a81040cae0045ce74641be9..07b2c81c2a528d04a92b6210bd3a5b48625823d3 100644 (file)
@@ -486,8 +486,10 @@ out:
 
 /**
  * Send the current audiod status to all connected stat clients.
 
 /**
  * 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;
 {
        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) {
        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);
                        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];
 
        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);
                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();
 
        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);
                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();
 
        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);
                free(old);
                stat_item_values[SI_DECODER_FLAGS] = new;
                stat_client_write_item(SI_DECODER_FLAGS);