]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/pstream.c
Use <pulsecore/socket.h> instead of <sys/socket.h>
[pulseaudio] / src / pulsecore / pstream.c
index e26ca473c4d4e0ec38798c11fe259139d2a404b1..369e22ca82eb1943c9ea3da50785dbfcb43478de 100644 (file)
@@ -28,9 +28,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
 #ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
 #endif
 #include <netinet/in.h>
 #endif
 
-
 #include <pulse/xmalloc.h>
 
-#include <pulsecore/winsock.h>
+#include <pulsecore/socket.h>
 #include <pulsecore/queue.h>
 #include <pulsecore/log.h>
 #include <pulsecore/core-scache.h>
@@ -283,7 +279,7 @@ pa_pstream *pa_pstream_new(pa_mainloop_api *m, pa_iochannel *io, pa_mempool *poo
     return p;
 }
 
-static void item_free(void *item, PA_GCC_UNUSED void *q) {
+static void item_free(void *item, void *q) {
     struct item_info *i = item;
     pa_assert(i);
 
@@ -488,7 +484,7 @@ static void prepare_next_write_item(pa_pstream *p) {
 
         pa_assert(p->write.current->packet);
         p->write.data = p->write.current->packet->data;
-        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->packet->length);
+        p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl((uint32_t) p->write.current->packet->length);
 
     } else if (p->write.current->type == PA_PSTREAM_ITEM_SHMRELEASE) {
 
@@ -511,7 +507,7 @@ static void prepare_next_write_item(pa_pstream *p) {
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI] = htonl((uint32_t) (((uint64_t) p->write.current->offset) >> 32));
         p->write.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_LO] = htonl((uint32_t) ((uint64_t) p->write.current->offset));
 
-        flags = p->write.current->seek_mode & PA_FLAG_SEEKMASK;
+        flags = (uint32_t) (p->write.current->seek_mode & PA_FLAG_SEEKMASK);
 
         if (p->use_shm) {
             uint32_t block_id, shm_id;
@@ -542,7 +538,7 @@ static void prepare_next_write_item(pa_pstream *p) {
         }
 
         if (send_payload) {
-            p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl(p->write.current->chunk.length);
+            p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH] = htonl((uint32_t) p->write.current->chunk.length);
             p->write.memchunk = p->write.current->chunk;
             pa_memblock_ref(p->write.memchunk.memblock);
             p->write.data = NULL;
@@ -607,7 +603,7 @@ static int do_write(pa_pstream *p) {
     if (release_memblock)
         pa_memblock_release(release_memblock);
 
-    p->write.index += r;
+    p->write.index += (size_t) r;
 
     if (p->write.index >= PA_PSTREAM_DESCRIPTOR_SIZE + ntohl(p->write.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH])) {
         pa_assert(p->write.current);
@@ -675,7 +671,7 @@ static int do_read(pa_pstream *p) {
     if (release_memblock)
         pa_memblock_release(release_memblock);
 
-    p->read.index += r;
+    p->read.index += (size_t) r;
 
     if (p->read.index == PA_PSTREAM_DESCRIPTOR_SIZE) {
         uint32_t flags, length, channel;
@@ -684,7 +680,7 @@ static int do_read(pa_pstream *p) {
         flags = ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_FLAGS]);
 
         if (!p->use_shm && (flags & PA_FLAG_SHMMASK) != 0) {
-            pa_log_warn("Recieved SHM frame on a socket where SHM is disabled.");
+            pa_log_warn("Received SHM frame on a socket where SHM is disabled.");
             return -1;
         }
 
@@ -714,7 +710,7 @@ static int do_read(pa_pstream *p) {
         length = ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_LENGTH]);
 
         if (length > FRAME_SIZE_MAX_ALLOW || length <= 0) {
-            pa_log_warn("Recieved invalid frame size: %lu", (unsigned long) length);
+            pa_log_warn("Received invalid frame size: %lu", (unsigned long) length);
             return -1;
         }
 
@@ -743,7 +739,7 @@ static int do_read(pa_pstream *p) {
             if ((flags & PA_FLAG_SHMMASK) == PA_FLAG_SHMDATA) {
 
                 if (length != sizeof(p->read.shm_info)) {
-                    pa_log_warn("Recieved SHM memblock frame with Invalid frame length.");
+                    pa_log_warn("Received SHM memblock frame with Invalid frame length.");
                     return -1;
                 }
 
@@ -758,7 +754,7 @@ static int do_read(pa_pstream *p) {
                 p->read.data = NULL;
             } else {
 
-                pa_log_warn("Recieved memblock frame with invalid flags value.");
+                pa_log_warn("Received memblock frame with invalid flags value.");
                 return -1;
             }
         }
@@ -769,7 +765,7 @@ static int do_read(pa_pstream *p) {
         if (p->read.memblock && p->recieve_memblock_callback) {
 
             /* Is this memblock data? Than pass it to the user */
-            l = (p->read.index - r) < PA_PSTREAM_DESCRIPTOR_SIZE ? p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE : (size_t) r;
+            l = (p->read.index - (size_t) r) < PA_PSTREAM_DESCRIPTOR_SIZE ? (size_t) (p->read.index - PA_PSTREAM_DESCRIPTOR_SIZE) : (size_t) r;
 
             if (l > 0) {
                 pa_memchunk chunk;
@@ -832,8 +828,8 @@ static int do_read(pa_pstream *p) {
                                           ntohl(p->read.shm_info[PA_PSTREAM_SHM_INDEX]),
                                           ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH])))) {
 
-                    pa_log_warn("Failed to import memory block.");
-                    return -1;
+                    if (pa_log_ratelimit(PA_LOG_DEBUG))
+                        pa_log_debug("Failed to import memory block.");
                 }
 
                 if (p->recieve_memblock_callback) {
@@ -842,7 +838,7 @@ static int do_read(pa_pstream *p) {
 
                     chunk.memblock = b;
                     chunk.index = 0;
-                    chunk.length = pa_memblock_get_length(b);
+                    chunk.length = b ? pa_memblock_get_length(b) : ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH]);
 
                     offset = (int64_t) (
                             (((uint64_t) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])) << 32) |
@@ -857,7 +853,8 @@ static int do_read(pa_pstream *p) {
                             p->recieve_memblock_callback_userdata);
                 }
 
-                pa_memblock_unref(b);
+                if (b)
+                    pa_memblock_unref(b);
             }
 
             goto frame_done;
@@ -942,7 +939,7 @@ pa_bool_t pa_pstream_is_pending(pa_pstream *p) {
     if (p->dead)
         b = FALSE;
     else
-        b = p->write.current || !pa_queue_is_empty(p->send_queue);
+        b = p->write.current || !pa_queue_isempty(p->send_queue);
 
     return b;
 }