[Spice-commits] 2 commits - server/mjpeg-encoder.c server/red-channel-client.c server/reds-stream.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Sep 11 20:06:09 UTC 2017


 server/mjpeg-encoder.c      |    6 +-----
 server/red-channel-client.c |    9 ++++++---
 server/reds-stream.h        |    4 ----
 3 files changed, 7 insertions(+), 12 deletions(-)

New commits:
commit b84d5d0124fcf1719007539ac49c1ce3b6c0cf75
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Sep 11 09:39:20 2017 +0100

    mjpeg: Reuse realloc instead of implementing it manually
    
    This potentially can also save the copy if there is enough
    space to resize the buffer in place.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
index 15f5e1f2..07ca69c2 100644
--- a/server/mjpeg-encoder.c
+++ b/server/mjpeg-encoder.c
@@ -278,15 +278,11 @@ static boolean empty_mem_output_buffer(j_compress_ptr cinfo)
 
   /* Try to allocate new buffer with double size */
   nextsize = dest->bufsize * 2;
-  nextbuffer = malloc(nextsize);
+  nextbuffer = realloc(dest->buffer, nextsize);
 
   if (nextbuffer == NULL)
     ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
 
-  memcpy(nextbuffer, dest->buffer, dest->bufsize);
-
-  free(dest->buffer);
-
   dest->pub.next_output_byte = nextbuffer + dest->bufsize;
   dest->pub.free_in_buffer = dest->bufsize;
 
commit d9bb9abb9e4c9dbbf8cdcdc7761e21fd75af15db
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Mon Sep 11 09:27:25 2017 +0100

    reds-stream: Remove shutdown field
    
    This field was used only by RedChannelClient to mark when the socket
    was shutdown. This condition can simply be tested by RedChannelClient
    checking if there's a watch as is the only condition (beside object
    destroying/disconnecting) where the watch is removed.
    In any case the shutdown was used to understand if there were possible
    data still to read.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 35bb8d92..9a47b7e6 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1014,12 +1014,11 @@ void red_channel_client_destroy(RedChannelClient *rcc)
 
 void red_channel_client_shutdown(RedChannelClient *rcc)
 {
-    if (rcc->priv->stream && !rcc->priv->stream->shutdown) {
+    if (rcc->priv->stream && rcc->priv->stream->watch) {
         SpiceCoreInterfaceInternal *core = red_channel_get_core_interface(rcc->priv->channel);
         core->watch_remove(core, rcc->priv->stream->watch);
         rcc->priv->stream->watch = NULL;
         shutdown(rcc->priv->stream->socket, SHUT_RDWR);
-        rcc->priv->stream->shutdown = TRUE;
     }
 }
 
@@ -1110,7 +1109,11 @@ static int red_peer_receive(RedsStream *stream, uint8_t *buf, uint32_t size)
     uint8_t *pos = buf;
     while (size) {
         int now;
-        if (stream->shutdown) {
+        /* if we don't have a watch it means socket has been shutdown
+         * shutdown read doesn't work as accepted - receive may return data afterward.
+         * check the flag before calling receive
+         */
+        if (!stream->watch) {
             return -1;
         }
         now = reds_stream_read(stream, pos, size);
diff --git a/server/reds-stream.h b/server/reds-stream.h
index 55a82745..10ec50b3 100644
--- a/server/reds-stream.h
+++ b/server/reds-stream.h
@@ -34,10 +34,6 @@ struct RedsStream {
     int socket;
     SpiceWatch *watch;
 
-    /* set it to TRUE if you shutdown the socket. shutdown read doesn't work as accepted -
-       receive may return data afterward. check the flag before calling receive*/
-    int shutdown;
-
     RedsStreamPrivate *priv;
 };
 


More information about the Spice-commits mailing list