mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-09 05:37:12 +00:00
server: simplify and constify sync_write()
+ symplify, improving style of code using it. https://bugs.freedesktop.org/show_bug.cgi?id=34795
This commit is contained in:
parent
8186db28c2
commit
159fee00c2
@ -1864,9 +1864,9 @@ static void reds_main_event(int fd, int event, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -1885,10 +1885,11 @@ static int reds_send_link_ack(RedLinkInfo *link)
|
||||
{
|
||||
SpiceLinkHeader header;
|
||||
SpiceLinkReply ack;
|
||||
Channel caps = { 0, };
|
||||
Channel *channel;
|
||||
BUF_MEM *bmBuf;
|
||||
BIO *bio;
|
||||
int ret;
|
||||
int ret = FALSE;
|
||||
|
||||
header.magic = SPICE_MAGIC;
|
||||
header.size = sizeof(ack);
|
||||
@ -1897,14 +1898,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())) {
|
||||
@ -1925,13 +1926,20 @@ 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));
|
||||
}
|
||||
|
||||
if (!sync_write(link->stream, &header, sizeof(header)))
|
||||
goto end;
|
||||
if (!sync_write(link->stream, &ack, sizeof(ack)))
|
||||
goto end;
|
||||
if (!sync_write(link->stream, channel->common_caps, channel->num_common_caps * sizeof(uint32_t)))
|
||||
goto end;
|
||||
if (!sync_write(link->stream, channel->caps, channel->num_caps * sizeof(uint32_t)))
|
||||
goto end;
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
end:
|
||||
reds_channel_dispose(&caps);
|
||||
BIO_free(bio);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user