[Spice-devel] [PATCH spice-gtk 1/3] spice-channel: support SPICE_COMMON_CAP_HEADER_NO_SUB
Yonit Halperin
yhalperi at redhat.com
Wed Dec 28 09:15:42 PST 2011
---
gtk/spice-channel-priv.h | 3 +++
gtk/spice-channel.c | 27 +++++++++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 5585f13..cf5caba 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -123,6 +123,9 @@ struct _SpiceChannelPrivate {
GArray *remote_common_caps;
gsize total_read_bytes;
+
+ gboolean has_header_no_sub;
+ unsigned int header_size;
};
SpiceMsgIn *spice_msg_in_new(SpiceChannel *channel);
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index f4c398d..69a0571 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -106,6 +106,7 @@ static void spice_channel_init(SpiceChannel *channel)
c->remote_caps = g_array_new(FALSE, TRUE, sizeof(guint32));
c->remote_common_caps = g_array_new(FALSE, TRUE, sizeof(guint32));
spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION);
+ spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_HEADER_NO_SUB);
g_queue_init(&c->xmit_queue);
}
@@ -454,7 +455,7 @@ void spice_msg_in_hexdump(SpiceMsgIn *in)
fprintf(stderr, "--\n<< hdr: %s serial %" PRIu64 " type %d size %d sub-list %d\n",
c->name, in->header.serial, in->header.type,
- in->header.size, in->header.sub_list);
+ in->header.size, c->has_header_no_sub ? 0: in->header.sub_list);
hexdump("<< msg", in->data, in->dpos);
}
@@ -465,7 +466,7 @@ void spice_msg_out_hexdump(SpiceMsgOut *out, unsigned char *data, int len)
fprintf(stderr, "--\n>> hdr: %s serial %" PRIu64 " type %d size %d sub-list %d\n",
c->name, out->header->serial, out->header->type,
- out->header->size, out->header->sub_list);
+ out->header->size, c->has_header_no_sub ? 0 : out->header->sub_list);
hexdump(">> msg", data, len);
}
@@ -509,11 +510,13 @@ SpiceMsgOut *spice_msg_out_new(SpiceChannel *channel, int type)
out->marshallers = c->marshallers;
out->marshaller = spice_marshaller_new();
out->header = (SpiceDataHeader *)
- spice_marshaller_reserve_space(out->marshaller, sizeof(SpiceDataHeader));
- spice_marshaller_set_base(out->marshaller, sizeof(SpiceDataHeader));
+ spice_marshaller_reserve_space(out->marshaller, c->header_size);
+ spice_marshaller_set_base(out->marshaller, c->header_size);
out->header->serial = c->serial++;
out->header->type = type;
- out->header->sub_list = 0;
+ if (!c->has_header_no_sub) {
+ out->header->sub_list = 0;
+ }
return out;
}
@@ -701,7 +704,7 @@ static void spice_channel_write_msg(SpiceChannel *channel, SpiceMsgOut *out)
}
out->header->size =
- spice_marshaller_get_total_size(out->marshaller) - sizeof(SpiceDataHeader);
+ spice_marshaller_get_total_size(out->marshaller) - channel->priv->header_size;
data = spice_marshaller_linearize(out->marshaller, 0, &len, &free_data);
/* spice_msg_out_hexdump(out, data, len); */
spice_channel_write(channel, data, len);
@@ -1548,7 +1551,10 @@ static void spice_channel_recv_link_msg(SpiceChannel *channel)
goto error;
}
}
-
+ c->has_header_no_sub = spice_channel_test_common_capability(channel,
+ SPICE_COMMON_CAP_HEADER_NO_SUB);
+ c->header_size = c->has_header_no_sub ? sizeof(SpiceDataHeaderNoSub) :
+ sizeof(SpiceDataHeader);
return;
error:
@@ -1587,15 +1593,15 @@ void spice_channel_recv_msg(SpiceChannel *channel,
in = c->msg_in;
/* receive message */
- if (in->hpos < sizeof(in->header)) {
+ if (in->hpos < c->header_size) {
rc = spice_channel_read(channel, (uint8_t*)&in->header + in->hpos,
- sizeof(in->header) - in->hpos);
+ c->header_size - in->hpos);
if (rc < 0) {
g_critical("recv hdr: %s", strerror(errno));
return;
}
in->hpos += rc;
- if (in->hpos < sizeof(in->header))
+ if (in->hpos < c->header_size)
return;
in->data = spice_malloc(in->header.size);
}
@@ -2190,6 +2196,7 @@ static void channel_reset(SpiceChannel *channel, gboolean migrating)
g_array_set_size(c->caps, 0);
/* Restore our default capabilities in case the channel gets re-used */
spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION);
+ spice_channel_set_common_capability(channel, SPICE_COMMON_CAP_HEADER_NO_SUB);
}
/* system or coroutine context */
--
1.7.6.4
More information about the Spice-devel
mailing list