summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2018-03-05 15:57:31 +0000
committerFrediano Ziglio <fziglio@redhat.com>2018-04-11 12:34:14 +0100
commit4e27551f0670f85d5d1b8f9cd6ccb17cac9f7069 (patch)
tree02073ecfeef6c98c014a94dcdaa9142684a81bb9
parent48e7f4c9999afad54cc885c6a8600744afe4fc90 (diff)
stream-device: Factor out function to fill message headers
This function will be reused to initialise different message headers. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe de Dinechin <dinechin@redhat.com>
-rw-r--r--server/red-stream-device.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/server/red-stream-device.c b/server/red-stream-device.c
index d81c3b26..6bc664ee 100644
--- a/server/red-stream-device.c
+++ b/server/red-stream-device.c
@@ -76,6 +76,15 @@ close_timer_func(void *opaque)
}
}
+static void
+fill_dev_hdr(StreamDevHeader *hdr, StreamMsgType msg_type, uint32_t msg_size)
+{
+ hdr->protocol_version = STREAM_DEVICE_PROTOCOL;
+ hdr->padding = 0;
+ hdr->type = GUINT16_TO_LE(msg_type);
+ hdr->size = GUINT32_TO_LE(msg_size);
+}
+
static bool
stream_device_partial_read(StreamDevice *dev, SpiceCharDeviceInstance *sin)
{
@@ -212,10 +221,7 @@ handle_msg_invalid(StreamDevice *dev, SpiceCharDeviceInstance *sin, const char *
buf->buf_used = total_size;
StreamDevHeader *const hdr = (StreamDevHeader *)buf->buf;
- hdr->protocol_version = STREAM_DEVICE_PROTOCOL;
- hdr->padding = 0;
- hdr->type = GUINT16_TO_LE(STREAM_TYPE_NOTIFY_ERROR);
- hdr->size = GUINT32_TO_LE(msg_size);
+ fill_dev_hdr(hdr, STREAM_TYPE_NOTIFY_ERROR, msg_size);
StreamMsgNotifyError *const error = (StreamMsgNotifyError *)(hdr+1);
error->error_code = GUINT32_TO_LE(0);
@@ -453,10 +459,7 @@ stream_device_stream_start(void *opaque, StreamMsgStartStop *start,
buf->buf_used = total_size;
StreamDevHeader *hdr = (StreamDevHeader *)buf->buf;
- hdr->protocol_version = STREAM_DEVICE_PROTOCOL;
- hdr->padding = 0;
- hdr->type = GUINT16_TO_LE(STREAM_TYPE_START_STOP);
- hdr->size = GUINT32_TO_LE(msg_size);
+ fill_dev_hdr(hdr, STREAM_TYPE_START_STOP, msg_size);
memcpy(&hdr[1], start, msg_size);