[Spice-commits] 3 commits - server/reds-private.h server/reds.c

Christophe Fergau teuf at kemper.freedesktop.org
Thu Jun 15 16:26:56 UTC 2017


 server/reds-private.h |   13 ++++---------
 server/reds.c         |   31 +++++++++----------------------
 2 files changed, 13 insertions(+), 31 deletions(-)

New commits:
commit 429958f7d4189497caeb19fb253060323694a6f6
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Jun 15 12:00:36 2017 +0200

    reds: Free client_monitors_config in spice_server_destroy()
    
    This was not done until now, and it's only going to be needed if we receive
    a partial ClientMonitorsConfig message.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds.c b/server/reds.c
index a5f4b377..a569a6ef 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3706,7 +3706,7 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
        reds_core_watch_remove(reds, reds->secure_listen_watch);
        close(reds->secure_listen_socket);
     }
-
+    spice_buffer_free(&reds->client_monitors_config);
     red_record_unref(reds->record);
     reds_cleanup(reds);
 #ifdef RED_STATISTICS
commit edf90ba1241565de956e95fc2576bf80b0f7ce8f
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Jun 15 11:55:00 2017 +0200

    reds: Remove redundant __func in debug log
    
    The function name is always prepended by the spice_log macro, so we
    don't need to explicitly add it in debug messages.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds.c b/server/reds.c
index cb1fa294..a5f4b377 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1117,7 +1117,7 @@ static void reds_on_main_agent_monitors_config(RedsState *reds,
         return;
     }
     monitors_config = (VDAgentMonitorsConfig *)(cmc->buffer + sizeof(*msg_header));
-    spice_debug("%s: %d", __func__, monitors_config->num_of_monitors);
+    spice_debug("monitors_config->num_of_monitors: %d", monitors_config->num_of_monitors);
     reds_client_monitors_config(reds, monitors_config);
     spice_buffer_free(cmc);
 }
commit 2b08ba3d516bfea37dad0ec88e1923e5a7a721f2
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue May 30 16:37:35 2017 +0200

    reds: Replace RedsClientMonitorsConfig with SpiceBuffer
    
    RedsClientMonitorsConfig duplicates what SpiceBuffer does,
    so using we can replace it with SpiceBuffer and make
    reds_on_main_agent_monitors_config() simpler.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds-private.h b/server/reds-private.h
index 915bcf6f..26b7435a 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -59,14 +59,6 @@ typedef struct RedsMigTargetClient {
     GList *pending_links;
 } RedsMigTargetClient;
 
-/* Intermediate state for on going monitors config message from a single
- * client, being passed to the guest */
-typedef struct RedsClientMonitorsConfig {
-    uint8_t *buffer;
-    int buffer_size;
-    int buffer_pos;
-} RedsClientMonitorsConfig;
-
 typedef struct ChannelSecurityOptions ChannelSecurityOptions;
 
 typedef struct RedSSLParameters {
@@ -126,7 +118,10 @@ struct RedsState {
 #endif
     int allow_multiple_clients;
 
-    RedsClientMonitorsConfig client_monitors_config;
+    /* Intermediate state for on going monitors config message from a single
+     * client, being passed to the guest */
+    SpiceBuffer client_monitors_config;
+
     int mm_time_enabled;
     uint32_t mm_time_latency;
 
diff --git a/server/reds.c b/server/reds.c
index ad41a75b..cb1fa294 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1102,37 +1102,24 @@ void reds_release_agent_data_buffer(RedsState *reds, uint8_t *buf)
     dev->priv->recv_from_client_buf_pushed = FALSE;
 }
 
-static void reds_client_monitors_config_cleanup(RedsState *reds)
-{
-    RedsClientMonitorsConfig *cmc = &reds->client_monitors_config;
-
-    cmc->buffer_size = cmc->buffer_pos = 0;
-    free(cmc->buffer);
-    cmc->buffer = NULL;
-}
-
 static void reds_on_main_agent_monitors_config(RedsState *reds,
         MainChannelClient *mcc, const void *message, size_t size)
 {
     VDAgentMessage *msg_header;
     VDAgentMonitorsConfig *monitors_config;
-    RedsClientMonitorsConfig *cmc = &reds->client_monitors_config;
+    SpiceBuffer *cmc = &reds->client_monitors_config;
 
-    cmc->buffer_size += size;
-    cmc->buffer = realloc(cmc->buffer, cmc->buffer_size);
-    spice_assert(cmc->buffer);
-    memcpy(cmc->buffer + cmc->buffer_pos, message, size);
-    cmc->buffer_pos += size;
+    spice_buffer_append(cmc, message, size);
     msg_header = (VDAgentMessage *)cmc->buffer;
-    if (sizeof(VDAgentMessage) > cmc->buffer_size ||
-            msg_header->size > cmc->buffer_size - sizeof(VDAgentMessage)) {
-        spice_debug("not enough data yet. %d", cmc->buffer_size);
+    if (sizeof(VDAgentMessage) > cmc->offset ||
+            msg_header->size > cmc->offset - sizeof(VDAgentMessage)) {
+        spice_debug("not enough data yet. %zd", cmc->offset);
         return;
     }
     monitors_config = (VDAgentMonitorsConfig *)(cmc->buffer + sizeof(*msg_header));
     spice_debug("%s: %d", __func__, monitors_config->num_of_monitors);
     reds_client_monitors_config(reds, monitors_config);
-    reds_client_monitors_config_cleanup(reds);
+    spice_buffer_free(cmc);
 }
 
 void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, const void *message,
@@ -3438,7 +3425,7 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
 
     reds->mouse_mode = SPICE_MOUSE_MODE_SERVER;
 
-    reds_client_monitors_config_cleanup(reds);
+    spice_buffer_free(&reds->client_monitors_config);
 
     reds->allow_multiple_clients = getenv(SPICE_DEBUG_ALLOW_MC_ENV) != NULL;
     if (reds->allow_multiple_clients) {


More information about the Spice-commits mailing list