[Spice-commits] 3 commits - server/cursor-channel.c server/red-channel.c server/red-channel-client.c server/red-channel-client.h server/red-channel.h server/red-worker.c

Christophe Fergau teuf at kemper.freedesktop.org
Tue Sep 12 16:20:42 UTC 2017


 server/cursor-channel.c     |    6 +-----
 server/red-channel-client.c |    9 ---------
 server/red-channel-client.h |    1 -
 server/red-channel.c        |   24 ++++++++++++++----------
 server/red-channel.h        |   11 +++++------
 server/red-worker.c         |   12 ++----------
 6 files changed, 22 insertions(+), 41 deletions(-)

New commits:
commit 1e43272ba1903cb6c3365d45f90c6ae7fc4130cf
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Wed Aug 30 18:09:42 2017 +0200

    channel: Remove no longer used red_channel_apply_clients{_data,}
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/red-channel.c b/server/red-channel.c
index b8f4f54e..b4a92340 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -493,16 +493,6 @@ void red_channel_connect(RedChannel *channel, RedClient *client,
     channel->priv->client_cbs.connect(channel, client, stream, migration, caps);
 }
 
-void red_channel_apply_clients(RedChannel *channel, channel_client_callback cb)
-{
-    g_list_foreach(channel->priv->clients, (GFunc)cb, NULL);
-}
-
-void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback_data cb, void *data)
-{
-    g_list_foreach(channel->priv->clients, (GFunc)cb, data);
-}
-
 GList *red_channel_get_clients(RedChannel *channel)
 {
     return channel->priv->clients;
diff --git a/server/red-channel.h b/server/red-channel.h
index a55c830f..e0fe94fe 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -203,12 +203,6 @@ uint32_t red_channel_max_pipe_size(RedChannel *channel);
 /* return the max size of all the rcc pipe */
 uint32_t red_channel_sum_pipes_size(RedChannel *channel);
 
-/* apply given function to all connected clients */
-typedef void (*channel_client_callback)(RedChannelClient *rcc);
-typedef void (*channel_client_callback_data)(RedChannelClient *rcc, void *data);
-void red_channel_apply_clients(RedChannel *channel, channel_client_callback v);
-void red_channel_apply_clients_data(RedChannel *channel, channel_client_callback_data v,
-                                    void *data);
 GList *red_channel_get_clients(RedChannel *channel);
 guint red_channel_get_n_clients(RedChannel *channel);
 struct RedsState* red_channel_get_server(RedChannel *channel);
commit 1b7fca87b6facaa641411788cd1067bcf9631498
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Thu Aug 31 09:35:58 2017 +0200

    channel: Remove red_channel_client_disconnect_if_pending_send()
    
    There is exactly one user in RedChannel, and this can be reimplemented
    using already public RedChannelClient API. No need for an extra
    function very specialized function with a not great name.
    
    This commit thus removes one method from RedChannelClient public API,
    and replaces it with an equivalent private helper in RedChannel.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index 34202c49..8f730862 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1848,15 +1848,6 @@ bool red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
     }
 }
 
-void red_channel_client_disconnect_if_pending_send(RedChannelClient *rcc)
-{
-    if (red_channel_client_is_blocked(rcc) || !g_queue_is_empty(&rcc->priv->pipe)) {
-        red_channel_client_disconnect(rcc);
-    } else {
-        spice_assert(red_channel_client_no_item_being_sent(rcc));
-    }
-}
-
 gboolean red_channel_client_no_item_being_sent(RedChannelClient *rcc)
 {
     return !rcc || (rcc->priv->send_data.size == 0);
diff --git a/server/red-channel-client.h b/server/red-channel-client.h
index f5e04df7..732fbdd5 100644
--- a/server/red-channel-client.h
+++ b/server/red-channel-client.h
@@ -143,7 +143,6 @@ bool red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
                                             int64_t timeout);
 bool red_channel_client_wait_outgoing_item(RedChannelClient *rcc,
                                            int64_t timeout);
-void red_channel_client_disconnect_if_pending_send(RedChannelClient *rcc);
 
 RedChannel* red_channel_client_get_channel(RedChannelClient *rcc);
 
diff --git a/server/red-channel.c b/server/red-channel.c
index c24b9772..b8f4f54e 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -627,6 +627,19 @@ uint32_t red_channel_sum_pipes_size(RedChannel *channel)
     return sum;
 }
 
+static void red_channel_disconnect_if_pending_send(RedChannel *channel)
+{
+    RedChannelClient *rcc;
+
+    FOREACH_CLIENT(channel, rcc) {
+        if (red_channel_client_is_blocked(rcc) || !red_channel_client_pipe_is_empty(rcc)) {
+            red_channel_client_disconnect(rcc);
+        } else {
+            spice_assert(red_channel_client_no_item_being_sent(rcc));
+        }
+    }
+}
+
 bool red_channel_wait_all_sent(RedChannel *channel,
                                int64_t timeout)
 {
@@ -654,7 +667,7 @@ bool red_channel_wait_all_sent(RedChannel *channel,
     if (max_pipe_size || blocked) {
         spice_warning("timeout: pending out messages exist (pipe-size %u, blocked %d)",
                       max_pipe_size, blocked);
-        red_channel_apply_clients(channel, red_channel_client_disconnect_if_pending_send);
+        red_channel_disconnect_if_pending_send(channel);
         return FALSE;
     } else {
         spice_assert(red_channel_no_item_being_sent(channel));
commit 685a6288f3f5771a6ec61066a3497ca4bb53f307
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Wed Aug 30 18:09:23 2017 +0200

    channel: Call red_channel_disconnect_if_pending_send() from red_channel_wait_all_sent()
    
    red_channel_disconnect_if_pending_send() and red_channel_wait_all_sent() are
    always called together, we can remove one of the 2 methods.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index a844100a..7fab4c8c 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -305,11 +305,7 @@ void cursor_channel_reset(CursorChannel *cursor)
         if (!common_graphics_channel_get_during_target_migrate(COMMON_GRAPHICS_CHANNEL(cursor))) {
             red_channel_pipes_add_empty_msg(channel, SPICE_MSG_CURSOR_RESET);
         }
-        if (!red_channel_wait_all_sent(channel,
-                                       COMMON_CLIENT_TIMEOUT)) {
-            red_channel_apply_clients(channel,
-                                      red_channel_client_disconnect_if_pending_send);
-        }
+        red_channel_wait_all_sent(channel, COMMON_CLIENT_TIMEOUT);
     }
 }
 
diff --git a/server/red-channel.c b/server/red-channel.c
index 97be2f2b..c24b9772 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -654,6 +654,7 @@ bool red_channel_wait_all_sent(RedChannel *channel,
     if (max_pipe_size || blocked) {
         spice_warning("timeout: pending out messages exist (pipe-size %u, blocked %d)",
                       max_pipe_size, blocked);
+        red_channel_apply_clients(channel, red_channel_client_disconnect_if_pending_send);
         return FALSE;
     } else {
         spice_assert(red_channel_no_item_being_sent(channel));
diff --git a/server/red-channel.h b/server/red-channel.h
index b5510c30..a55c830f 100644
--- a/server/red-channel.h
+++ b/server/red-channel.h
@@ -226,6 +226,11 @@ const RedChannelCapabilities* red_channel_get_local_capabilities(RedChannel *sel
  *
  * timeout is in nano sec. -1 for no timeout.
  *
+ * This method tries for up to @timeout nanoseconds to send all the
+ * items which are currently queued. If the timeout elapses,
+ * the RedChannelClient which are too slow (those which still have pending
+ * items) will be disconnected.
+ *
  * Return: TRUE if waiting succeeded. FALSE if timeout expired.
  */
 
diff --git a/server/red-worker.c b/server/red-worker.c
index eb7d204a..a4cfdb45 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -613,16 +613,8 @@ static void handle_dev_stop(void *opaque, void *payload)
      * purge the pipe, send destroy_all_surfaces
      * to the client (there is no such message right now), and start
      * from scratch on the destination side */
-    if (!red_channel_wait_all_sent(RED_CHANNEL(worker->display_channel),
-                                   COMMON_CLIENT_TIMEOUT)) {
-        red_channel_apply_clients(RED_CHANNEL(worker->display_channel),
-                                 red_channel_client_disconnect_if_pending_send);
-    }
-    if (!red_channel_wait_all_sent(RED_CHANNEL(worker->cursor_channel),
-                                   COMMON_CLIENT_TIMEOUT)) {
-        red_channel_apply_clients(RED_CHANNEL(worker->cursor_channel),
-                                 red_channel_client_disconnect_if_pending_send);
-    }
+    red_channel_wait_all_sent(RED_CHANNEL(worker->display_channel), COMMON_CLIENT_TIMEOUT);
+    red_channel_wait_all_sent(RED_CHANNEL(worker->cursor_channel), COMMON_CLIENT_TIMEOUT);
 }
 
 static void handle_dev_start(void *opaque, void *payload)


More information about the Spice-commits mailing list