diff options
-rw-r--r-- | libasound.c | 42 |
1 files 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; |