[Spice-commits] 11 commits - server/char-device.c server/char-device.h server/red-channel-client.c

Christophe Fergau teuf at kemper.freedesktop.org
Fri Apr 28 15:09:17 UTC 2017


 server/char-device.c        |   89 +++++++++++++++++++++++++-------------------
 server/char-device.h        |    9 +---
 server/red-channel-client.c |   29 +++-----------
 3 files changed, 61 insertions(+), 66 deletions(-)

New commits:
commit df43483f71c2eb36bedde4a59f9ed6b2786deabe
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:21:03 2017 +0200

    Introduce WriteBufferOrigin enum typedef
    
    This use to be an anonymous enum, used as an int in
    RedCharDeviceWriteBufferPrivate::origin.
    Introducing a typedef clarifies what kind of value it's holding.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index b969d36e..ab0707fb 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -31,10 +31,17 @@
 #define RED_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT 30000
 #define MAX_POOL_SIZE (10 * 64 * 1024)
 
+typedef enum {
+    WRITE_BUFFER_ORIGIN_NONE,
+    WRITE_BUFFER_ORIGIN_CLIENT,
+    WRITE_BUFFER_ORIGIN_SERVER,
+    WRITE_BUFFER_ORIGIN_SERVER_NO_TOKEN,
+} WriteBufferOrigin;
+
 struct RedCharDeviceWriteBufferPrivate {
     RedClient *client; /* The client that sent the message to the device.
                           NULL if the server created the message */
-    int origin;
+    WriteBufferOrigin origin;
     uint32_t token_price;
     uint32_t refs;
 };
@@ -77,14 +84,6 @@ struct RedCharDevicePrivate {
     SpiceServer *reds;
 };
 
-enum {
-    WRITE_BUFFER_ORIGIN_NONE,
-    WRITE_BUFFER_ORIGIN_CLIENT,
-    WRITE_BUFFER_ORIGIN_SERVER,
-    WRITE_BUFFER_ORIGIN_SERVER_NO_TOKEN,
-};
-
-
 G_DEFINE_TYPE(RedCharDevice, red_char_device, G_TYPE_OBJECT)
 
 #define RED_CHAR_DEVICE_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RED_TYPE_CHAR_DEVICE, RedCharDevicePrivate))
@@ -535,7 +534,7 @@ static void red_char_device_write_retry(void *opaque)
 
 static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
     RedCharDevice *dev, RedClient *client,
-    int size, int origin, int migrated_data_tokens)
+    int size, WriteBufferOrigin origin, int migrated_data_tokens)
 {
     RedCharDeviceWriteBuffer *ret;
 
@@ -655,7 +654,7 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
     }
     *p_write_buf = NULL;
 
-    int buf_origin = write_buf->priv->origin;
+    WriteBufferOrigin buf_origin = write_buf->priv->origin;
     uint32_t buf_token_price = write_buf->priv->token_price;
     RedClient *client = write_buf->priv->client;
 
commit 113b7c8f5e509458f48ea8b9467caf89e97c58f2
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:15:46 2017 +0200

    Make RedCharDeviceWriteBuffer::refs private
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index 5ea7a567..b969d36e 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -36,6 +36,7 @@ struct RedCharDeviceWriteBufferPrivate {
                           NULL if the server created the message */
     int origin;
     uint32_t token_price;
+    uint32_t refs;
 };
 
 typedef struct RedCharDeviceClient RedCharDeviceClient;
@@ -164,7 +165,7 @@ static void write_buffers_queue_free(GQueue *write_queue)
 static void red_char_device_write_buffer_pool_add(RedCharDevice *dev,
                                                   RedCharDeviceWriteBuffer *buf)
 {
-    if (buf->refs == 1 &&
+    if (buf->priv->refs == 1 &&
         dev->priv->cur_pool_size < MAX_POOL_SIZE) {
         buf->buf_used = 0;
         buf->priv->origin = WRITE_BUFFER_ORIGIN_NONE;
@@ -588,7 +589,7 @@ static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
     }
 
     ret->priv->token_price = migrated_data_tokens ? migrated_data_tokens : 1;
-    ret->refs = 1;
+    ret->priv->refs = 1;
     return ret;
 error:
     dev->priv->cur_pool_size += ret->buf_size;
@@ -616,7 +617,7 @@ static RedCharDeviceWriteBuffer *red_char_device_write_buffer_ref(RedCharDeviceW
 {
     spice_assert(write_buf);
 
-    write_buf->refs++;
+    write_buf->priv->refs++;
     return write_buf;
 }
 
@@ -624,8 +625,8 @@ static void red_char_device_write_buffer_unref(RedCharDeviceWriteBuffer *write_b
 {
     spice_assert(write_buf);
 
-    write_buf->refs--;
-    if (write_buf->refs == 0)
+    write_buf->priv->refs--;
+    if (write_buf->priv->refs == 0)
         red_char_device_write_buffer_free(write_buf);
 }
 
diff --git a/server/char-device.h b/server/char-device.h
index 13e625fe..f66e2a15 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -151,7 +151,6 @@ typedef struct RedCharDeviceWriteBuffer {
     uint8_t *buf;
     uint32_t buf_size;
     uint32_t buf_used;
-    uint32_t refs;
 
     RedCharDeviceWriteBufferPrivate *priv;
 } RedCharDeviceWriteBuffer;
commit 76a06bdef84fad6b1540e94679fa43768193f7ab
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:14:42 2017 +0200

    Make RedCharDeviceWriteBuffer::token_price private
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index 0b2af0a6..5ea7a567 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -35,6 +35,7 @@ struct RedCharDeviceWriteBufferPrivate {
     RedClient *client; /* The client that sent the message to the device.
                           NULL if the server created the message */
     int origin;
+    uint32_t token_price;
 };
 
 typedef struct RedCharDeviceClient RedCharDeviceClient;
@@ -586,7 +587,7 @@ static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
         dev->priv->num_self_tokens--;
     }
 
-    ret->token_price = migrated_data_tokens ? migrated_data_tokens : 1;
+    ret->priv->token_price = migrated_data_tokens ? migrated_data_tokens : 1;
     ret->refs = 1;
     return ret;
 error:
@@ -654,7 +655,7 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
     *p_write_buf = NULL;
 
     int buf_origin = write_buf->priv->origin;
-    uint32_t buf_token_price = write_buf->token_price;
+    uint32_t buf_token_price = write_buf->priv->token_price;
     RedClient *client = write_buf->priv->client;
 
     if (!dev) {
@@ -912,7 +913,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
         *write_to_dev_size_ptr += buf_remaining;
         if (dev->priv->cur_write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
             spice_assert(dev->priv->cur_write_buf->priv->client == dev_client->client);
-            (*write_to_dev_tokens_ptr) += dev->priv->cur_write_buf->token_price;
+            (*write_to_dev_tokens_ptr) += dev->priv->cur_write_buf->priv->token_price;
         }
     }
 
@@ -926,7 +927,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
         *write_to_dev_size_ptr += write_buf->buf_used;
         if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
             spice_assert(write_buf->priv->client == dev_client->client);
-            (*write_to_dev_tokens_ptr) += write_buf->token_price;
+            (*write_to_dev_tokens_ptr) += write_buf->priv->token_price;
         }
     }
     spice_debug("migration data dev %p: write_queue size %u tokens %u",
diff --git a/server/char-device.h b/server/char-device.h
index 0dd493c4..13e625fe 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -151,7 +151,6 @@ typedef struct RedCharDeviceWriteBuffer {
     uint8_t *buf;
     uint32_t buf_size;
     uint32_t buf_used;
-    uint32_t token_price;
     uint32_t refs;
 
     RedCharDeviceWriteBufferPrivate *priv;
commit 8dc7505ae97e3568eed74e3d5e424b3272fc29c3
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:13:41 2017 +0200

    Make RedCharDeviceWriteBuffer::client private
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index cb680b83..0b2af0a6 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -32,6 +32,8 @@
 #define MAX_POOL_SIZE (10 * 64 * 1024)
 
 struct RedCharDeviceWriteBufferPrivate {
+    RedClient *client; /* The client that sent the message to the device.
+                          NULL if the server created the message */
     int origin;
 };
 
@@ -165,7 +167,7 @@ static void red_char_device_write_buffer_pool_add(RedCharDevice *dev,
         dev->priv->cur_pool_size < MAX_POOL_SIZE) {
         buf->buf_used = 0;
         buf->priv->origin = WRITE_BUFFER_ORIGIN_NONE;
-        buf->client = NULL;
+        buf->priv->client = NULL;
         dev->priv->cur_pool_size += buf->buf_size;
         g_queue_push_head(&dev->priv->write_bufs_pool, buf);
         return;
@@ -193,7 +195,7 @@ static void red_char_device_client_free(RedCharDevice *dev,
         next = l->next;
 
         if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
-            write_buf->client == dev_client->client) {
+            write_buf->priv->client == dev_client->client) {
             g_queue_delete_link(&dev->priv->write_queue, l);
             red_char_device_write_buffer_pool_add(dev, write_buf);
         }
@@ -201,9 +203,9 @@ static void red_char_device_client_free(RedCharDevice *dev,
     }
 
     if (dev->priv->cur_write_buf && dev->priv->cur_write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
-        dev->priv->cur_write_buf->client == dev_client->client) {
+        dev->priv->cur_write_buf->priv->client == dev_client->client) {
         dev->priv->cur_write_buf->priv->origin = WRITE_BUFFER_ORIGIN_NONE;
-        dev->priv->cur_write_buf->client = NULL;
+        dev->priv->cur_write_buf->priv->client = NULL;
     }
 
     dev->priv->clients = g_list_remove(dev->priv->clients, dev_client);
@@ -570,7 +572,7 @@ static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
                 red_char_device_handle_client_overflow(dev_client);
                 goto error;
             }
-            ret->client = client;
+            ret->priv->client = client;
             if (!migrated_data_tokens && dev_client->do_flow_control) {
                 dev_client->num_client_tokens--;
             }
@@ -632,8 +634,8 @@ void red_char_device_write_buffer_add(RedCharDevice *dev,
     spice_assert(dev);
     /* caller shouldn't add buffers for client that was removed */
     if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
-        !red_char_device_client_find(dev, write_buf->client)) {
-        spice_printerr("client not found: dev %p client %p", dev, write_buf->client);
+        !red_char_device_client_find(dev, write_buf->priv->client)) {
+        spice_printerr("client not found: dev %p client %p", dev, write_buf->priv->client);
         red_char_device_write_buffer_pool_add(dev, write_buf);
         return;
     }
@@ -653,7 +655,7 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
 
     int buf_origin = write_buf->priv->origin;
     uint32_t buf_token_price = write_buf->token_price;
-    RedClient *client = write_buf->client;
+    RedClient *client = write_buf->priv->client;
 
     if (!dev) {
         spice_printerr("no device. write buffer is freed");
@@ -909,7 +911,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
                                          );
         *write_to_dev_size_ptr += buf_remaining;
         if (dev->priv->cur_write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
-            spice_assert(dev->priv->cur_write_buf->client == dev_client->client);
+            spice_assert(dev->priv->cur_write_buf->priv->client == dev_client->client);
             (*write_to_dev_tokens_ptr) += dev->priv->cur_write_buf->token_price;
         }
     }
@@ -923,7 +925,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
                                          );
         *write_to_dev_size_ptr += write_buf->buf_used;
         if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
-            spice_assert(write_buf->client == dev_client->client);
+            spice_assert(write_buf->priv->client == dev_client->client);
             (*write_to_dev_tokens_ptr) += write_buf->token_price;
         }
     }
diff --git a/server/char-device.h b/server/char-device.h
index df15cfdf..0dd493c4 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -148,9 +148,6 @@ GType red_char_device_get_type(void) G_GNUC_CONST;
 /* buffer that is used for writing to the device */
 typedef struct RedCharDeviceWriteBufferPrivate RedCharDeviceWriteBufferPrivate;
 typedef struct RedCharDeviceWriteBuffer {
-    RedClient *client; /* The client that sent the message to the device.
-                          NULL if the server created the message */
-
     uint8_t *buf;
     uint32_t buf_size;
     uint32_t buf_used;
commit 3fe4c661ef517c3111e3bc3d38b533b0ba6006a2
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:09:58 2017 +0200

    Make RedCharDeviceWriteBuffer::origin private
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index 16687d83..cb680b83 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -32,6 +32,7 @@
 #define MAX_POOL_SIZE (10 * 64 * 1024)
 
 struct RedCharDeviceWriteBufferPrivate {
+    int origin;
 };
 
 typedef struct RedCharDeviceClient RedCharDeviceClient;
@@ -163,7 +164,7 @@ static void red_char_device_write_buffer_pool_add(RedCharDevice *dev,
     if (buf->refs == 1 &&
         dev->priv->cur_pool_size < MAX_POOL_SIZE) {
         buf->buf_used = 0;
-        buf->origin = WRITE_BUFFER_ORIGIN_NONE;
+        buf->priv->origin = WRITE_BUFFER_ORIGIN_NONE;
         buf->client = NULL;
         dev->priv->cur_pool_size += buf->buf_size;
         g_queue_push_head(&dev->priv->write_bufs_pool, buf);
@@ -191,7 +192,7 @@ static void red_char_device_client_free(RedCharDevice *dev,
         RedCharDeviceWriteBuffer *write_buf = l->data;
         next = l->next;
 
-        if (write_buf->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
+        if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
             write_buf->client == dev_client->client) {
             g_queue_delete_link(&dev->priv->write_queue, l);
             red_char_device_write_buffer_pool_add(dev, write_buf);
@@ -199,9 +200,9 @@ static void red_char_device_client_free(RedCharDevice *dev,
         l = next;
     }
 
-    if (dev->priv->cur_write_buf && dev->priv->cur_write_buf->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
+    if (dev->priv->cur_write_buf && dev->priv->cur_write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
         dev->priv->cur_write_buf->client == dev_client->client) {
-        dev->priv->cur_write_buf->origin = WRITE_BUFFER_ORIGIN_NONE;
+        dev->priv->cur_write_buf->priv->origin = WRITE_BUFFER_ORIGIN_NONE;
         dev->priv->cur_write_buf->client = NULL;
     }
 
@@ -557,7 +558,7 @@ static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
         ret->buf = spice_realloc(ret->buf, size);
         ret->buf_size = size;
     }
-    ret->origin = origin;
+    ret->priv->origin = origin;
 
     if (origin == WRITE_BUFFER_ORIGIN_CLIENT) {
        spice_assert(client);
@@ -630,7 +631,7 @@ void red_char_device_write_buffer_add(RedCharDevice *dev,
 {
     spice_assert(dev);
     /* caller shouldn't add buffers for client that was removed */
-    if (write_buf->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
+    if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT &&
         !red_char_device_client_find(dev, write_buf->client)) {
         spice_printerr("client not found: dev %p client %p", dev, write_buf->client);
         red_char_device_write_buffer_pool_add(dev, write_buf);
@@ -650,7 +651,7 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
     }
     *p_write_buf = NULL;
 
-    int buf_origin = write_buf->origin;
+    int buf_origin = write_buf->priv->origin;
     uint32_t buf_token_price = write_buf->token_price;
     RedClient *client = write_buf->client;
 
@@ -907,7 +908,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
                                          red_char_device_write_buffer_ref(dev->priv->cur_write_buf)
                                          );
         *write_to_dev_size_ptr += buf_remaining;
-        if (dev->priv->cur_write_buf->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
+        if (dev->priv->cur_write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
             spice_assert(dev->priv->cur_write_buf->client == dev_client->client);
             (*write_to_dev_tokens_ptr) += dev->priv->cur_write_buf->token_price;
         }
@@ -921,7 +922,7 @@ void red_char_device_migrate_data_marshall(RedCharDevice *dev,
                                          red_char_device_write_buffer_ref(write_buf)
                                          );
         *write_to_dev_size_ptr += write_buf->buf_used;
-        if (write_buf->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
+        if (write_buf->priv->origin == WRITE_BUFFER_ORIGIN_CLIENT) {
             spice_assert(write_buf->client == dev_client->client);
             (*write_to_dev_tokens_ptr) += write_buf->token_price;
         }
diff --git a/server/char-device.h b/server/char-device.h
index 9bfd7c65..df15cfdf 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -148,7 +148,6 @@ GType red_char_device_get_type(void) G_GNUC_CONST;
 /* buffer that is used for writing to the device */
 typedef struct RedCharDeviceWriteBufferPrivate RedCharDeviceWriteBufferPrivate;
 typedef struct RedCharDeviceWriteBuffer {
-    int origin;
     RedClient *client; /* The client that sent the message to the device.
                           NULL if the server created the message */
 
commit 968f3ab3e8dfa5dbbedd93bee969efea63009bd5
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Mon Apr 10 11:06:44 2017 +0200

    Add RedCharDeviceWriteBufferPrivate
    
    This is intended to hold the fields that only char-device.c has a use
    for, but for now this only adds the boilerplate for it, the next commit
    will move the relevant field there.
    
    Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/char-device.c b/server/char-device.c
index d3259320..16687d83 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -31,6 +31,9 @@
 #define RED_CHAR_DEVICE_WAIT_TOKENS_TIMEOUT 30000
 #define MAX_POOL_SIZE (10 * 64 * 1024)
 
+struct RedCharDeviceWriteBufferPrivate {
+};
+
 typedef struct RedCharDeviceClient RedCharDeviceClient;
 struct RedCharDeviceClient {
     RedCharDevice *dev;
@@ -539,7 +542,13 @@ static RedCharDeviceWriteBuffer *__red_char_device_write_buffer_get(
     if (ret) {
         dev->priv->cur_pool_size -= ret->buf_size;
     } else {
-        ret = spice_new0(RedCharDeviceWriteBuffer, 1);
+        struct RedCharDeviceWriteBufferFull {
+            RedCharDeviceWriteBuffer buffer;
+            RedCharDeviceWriteBufferPrivate priv;
+        } *write_buf;
+        write_buf = spice_new0(struct RedCharDeviceWriteBufferFull, 1);
+        ret = &write_buf->buffer;
+        ret->priv = &write_buf->priv;
     }
 
     spice_assert(!ret->buf_used);
diff --git a/server/char-device.h b/server/char-device.h
index 7854086c..9bfd7c65 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -146,6 +146,7 @@ GType red_char_device_get_type(void) G_GNUC_CONST;
  * */
 
 /* buffer that is used for writing to the device */
+typedef struct RedCharDeviceWriteBufferPrivate RedCharDeviceWriteBufferPrivate;
 typedef struct RedCharDeviceWriteBuffer {
     int origin;
     RedClient *client; /* The client that sent the message to the device.
@@ -156,6 +157,8 @@ typedef struct RedCharDeviceWriteBuffer {
     uint32_t buf_used;
     uint32_t token_price;
     uint32_t refs;
+
+    RedCharDeviceWriteBufferPrivate *priv;
 } RedCharDeviceWriteBuffer;
 
 void red_char_device_reset_dev_instance(RedCharDevice *dev,
commit ecdef4930b7014dc67379b82248f04e38291fadd
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Apr 7 18:19:01 2017 +0200

    Remove redundant code from red_channel_client_msg_sent()
    
    red_channel_client_clear_sent_item() will clear send_data.blocked, so no
    need to do it in red_channel_client_msg_sent() as well.
    
    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 379684f5..7224c37e 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -634,9 +634,6 @@ static void red_channel_client_msg_sent(RedChannelClient *rcc)
     }
 
     red_channel_client_clear_sent_item(rcc);
-    if (red_channel_client_is_blocked(rcc)) {
-        rcc->priv->send_data.blocked = FALSE;
-    }
 
     if (red_channel_client_urgent_marshaller_is_active(rcc)) {
         red_channel_client_restore_main_sender(rcc);
commit 2a3b6c2c00db9aee51478ffa302acd66f5ede47b
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Apr 28 13:20:30 2017 +0200

    Use red_channel_client_set_blocked() helper
    
    Now that red_channel_client_set_blocked() is no longer changing the
    events we are watching for, we can call it from
    red_channel_client_push().
    
    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 b8ce6ef2..379684f5 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -1289,7 +1289,7 @@ void red_channel_client_push(RedChannelClient *rcc)
     }
 
     if (!red_channel_client_no_item_being_sent(rcc) && !red_channel_client_is_blocked(rcc)) {
-        rcc->priv->send_data.blocked = TRUE;
+        red_channel_client_set_blocked(rcc);
         spice_printerr("ERROR: an item waiting to be sent and not blocked");
     }
 
commit 2eb491cb6b72e17cdd1e92a67124307801f1712f
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Apr 28 12:59:35 2017 +0200

    Don't modify watch when network queue is full
    
    Since 5c460d, we need to watch for WATCH_EVENT_WRITE as long as there are
    items queued waiting to be sent, this does not need to be done only when
    the network queue is full.
    
    When red_channel_client_set_blocked() is called, as a message is being
    sent, WATCH_EVENT_WRITE will already be set, so it does not need to set
    it again.
    red_channel_client_msg_sent() removes WATCH_EVENT_WRITE, but this will
    be done later anyway by red_channel_client_push() if needed.
    
    Since it's redundant, we can remove this.
    
    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 02dabdc4..b8ce6ef2 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -495,13 +495,7 @@ static int red_channel_client_prepare_out_msg(RedChannelClient *rcc,
 
 static void red_channel_client_set_blocked(RedChannelClient *rcc)
 {
-    SpiceCoreInterfaceInternal *core;
-
     rcc->priv->send_data.blocked = TRUE;
-    core = red_channel_get_core_interface(rcc->priv->channel);
-    core->watch_update_mask(core, rcc->priv->stream->watch,
-                            SPICE_WATCH_EVENT_READ |
-                            SPICE_WATCH_EVENT_WRITE);
 }
 
 static inline int red_channel_client_urgent_marshaller_is_active(RedChannelClient *rcc)
@@ -641,10 +635,7 @@ static void red_channel_client_msg_sent(RedChannelClient *rcc)
 
     red_channel_client_clear_sent_item(rcc);
     if (red_channel_client_is_blocked(rcc)) {
-        SpiceCoreInterfaceInternal *core = red_channel_get_core_interface(rcc->priv->channel);
         rcc->priv->send_data.blocked = FALSE;
-        core->watch_update_mask(core, rcc->priv->stream->watch,
-                                SPICE_WATCH_EVENT_READ);
     }
 
     if (red_channel_client_urgent_marshaller_is_active(rcc)) {
commit 68a4eaedf1b6489bf37b903600d70735fe8deb9f
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Apr 7 18:24:03 2017 +0200

    Remove unneeded red_channel_client_is_blocked() call
    
    red_channel_client_msg_sent() calls red_channel_client_clear_sent_item()
    which will clear the rcc->priv->send_data.blocked flag. Later on, it
    contains a check for !red_channel_client_is_blocked(), which will always
    be true as nothing in between could have set it again. This commit
    removes this unneeded check.
    
    This check was already redundant when it was introduced in
    9a62a9a809eaf0
    
    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 f92f2e56..02dabdc4 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -652,8 +652,7 @@ static void red_channel_client_msg_sent(RedChannelClient *rcc)
         spice_assert(rcc->priv->send_data.header.data != NULL);
         red_channel_client_begin_send_message(rcc);
     } else {
-        if (!red_channel_client_is_blocked(rcc)
-            && g_queue_is_empty(&rcc->priv->pipe)) {
+        if (g_queue_is_empty(&rcc->priv->pipe)) {
             /* It is possible that the socket will become idle, so we may be able to test latency */
             red_channel_client_restart_ping_timer(rcc);
         }
commit bf7bb4e88616df921fc7e12df2ee61ac6ac0dd37
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Fri Apr 7 17:34:12 2017 +0200

    Remove unneeded rcc->priv->latency_monitor.timer checks
    
    Before this commit, red_channel_client_start_ping_timer() and
    red_channel_client_cancel_ping_timer() had checks to be no-ops when
    rcc->priv->latency_monitor.timer is NULL.
    
    This commit adds a similar check to
    red_channel_client_restart_ping_timer(), and removes explicit NULL
    checks before calls to red_channel_client_{cancel,restart,start}_ping_timer()
    
    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 2dc0b8f6..f92f2e56 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -257,6 +257,9 @@ static void red_channel_client_restart_ping_timer(RedChannelClient *rcc)
 {
     uint64_t passed, timeout;
 
+    if (!rcc->priv->latency_monitor.timer) {
+        return;
+    }
     passed = (spice_get_monotonic_time_ns() - rcc->priv->latency_monitor.last_pong_time) / NSEC_PER_MILLISEC;
     timeout = PING_TEST_IDLE_NET_TIMEOUT_MS;
     if (passed  < PING_TEST_TIMEOUT_MS) {
@@ -649,8 +652,7 @@ static void red_channel_client_msg_sent(RedChannelClient *rcc)
         spice_assert(rcc->priv->send_data.header.data != NULL);
         red_channel_client_begin_send_message(rcc);
     } else {
-        if (rcc->priv->latency_monitor.timer
-            && !red_channel_client_is_blocked(rcc)
+        if (!red_channel_client_is_blocked(rcc)
             && g_queue_is_empty(&rcc->priv->pipe)) {
             /* It is possible that the socket will become idle, so we may be able to test latency */
             red_channel_client_restart_ping_timer(rcc);
@@ -969,9 +971,7 @@ static void red_channel_client_seamless_migration_done(RedChannelClient *rcc)
     rcc->priv->wait_migrate_data = FALSE;
 
     if (red_client_seamless_migration_done_for_channel(rcc->priv->client)) {
-        if (rcc->priv->latency_monitor.timer) {
-            red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
-        }
+        red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
         if (rcc->priv->connectivity_monitor.timer) {
             SpiceCoreInterfaceInternal *core = red_channel_get_core_interface(rcc->priv->channel);
             core->timer_start(core, rcc->priv->connectivity_monitor.timer,
@@ -982,9 +982,7 @@ static void red_channel_client_seamless_migration_done(RedChannelClient *rcc)
 
 void red_channel_client_semi_seamless_migration_complete(RedChannelClient *rcc)
 {
-    if (rcc->priv->latency_monitor.timer) {
-        red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
-    }
+    red_channel_client_start_ping_timer(rcc, PING_TEST_IDLE_NET_TIMEOUT_MS);
 }
 
 bool red_channel_client_is_waiting_for_migrate_data(RedChannelClient *rcc)


More information about the Spice-commits mailing list