Without this, para_audiod might not notice for a long time when
a stat client went away.
Also avoid to dump the status twice.
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) {
}
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));
+ else if (ret > 0)
+ force = true;
+ audiod_status_dump(force);
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(true);
}
/* avoid busy loop if server is down */
}
/* avoid busy loop if server is down */
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);
/**
* 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;
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);
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);
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);
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);