summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Lureau <marcandre.lureau@gmail.com>2015-12-22 16:08:08 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-01-14 11:46:16 +0000
commit267391c8fd7c90c067b3e4845ff0227a2580e2e2 (patch)
tree8a8b6f3eb654d42afb77b603e4b1c2bd68c65267
parent6b86c1a510f333f53a6955cd09da16fd98731d02 (diff)
downloadspice-protocol-267391c8fd7c90c067b3e4845ff0227a2580e2e2.tar.gz
spice-protocol-267391c8fd7c90c067b3e4845ff0227a2580e2e2.tar.xz
spice-protocol-267391c8fd7c90c067b3e4845ff0227a2580e2e2.zip
protocol: learn to describe fd passing in messages
Add a new type, "unix_fd", used to describe file descriptor sharing via socket ancillary data (these messages are local only). The marshaller/demarshaller can't serialize this in memory (consume_fd implementation is empty), so it is the responsability of the marshaller user to handle sending and receiving the handles, which are appended at the end of the message with an extra stream byte (because some Unix requires sending at least a byte with ancillary data). Even if there is no fd to send (or if the fd is invalid etc), the receiver side expects an extra byte anyway. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--python_modules/demarshal.py4
-rw-r--r--python_modules/ptypes.py9
-rw-r--r--python_modules/spice_parser.py3
3 files changed, 15 insertions, 1 deletions
diff --git a/python_modules/demarshal.py b/python_modules/demarshal.py
index 209eafc..2252f37 100644
--- a/python_modules/demarshal.py
+++ b/python_modules/demarshal.py
@@ -72,6 +72,10 @@ def write_parser_helpers(writer):
writer.statement("return val")
writer.end_block()
+ writer.function("SPICE_GNUC_UNUSED consume_fd", "int", "uint8_t **ptr", True)
+ writer.statement("return -1")
+ writer.end_block()
+
writer.newline()
writer.statement("typedef struct PointerInfo PointerInfo")
writer.statement("typedef void (*message_destructor_t)(uint8_t *message)")
diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 7ab2771..9c10b57 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -1119,6 +1119,14 @@ class ProtocolType(Type):
return self
+class FdType(IntegerType):
+
+ def primitive_type(self):
+ return "fd"
+
+ def c_type(self):
+ return "int"
+
int8 = IntegerType(8, True)
uint8 = IntegerType(8, False)
int16 = IntegerType(16, True)
@@ -1127,3 +1135,4 @@ int32 = IntegerType(32, True)
uint32 = IntegerType(32, False)
int64 = IntegerType(64, True)
uint64 = IntegerType(64, False)
+unix_fd = FdType(1, True)
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index 97af8b2..db3cc8d 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -56,6 +56,7 @@ def SPICE_BNF():
uint32_ = Keyword("uint32").setParseAction(replaceWith(ptypes.uint32))
int64_ = Keyword("int64").setParseAction(replaceWith(ptypes.int64))
uint64_ = Keyword("uint64").setParseAction(replaceWith(ptypes.uint64))
+ unix_fd_ = Keyword("unix_fd").setParseAction(replaceWith(ptypes.unix_fd))
# keywords
enum32_ = Keyword("enum32").setParseAction(replaceWith(32))
@@ -108,7 +109,7 @@ def SPICE_BNF():
# have to use longest match for type, in case a user-defined type name starts with a keyword type, like "channel_type"
typeSpec << ( structSpec ^ int8_ ^ uint8_ ^ int16_ ^ uint16_ ^
- int32_ ^ uint32_ ^ int64_ ^ uint64_ ^
+ int32_ ^ uint32_ ^ int64_ ^ uint64_ ^ unix_fd_ ^
typename).setName("type")
flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(equals + integer))) + Optional(comma) + rbrace)