From 4e226ad64a48792355710e4e45e76c694914ae74 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 12 Jun 2011 13:58:49 +0200 Subject: [PATCH] audiod: Use non-blocking writes for stat clients. This allows to kill the call to write_ok() which involves a select system call. --- audiod_command.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/audiod_command.c b/audiod_command.c index a54bd82d..0f7aa7e6 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -120,24 +120,22 @@ void stat_client_write_item(int item_num) struct para_buffer pb = {.flags = 0}; struct para_buffer pfpb = {.flags = PBF_SIZE_PREFIX}; const uint64_t one = 1; + char *msg = stat_item_values[item_num]; + struct para_buffer *b; 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) - (void)WRITE_STATUS_ITEM(b, item_num, "%s\n", - msg? msg : ""); - ret = write(fd, b->buf, b->offset); - if (ret == b->offset) - continue; - } - /* write error or fd not ready for writing */ + b = (sc->flags & SCF_PARSER_FRIENDLY)? &pfpb : &pb; + if (!b->buf) + (void)WRITE_STATUS_ITEM(b, item_num, "%s\n", + msg? msg : ""); + ret = write(fd, b->buf, b->offset); + if (ret == b->offset) + continue; + /* write error or short write */ close(fd); num_clients--; PARA_INFO_LOG("deleting client on fd %d\n", fd); @@ -147,8 +145,6 @@ void stat_client_write_item(int item_num) } free(pb.buf); free(pfpb.buf); -// if (num_clients) -// PARA_DEBUG_LOG("%d client(s)\n", num_clients); } /** @@ -307,6 +303,9 @@ int com_stat(int fd, int argc, char **argv) const uint64_t one = 1; struct para_buffer b = {.flags = 0}; + ret = mark_fd_nonblocking(fd); + if (ret < 0) + return ret; for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (arg[0] != '-') -- 2.39.5