mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-31 22:25:35 -04:00
Make snd_hctl_wait() respect the API
snd_hctl_wait() currently makes a lot of assumptions that fall outside the defined API. snd_pcm_wait(), however, follows the API nicely so the new version is based on that. Signed-off-by: Pierre Ossman <ossman@cendio.se>
This commit is contained in:
parent
3fd9369990
commit
2a7f35347b
1 changed files with 41 additions and 11 deletions
|
|
@ -657,22 +657,52 @@ unsigned int snd_hctl_get_count(snd_hctl_t *hctl)
|
||||||
* \brief Wait for a HCTL to become ready (i.e. at least one event pending)
|
* \brief Wait for a HCTL to become ready (i.e. at least one event pending)
|
||||||
* \param hctl HCTL handle
|
* \param hctl HCTL handle
|
||||||
* \param timeout maximum time in milliseconds to wait
|
* \param timeout maximum time in milliseconds to wait
|
||||||
* \return 0 otherwise a negative error code on failure
|
* \return a positive value on success otherwise a negative error code
|
||||||
|
* \retval 0 timeout occurred
|
||||||
|
* \retval 1 an event is pending
|
||||||
*/
|
*/
|
||||||
int snd_hctl_wait(snd_hctl_t *hctl, int timeout)
|
int snd_hctl_wait(snd_hctl_t *hctl, int timeout)
|
||||||
{
|
{
|
||||||
struct pollfd pfd;
|
struct pollfd *pfd;
|
||||||
int err;
|
unsigned short *revents;
|
||||||
err = snd_hctl_poll_descriptors(hctl, &pfd, 1);
|
int i, npfds, pollio, err, err_poll;
|
||||||
|
|
||||||
|
npfds = snd_hctl_poll_descriptors_count(hctl);
|
||||||
|
if (npfds <= 0 || npfds >= 16) {
|
||||||
|
SNDERR("Invalid poll_fds %d\n", npfds);
|
||||||
|
return -EIO;
|
||||||
|
}
|
||||||
|
pfd = alloca(sizeof(*pfd) * npfds);
|
||||||
|
revents = alloca(sizeof(*revents) * npfds);
|
||||||
|
err = snd_hctl_poll_descriptors(hctl, pfd, npfds);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
if (! err)
|
if (err != npfds) {
|
||||||
return 0;
|
SNDMSG("invalid poll descriptors %d\n", err);
|
||||||
assert(err == 1);
|
return -EIO;
|
||||||
err = poll(&pfd, 1, timeout);
|
}
|
||||||
if (err < 0)
|
do {
|
||||||
return -errno;
|
pollio = 0;
|
||||||
return 0;
|
err_poll = poll(pfd, npfds, timeout);
|
||||||
|
if (err_poll < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
continue;
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
if (! err_poll)
|
||||||
|
break;
|
||||||
|
err = snd_hctl_poll_descriptors_revents(hctl, pfd, npfds, revents);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
for (i = 0; i < npfds; i++) {
|
||||||
|
if (revents[i] & (POLLERR | POLLNVAL))
|
||||||
|
return -EIO;
|
||||||
|
if ((revents[i] & (POLLIN | POLLOUT)) == 0)
|
||||||
|
continue;
|
||||||
|
pollio++;
|
||||||
|
}
|
||||||
|
} while (! pollio);
|
||||||
|
return err_poll > 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue