commit fc4a38afafeec3a23f264e76659b3405d2d7cc48 from: Omar Polo date: Thu May 19 13:57:08 2022 UTC don't set the imsg fd as blocking mode just do a poll before imsg_read in player_disptach to wait for data to read. It's not performance-critical code, so this is fine. If it were important not to do an extra poll(2), for example when we're called is called after player_pendingimsg we already know there's something to read, we could move the polling in the case `n == 0' below. commit - 90122a37e6f55f08fd979f7b07ba20a49952faf8 commit + fc4a38afafeec3a23f264e76659b3405d2d7cc48 blob - c62f252b1076d5bf82b1fff5281a68416e9112a7 blob + 5fdc9aaf6d8e883142898ac8286585135a723535 --- player.c +++ player.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -139,12 +138,18 @@ player_enqueue(struct imsg *imsg) int player_dispatch(void) { + struct pollfd pfd; struct imsg imsg; ssize_t n; int ret; if (halted != 0) return IMSG_STOP; + + pfd.fd = ibuf->fd; + pfd.events = POLLIN; + if (poll(&pfd, 1, INFTIM) == -1) + fatal("poll"); if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) fatalx("imsg_read"); @@ -265,7 +270,8 @@ play(const void *buf, size_t len) int player(int debug, int verbose) { - int flags, r; + int r; + log_init(debug, LOG_DAEMON); log_setverbose(verbose); @@ -283,12 +289,6 @@ player(int debug, int verbose) audio_init(); - /* mark fd as blocking i/o mode */ - if ((flags = fcntl(3, F_GETFL)) == -1) - fatal("fcntl(F_GETFL)"); - if (fcntl(3, F_SETFL, flags & ~O_NONBLOCK) == -1) - fatal("fcntl F_SETFL O_NONBLOCK"); - ibuf = xmalloc(sizeof(*ibuf)); imsg_init(ibuf, 3);