From 4c27d6dd84cfc71c1345bb6f7590a7bd7e3dcfb2 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Wed, 31 Oct 2018 04:00:14 +0200 Subject: 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. --- libasound.c | 41 +++++++++++++++++++---------------------- 1 file 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: -- cgit v1.2.3-70-g09d2