libsndio: Don't use poll(2) for output on the control device.
authorratchov <ratchov@openbsd.org>
Tue, 23 Jul 2024 08:36:51 +0000 (08:36 +0000)
committerratchov <ratchov@openbsd.org>
Tue, 23 Jul 2024 08:36:51 +0000 (08:36 +0000)
The AUDIO_MIXER_WRITE ioctl always succeeds without blocking, so no
need to use poll(2) for output. The audio(4) control device driver
doesn't implement the corresponding struct filterops anyway.

Fixes delayed level settings.

lib/libsndio/sioctl_sun.c

index 64129ac..886c820 100644 (file)
@@ -472,9 +472,18 @@ sioctl_sun_pollfd(struct sioctl_hdl *addr, struct pollfd *pfd, int events)
 {
        struct sioctl_sun_hdl *hdl = (struct sioctl_sun_hdl *)addr;
 
+       hdl->events = events;
+
+       /*
+        * The audio(4) driver doesn't support POLLOUT, so if it is
+        * requested, don't set the struct pollfd. The AUDIO_MIXER_WRITE
+        * ioctl never blocks, so just return POLLOUT in sioctl_sun_revents().
+        */
+       if (events & POLLOUT)
+               return 0;
+
        pfd->fd = hdl->fd;
        pfd->events = POLLIN;
-       hdl->events = events;
        return 1;
 }
 
@@ -485,6 +494,9 @@ sioctl_sun_revents(struct sioctl_hdl *arg, struct pollfd *pfd)
        struct volume *vol;
        int idx, n;
 
+       if (hdl->events & POLLOUT)
+               return POLLOUT;
+
        if (pfd->revents & POLLIN) {
                while (1) {
                        n = read(hdl->fd, &idx, sizeof(int));
@@ -514,5 +526,5 @@ sioctl_sun_revents(struct sioctl_hdl *arg, struct pollfd *pfd)
                                return POLLHUP;
                }
        }
-       return hdl->events & POLLOUT;
+       return 0;
 }