[PATCH spice-server v3 2/4] stream-device: Factor out function to fill message headers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function will be reused to initialise different message
headers.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 server/red-stream-device.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/server/red-stream-device.c b/server/red-stream-device.c
index e91df88d..bfa6c559 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);
 
-- 
2.14.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]