diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-31 04:00:14 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2018-10-31 04:00:14 +0200 |
commit | 4c27d6dd84cfc71c1345bb6f7590a7bd7e3dcfb2 (patch) | |
tree | b9eec958d162a534823500091cffca17fa0489c6 | |
parent | 904b83da068c42b560c4b3d7a622c71f46c1f1cd (diff) |
don't while loop in poll
not really sure why sio_revents returns 0 here, but I'll investigate it
more later. The poll should block untill POLLOUT or POLLHUP.
-rw-r--r-- | libasound.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/libasound.c b/libasound.c index 749a879..92398cf 100644 --- a/libasound.c +++ b/libasound.c @@ -327,32 +327,29 @@ 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) { - 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; - } - - errno = 0; - while ((nfds = poll(pfd, nfds, -1)) < 0) { - if (errno == EINVAL) { - WARNX1("poll EINVAL"); - goto fail; - } - } + struct pollfd pfd[16]; + int nfds = sio_nfds(pcm->hdl); + assert((unsigned int)nfds < ARRAY_SIZE(pfd)); - const int events = sio_revents(pcm->hdl, pfd); - if (!(events & (POLLOUT | POLLIN))) - continue; + // FIXME: should POLLIN / POLLOUT depending on stream + if (!sio_pollfd(pcm->hdl, pfd, POLLOUT)) { + WARNX1("sio_pollfd failed"); + goto fail; + } - break; + // FIXME: timeout should be period time + errno = 0; + while ((nfds = poll(pfd, nfds, -1)) < 0) { + if (errno == EINVAL) { + WARNX1("poll EINVAL"); + goto fail; + } } + const int events = sio_revents(pcm->hdl, pfd); + if (!(events & (POLLOUT | POLLIN))) + goto fail; + return pcm->hw.par.appbufsz; fail: |