Reduce number of write to the channel. This will also help making the write to socket all asynchronous avoiding potential blockages. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- src/channel-webdav.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/channel-webdav.c b/src/channel-webdav.c index f5a38ad3..a4bc1cb2 100644 --- a/src/channel-webdav.c +++ b/src/channel-webdav.c @@ -179,6 +179,8 @@ static void output_queue_push(OutputQueue *q, const guint8 *buf, gsize size, q->idle_id = g_idle_add(output_queue_idle, q); } +#define MAX_MUX_SIZE G_MAXUINT16 + typedef struct Client { guint refs; @@ -187,11 +189,11 @@ typedef struct Client gint64 id; GCancellable *cancellable; - struct _mux { + struct { gint64 id; guint16 size; - guint8 *buf; - } mux; + guint8 buf[MAX_MUX_SIZE]; + } *mux; } Client; static void @@ -200,7 +202,7 @@ client_unref(Client *client) if (--client->refs > 0) return; - g_free(client->mux.buf); + g_free(client->mux); g_object_unref(client->pipe); g_object_unref(client->cancellable); @@ -231,7 +233,7 @@ static void mux_pushed_cb(OutputQueue *q, gpointer user_data) { Client *client = user_data; - if (client->mux.size == 0 || + if (client->mux->size == 0 || !client_start_read(client)) { remove_client(client); } @@ -239,8 +241,6 @@ static void mux_pushed_cb(OutputQueue *q, gpointer user_data) client_unref(client); } -#define MAX_MUX_SIZE G_MAXUINT16 - static void server_reply_cb(GObject *source_object, GAsyncResult *res, gpointer user_data) @@ -256,12 +256,10 @@ static void server_reply_cb(GObject *source_object, g_return_if_fail(size <= MAX_MUX_SIZE); g_return_if_fail(size >= 0); - client->mux.size = size; + client->mux->size = GUINT16_TO_LE(size); - output_queue_push(c->queue, (guint8 *)&client->mux.id, sizeof(gint64), NULL, NULL); - client->mux.size = GUINT16_TO_LE(client->mux.size); - output_queue_push(c->queue, (guint8 *)&client->mux.size, sizeof(guint16), NULL, NULL); - output_queue_push(c->queue, (guint8 *)client->mux.buf, size, (GFunc)mux_pushed_cb, client); + output_queue_push(c->queue, (guint8 *)client->mux, sizeof(gint64) + sizeof(guint16) + size, + (GFunc)mux_pushed_cb, client); return; @@ -284,7 +282,7 @@ static bool client_start_read(Client *client) if (g_input_stream_is_closed(input)) { return false; } - g_input_stream_read_async(input, client->mux.buf, MAX_MUX_SIZE, + g_input_stream_read_async(input, client->mux->buf, MAX_MUX_SIZE, G_PRIORITY_DEFAULT, client->cancellable, server_reply_cb, client_ref(client)); return true; @@ -368,8 +366,8 @@ static void start_client(SpiceWebdavChannel *self) client->refs = 1; client->id = c->demux.client; client->self = self; - client->mux.id = GINT64_TO_LE(client->id); - client->mux.buf = g_malloc0(MAX_MUX_SIZE); + client->mux = g_malloc0(sizeof(*client->mux)); + client->mux->id = GINT64_TO_LE(client->id); client->cancellable = g_cancellable_new(); spice_make_pipe(&client->pipe, &peer); -- 2.20.1 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel