struct compr_config *config;
int running;
int max_poll_wait_ms;
+ int nonblocking;
unsigned int gapless_metadata;
unsigned int next_track;
};
* or there is enough space for all remaining data
*/
if ((avail.avail < frag_size) && (avail.avail < size)) {
+
+ if (compress->nonblocking)
+ return total;
+
ret = poll(&fds, 1, compress->max_poll_wait_ms);
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop writing */
/* Less than one fragment available and not at the
* end of the read, so poll
*/
+ if (compress->nonblocking)
+ return total;
+
ret = poll(&fds, 1, compress->max_poll_wait_ms);
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop reading */
compress->max_poll_wait_ms = milliseconds;
}
+void compress_nonblock(struct compress *compress, int nonblock)
+{
+ compress->nonblocking = !!nonblock;
+}
+
+int compress_wait(struct compress *compress, int timeout_ms)
+{
+ struct pollfd fds;
+ int ret;
+
+ fds.fd = compress->fd;
+ fds.events = POLLOUT | POLLIN;
+
+ ret = poll(&fds, 1, timeout_ms);
+ /* A pause will cause -EBADFD or zero. */
+ if ((ret < 0) && (ret != -EBADFD))
+ return oops(compress, errno, "poll error");
+ if (fds.revents & (POLLOUT | POLLIN)) {
+ return 0;
+ }
+ if (fds.revents & POLLERR) {
+ return oops(compress, -EIO, "poll returned error!");
+ }
+ return ret;
+}
+
/*
* compress_write: write data to the compress stream
* return bytes written on success, negative on error
- * this is a blocking call
+ * By default this is a blocking call and will not return
+ * until all bytes have been written or there was a
+ * write error.
+ * If non-blocking mode has been enabled with compress_nonblock(),
+ * this function will write all bytes that can be written without
+ * blocking and will then return the number of bytes successfully
+ * written. If the return value is not an error and is < size
+ * the caller can use compress_wait() to block until the driver
+ * is ready for more data.
*
* @compress: compress stream to be written to
* @buf: pointer to data
/*
* compress_read: read data from the compress stream
* return bytes read on success, negative on error
+ * By default this is a blocking call and will block until
+ * size bytes have been written or there was a read error.
+ * If non-blocking mode was enabled using compress_nonblock()
+ * the behaviour will change to read only as many bytes as
+ * are currently available (if no bytes are available it
+ * will return immediately). The caller can then use
+ * compress_wait() to block until more bytes are available.
*
* @compress: compress stream from where data is to be read
* @buf: pointer to data buffer
*/
void compress_set_max_poll_wait(struct compress *compress, int milliseconds);
+/* Enable or disable non-blocking mode for write and read */
+void compress_nonblock(struct compress *compress, int nonblock);
+
+/* Wait for ring buffer to ready for next read or write */
+int compress_wait(struct compress *compress, int timeout_ms);
+
int is_compress_running(struct compress *compress);
int is_compress_ready(struct compress *compress);