From 6980c5190c4d71cd672b88c26a189314b1e01be4 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 31 Oct 2018 03:44:37 +0200 Subject: fix polling logic, use timeout of -1 not 0 --- libasound.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libasound.c b/libasound.c index ffc486d..749a879 100644 --- a/libasound.c +++ b/libasound.c @@ -327,31 +327,31 @@ snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size) snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm) { - struct pollfd pfd[16]; - int nfds = sio_nfds(pcm->hdl); - assert((unsigned int)nfds < ARRAY_SIZE(pfd)); - - // FIXME: should POLLIN / POLLOUT depending on stream - if (!sio_pollfd(pcm->hdl, pfd, POLLOUT)) { - WARNX1("sio_pollfd failed"); - goto fail; - } - - errno = 0; - while ((nfds = poll(pfd, nfds, 0)) < 0) { - if (errno == EINVAL) { - WARNX1("poll EINVAL"); + while (1) { + struct pollfd pfd[16]; + int nfds = sio_nfds(pcm->hdl); + assert((unsigned int)nfds < ARRAY_SIZE(pfd)); + + // FIXME: should POLLIN / POLLOUT depending on stream + if (!sio_pollfd(pcm->hdl, pfd, POLLOUT)) { + WARNX1("sio_pollfd failed"); goto fail; } - } - int events = 0; - for (int i = 0; i < nfds; ++i) - events |= sio_revents(pcm->hdl, pfd); + errno = 0; + while ((nfds = poll(pfd, nfds, -1)) < 0) { + if (errno == EINVAL) { + WARNX1("poll EINVAL"); + goto fail; + } + } - // FIXME: should POLLIN / POLLOUT depending on stream - if (!(events & POLLOUT)) - goto fail; + const int events = sio_revents(pcm->hdl, pfd); + if (!(events & (POLLOUT | POLLIN))) + continue; + + break; + } return pcm->hw.par.appbufsz; -- cgit v1.2.3