All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Ossman <ossman@cendio.se>
To: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH] Make snd_hctl_wait() respect the API
Date: Fri, 26 May 2006 11:40:44 +0200	[thread overview]
Message-ID: <4476CD1C.1020108@cendio.se> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 229 bytes --]

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>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: hcontrol-wait.patch --]
[-- Type: text/x-patch; name="hcontrol-wait.patch", Size: 2012 bytes --]

Index: hcontrol.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/control/hcontrol.c,v
retrieving revision 1.37
diff -u -r1.37 hcontrol.c
--- hcontrol.c	27 Feb 2006 09:58:32 -0000	1.37
+++ hcontrol.c	25 May 2006 22:52:59 -0000
@@ -657,22 +657,52 @@
  * \brief Wait for a HCTL to become ready (i.e. at least one event pending)
  * \param hctl HCTL handle
  * \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)
 {
-	struct pollfd pfd;
-	int err;
-	err = snd_hctl_poll_descriptors(hctl, &pfd, 1);
+	struct pollfd *pfd;
+	unsigned short *revents;
+	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)
 		return err;
-	if (! err)
-		return 0;
-	assert(err == 1);
-	err = poll(&pfd, 1, timeout);
-	if (err < 0)
-		return -errno;
-	return 0;
+	if (err != npfds) {
+		SNDMSG("invalid poll descriptors %d\n", err);
+		return -EIO;
+	}
+	do {
+		pollio = 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;
 }
 
 /**

[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



[-- Attachment #3: Type: text/plain, Size: 161 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-devel

             reply	other threads:[~2006-05-26  9:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-26  9:40 Pierre Ossman [this message]
2006-05-26 15:27 ` [PATCH] Make snd_hctl_wait() respect the API Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4476CD1C.1020108@cendio.se \
    --to=ossman@cendio.se \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.