]> git.alsa-project.org Git - tinycompress.git/commitdiff
compress: Handle case of pause() during compress_write()
authorRichard Fitzgerald <rf@opensource.wolfsonmicro.com>
Fri, 22 Feb 2013 16:04:22 +0000 (16:04 +0000)
committerVinod Koul <vinod.koul@intel.com>
Fri, 22 Feb 2013 18:08:12 +0000 (23:38 +0530)
If stream is paused() during a compress_write() the poll()
will return 0 or -EBADFD, or the write() will return -EBADFD.
This is not an error so compress_write() should not pass an
error code to the caller. It should abort the write and then
return the number of bytes it had written up to that point.

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress.c

index 478652af064a81e07b1727a78ed95527e3bc2a0b..92d1a80a62d0ffec506aa0cff50e0e5beaf805a3 100644 (file)
@@ -340,10 +340,13 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                if (avail.avail < compress->config.fragment_size) {
                        /* nothing to write so wait */
                        ret = poll(&fds, 1, compress->max_poll_wait_ms);
+                       /* A pause will cause -EBADFD or zero return from driver
+                        * This is not an error, just stop writing
+                        */
+                       if ((ret == 0) || (ret == -EBADFD))
+                               break;
                        if (ret < 0)
                                return oops(compress, errno, "poll error");
-                       if (ret == 0)
-                               return oops(compress, -EPIPE, "Poll timeout, Broken Pipe");
                        if (fds.revents & POLLOUT) {
                                if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
                                        return oops(compress, errno, "cannot get avail");
@@ -362,6 +365,9 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
                else
                        to_write = size;
                written = write(compress->fd, cbuf, to_write);
+               /* If play was paused the write returns -EBADFD */
+               if (written == -EBADFD)
+                       break;
                if (written < 0)
                        return oops(compress, errno, "write failed!");