summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-31 03:44:37 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-31 03:44:37 +0200
commit6980c5190c4d71cd672b88c26a189314b1e01be4 (patch)
tree819d44111646c1167ce3003a8f1096bffdf96af7
parentd877f68c58e3ee0fbc6b0f86326bb91ce2a775e4 (diff)
fix polling logic, use timeout of -1 not 0
-rw-r--r--libasound.c42
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;