From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: return value of snd_pcm_wait() Date: Mon, 14 Jul 2003 16:24:26 +0200 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: Mime-Version: 1.0 (generated by SEMI 1.14.4 - "Hosorogi") Content-Type: multipart/mixed; boundary="Multipart_Mon_Jul_14_16:24:26_2003-1" Return-path: Errors-To: alsa-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: To: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Mon_Jul_14_16:24:26_2003-1 Content-Type: text/plain; charset=US-ASCII 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 --Multipart_Mon_Jul_14_16:24:26_2003-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="pcm-wait-fix.dif" Content-Transfer-Encoding: 7bit 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; } --Multipart_Mon_Jul_14_16:24:26_2003-1-- ------------------------------------------------------- This SF.Net email sponsored by: Parasoft Error proof Web apps, automate testing & more. Download & eval WebKing and get a free book. www.parasoft.com/bulletproofapps1