All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@lists.sourceforge.net
Subject: return value of snd_pcm_wait()
Date: Mon, 14 Jul 2003 16:24:26 +0200	[thread overview]
Message-ID: <s5hel0tuqxx.wl@alsa2.suse.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 489 bytes --]

Hi,

currently, snd_pcm_wait() returns -EIO if any error happens during
poll(), regardless what really happened.
i believe it's better to return a reasonable error code corresponding
to the current state, such as -EPIPE and -ESTRPIPE.

the attached patch adds this feature by calling snd_pcm_state() in
snd_pcm_wait().  this cleans up also some codes there.

i think there is no major drawback by this change.  but i'd like to
ask here to make it sure.

do you see any problems?


Takashi

[-- Attachment #2: pcm-wait-fix.dif --]
[-- Type: application/octet-stream, Size: 1767 bytes --]

Index: alsa-lib/src/pcm/pcm.c
===================================================================
RCS file: /suse/tiwai/cvs/alsa/alsa-lib/src/pcm/pcm.c,v
retrieving revision 1.134
diff -u -r1.134 pcm.c
--- alsa-lib/src/pcm/pcm.c	24 Jun 2003 10:03:53 -0000	1.134
+++ alsa-lib/src/pcm/pcm.c	14 Jul 2003 14:20:29 -0000
@@ -2000,6 +2000,7 @@
  * \param pcm PCM handle
  * \param timeout maximum time in milliseconds to wait
  * \return a positive value on success otherwise a negative error code
+ *         (-EPIPE for the xrun and -ESTRPIPE for the suspended status) 
  * \retval 0 timeout occurred
  * \retval 1 PCM stream is ready for I/O
  */
@@ -2016,8 +2017,17 @@
 	err = snd_pcm_poll_descriptors_revents(pcm, &pfd, 1, &revents);
 	if (err < 0)
 		return err;
-	if (revents & (POLLERR | POLLNVAL))
-		return -EIO;
+	if (revents & (POLLERR | POLLNVAL)) {
+		/* check more precisely */
+		switch (snd_pcm_state(pcm)) {
+		case SND_PCM_STATE_XRUN:
+			return -EPIPE;
+		case SND_PCM_STATE_SUSPENDED:
+			return -ESTRPIPE;
+		default:
+			return -EIO;
+		}
+	}
 	return err > 0 ? 1 : 0;
 }
 
@@ -6110,15 +6120,8 @@
 			}
 
 			err = snd_pcm_wait(pcm, -1);
-			state = snd_pcm_state(pcm);
-			if (err < 0) {
-				/* check more precisely */
-				if (state == SND_PCM_STATE_XRUN)
-					err = -EPIPE;
-				else if (state == SND_PCM_STATE_SUSPENDED)
-					err = -ESTRPIPE;
+			if (err < 0)
 				break;
-			}
 			goto _again;
 			
 		}
@@ -6187,15 +6190,8 @@
 			}
 
 			err = snd_pcm_wait(pcm, -1);
-			state = snd_pcm_state(pcm);
-			if (err < 0) {
-				/* check more precisely */
-				if (state == SND_PCM_STATE_XRUN)
-					err = -EPIPE;
-				else if (state == SND_PCM_STATE_SUSPENDED)
-					err = -ESTRPIPE;
+			if (err < 0)
 				break;
-			}
 			goto _again;
 			
 		}

             reply	other threads:[~2003-07-14 14:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-14 14:24 Takashi Iwai [this message]
2003-07-14 14:39 ` return value of snd_pcm_wait() Jaroslav Kysela

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=s5hel0tuqxx.wl@alsa2.suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@lists.sourceforge.net \
    /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.