[Spice-devel] [PATCH 10/13] server: simplify and constify sync_write()
Marc-André Lureau
marcandre.lureau at redhat.com
Tue Feb 22 08:09:04 PST 2011
+ symplify, improving style of code using it.
---
server/reds.c | 33 ++++++++++++++++-----------------
1 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/server/reds.c b/server/reds.c
index 3e2f927..c080005 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -1330,9 +1330,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 *peer, void *in_buf, size_t n)
+static int sync_write(RedsStream *peer, 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(peer, buf, n);
if (now <= 0) {
@@ -1351,6 +1351,7 @@ static int reds_send_link_ack(RedLinkInfo *link)
{
SpiceLinkHeader header;
SpiceLinkReply ack;
+ Channel caps = { 0, };
Channel *channel;
BUF_MEM *bmBuf;
BIO *bio;
@@ -1363,14 +1364,13 @@ 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())) {
@@ -1391,13 +1391,12 @@ 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
More information about the Spice-devel
mailing list