- if (audiod_status == AUDIOD_OFF)
- goto out;
- if (stat_task->sa_time_diff_sign > 0)
- tv_diff(&stat_task->server_stream_start, &stat_task->sa_time_diff,
- &adj_stream_start);
- else
- tv_add(&stat_task->server_stream_start, &stat_task->sa_time_diff,
- &adj_stream_start);
- tmp = adj_stream_start;
- if (newest_stime && audiod_status == AUDIOD_ON) {
- tv_diff(newest_stime, &adj_stream_start, &diff);
- if (tv2ms(&diff) < 5000) {
- tmp = *newest_stime;
- use_server_time = 0;
+ PARA_INFO_LOG("adding client on fd %d\n", fd);
+ new_client = para_calloc(sizeof(struct stat_client));
+ new_client->fd = fd;
+ new_client->item_mask = mask;
+ if (parser_friendly)
+ new_client->flags = SCF_PARSER_FRIENDLY;
+ para_list_add(&new_client->node, &client_list);
+ dump_stat_client_list();
+ num_clients++;
+ return 1;
+}
+/**
+ * Write a message to all connected status clients.
+ *
+ * \param item_num The number of the status item of \a msg.
+ *
+ * On write errors, remove the status client from the client list and close its
+ * file descriptor.
+ */
+void stat_client_write_item(int item_num)
+{
+ struct stat_client *sc, *tmp;
+ struct para_buffer pb = {.flags = 0};
+ struct para_buffer pfpb = {.flags = PBF_SIZE_PREFIX};
+ const uint64_t one = 1;
+
+ list_for_each_entry_safe(sc, tmp, &client_list, node) {
+ int fd = sc->fd, ret;
+
+ if (!((one << item_num) & sc->item_mask))
+ continue;
+ if (write_ok(fd) > 0) {
+ struct para_buffer *b =
+ (sc->flags & SCF_PARSER_FRIENDLY)? &pfpb : &pb;
+ char *msg = stat_item_values[item_num];
+ if (!b->buf)
+ WRITE_STATUS_ITEM(b, item_num, "%s\n",
+ msg? msg : "");
+ ret = write(fd, b->buf, b->offset);
+ if (ret == b->offset)
+ continue;