[PATCH 2/2] pstream: Optimise read of smaller packages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



During a stream, most packets sent are either memblocks (with SHM info),
or requests for more data. These are only slightly bigger than the
header.

This patch makes it possible to read these packages in one call to do_read,
thus saving us an extra poll syscall.

Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/pulsecore/pstream.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c
index d92178f..c6f1302 100644
--- a/src/pulsecore/pstream.c
+++ b/src/pulsecore/pstream.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
@@ -652,6 +653,7 @@ static int do_read(pa_pstream *p) {
     pa_assert(p);
     pa_assert(PA_REFCNT_VALUE(p) > 0);
 
+again:
     if (p->read.index < PA_PSTREAM_DESCRIPTOR_SIZE) {
         d = (uint8_t*) p->read.descriptor + p->read.index;
         l = PA_PSTREAM_DESCRIPTOR_SIZE - p->read.index;
@@ -774,6 +776,10 @@ static int do_read(pa_pstream *p) {
             }
         }
 
+        /* Optimisation: See if we can read the payload too */
+        if ((p->read.data || p->read.memblock) && (r == PA_PSTREAM_DESCRIPTOR_SIZE))
+            goto again;
+
     } else if (p->read.index > PA_PSTREAM_DESCRIPTOR_SIZE) {
         /* Frame payload available */
 
@@ -894,6 +900,8 @@ fail:
     if (release_memblock)
         pa_memblock_release(release_memblock);
 
+    if (r == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))
+        return 0; /* Let's just try again later, when socket is readable. */
     return -1;
 }
 
-- 
1.7.9.5



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux