summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Lureau <marcandre.lureau@gmail.com>2015-12-16 00:27:22 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-01-14 11:46:58 +0000
commita18bed136f866584daa2a03fe4cf12cc91d295bb (patch)
treecfa6174c4497f82d35fe342f6b3dfb40c9bbaedf
parent80cc3f680a1da4cfc7b2bc1666903086072ce1de (diff)
downloadspice-common-a18bed136f866584daa2a03fe4cf12cc91d295bb.tar.gz
spice-common-a18bed136f866584daa2a03fe4cf12cc91d295bb.tar.xz
spice-common-a18bed136f866584daa2a03fe4cf12cc91d295bb.zip
marshaller: learn to describe fd passing in messages
The marshaller can't serialize fd in memory stream. Instead, append the fd to the marshaller structure. The marshaller user is responsible for sending the fd when the message is sent. The fd to send can be retrieved with spice_marshaller_get_fd(). Note: only a single fd is supported with this API, supporting multiple fd is left for the future if it becomes necessary. Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--common/marshaller.c24
-rw-r--r--common/marshaller.h3
2 files changed, 27 insertions, 0 deletions
diff --git a/common/marshaller.c b/common/marshaller.c
index cedb321..c967371 100644
--- a/common/marshaller.c
+++ b/common/marshaller.c
@@ -19,11 +19,14 @@
#include <config.h>
#endif
+#include "log.h"
#include "marshaller.h"
#include "mem.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
+#include <unistd.h>
+#include <stdio.h>
#ifdef WORDS_BIGENDIAN
#define write_int8(ptr,v) (*((int8_t *)(ptr)) = v)
@@ -84,6 +87,7 @@ struct SpiceMarshaller {
MarshallerItem *items;
MarshallerItem static_items[N_STATIC_ITEMS];
+ int fd;
};
struct SpiceMarshallerData {
@@ -111,6 +115,7 @@ static void spice_marshaller_init(SpiceMarshaller *m,
m->n_items = 0;
m->items_size = N_STATIC_ITEMS;
m->items = m->static_items;
+ m->fd = -1;
}
SpiceMarshaller *spice_marshaller_new(void)
@@ -613,3 +618,22 @@ void *spice_marshaller_add_int8(SpiceMarshaller *m, int8_t v)
write_int8(ptr, v);
return (void *)ptr;
}
+
+void spice_marshaller_add_fd(SpiceMarshaller *m, int fd)
+{
+ spice_assert(m->fd == -1);
+
+ m->fd = dup(fd);
+ if (m->fd == -1) {
+ perror("dup");
+ }
+}
+
+int spice_marshaller_get_fd(SpiceMarshaller *m)
+{
+ int fd = m->fd;
+
+ m->fd = -1;
+
+ return fd;
+}
diff --git a/common/marshaller.h b/common/marshaller.h
index e19c0f6..b698b69 100644
--- a/common/marshaller.h
+++ b/common/marshaller.h
@@ -66,6 +66,9 @@ void *spice_marshaller_add_int8(SpiceMarshaller *m, int8_t v);
void spice_marshaller_set_uint32(SpiceMarshaller *m, void *ref, uint32_t v);
+void spice_marshaller_add_fd(SpiceMarshaller *m, int fd);
+int spice_marshaller_get_fd(SpiceMarshaller *m);
+
SPICE_END_DECLS
#endif