From 1049e3f5983b8fb502fd2228b10f2bf3b6fb00fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 11 Feb 2011 04:00:27 +0100 Subject: [PATCH] server: simplify and constify sync_write() + symplify, improving style of code using it. https://bugs.freedesktop.org/show_bug.cgi?id=34795 --- server/reds.c | 31 +++++++++++++++---------------- 1 files changed, 15 insertions(+), 16 deletions(-) diff --git a/server/reds.c b/server/reds.c index eb1ea44..1e7e318 100644 --- a/server/reds.c +++ b/server/reds.c @@ -1321,9 +1321,9 @@ void reds_on_main_receive_migrate_data(MainMigrateData *data, uint8_t *end) while (write_to_vdi_port() || read_from_vdi_port()); } -static int sync_write(RedsStream *stream, void *in_buf, size_t n) +static int sync_write(RedsStream *stream, const void *in_buf, size_t n) { - uint8_t *buf = (uint8_t *)in_buf; + const uint8_t *buf = (uint8_t *)in_buf; while (n) { int now = reds_stream_write(stream, buf, n); if (now <= 0) { @@ -1342,6 +1342,7 @@ static int reds_send_link_ack(RedLinkInfo *link) { SpiceLinkHeader header; SpiceLinkReply ack; + Channel caps = { 0, }; Channel *channel; BUF_MEM *bmBuf; BIO *bio; @@ -1354,14 +1355,14 @@ static int reds_send_link_ack(RedLinkInfo *link) ack.error = SPICE_LINK_ERR_OK; - if ((channel = reds_find_channel(link->link_mess->channel_type, 0))) { - ack.num_common_caps = channel->num_common_caps; - ack.num_channel_caps = channel->num_caps; - header.size += (ack.num_common_caps + ack.num_channel_caps) * sizeof(uint32_t); - } else { - ack.num_common_caps = 0; - ack.num_channel_caps = 0; + channel = reds_find_channel(link->link_mess->channel_type, 0); + if (!channel) { + channel = ∩︀ } + + ack.num_common_caps = channel->num_common_caps; + ack.num_channel_caps = channel->num_caps; + header.size += (ack.num_common_caps + ack.num_channel_caps) * sizeof(uint32_t); ack.caps_offset = sizeof(SpiceLinkReply); if (!(link->tiTicketing.rsa = RSA_new())) { @@ -1382,13 +1383,11 @@ static int reds_send_link_ack(RedLinkInfo *link) BIO_get_mem_ptr(bio, &bmBuf); memcpy(ack.pub_key, bmBuf->data, sizeof(ack.pub_key)); - ret = sync_write(link->stream, &header, sizeof(header)) && sync_write(link->stream, &ack, - sizeof(ack)); - if (channel) { - ret = ret && sync_write(link->stream, channel->common_caps, - channel->num_common_caps * sizeof(uint32_t)) && - sync_write(link->stream, channel->caps, channel->num_caps * sizeof(uint32_t)); - } + ret = sync_write(link->stream, &header, sizeof(header)); + ret &= sync_write(link->stream, &ack, sizeof(ack)); + ret &= sync_write(link->stream, channel->common_caps, channel->num_common_caps * sizeof(uint32_t)); + ret &= sync_write(link->stream, channel->caps, channel->num_caps * sizeof(uint32_t)); + BIO_free(bio); return ret; } -- 1.7.4