diff options
author | Marc-Andre Lureau <marcandre.lureau@gmail.com> | 2016-01-22 18:04:35 +0100 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2016-02-02 12:38:54 +0000 |
commit | 472e563591a80f75679be2ea855e660c6ee51721 (patch) | |
tree | a1963e203257c054a3369b01a29340ffb5639aa3 /common/marshaller.c | |
parent | 6424c0baee9b25cc4508e3f1a81f7be5546a3793 (diff) | |
download | spice-common-472e563591a80f75679be2ea855e660c6ee51721.tar.gz spice-common-472e563591a80f75679be2ea855e660c6ee51721.tar.xz spice-common-472e563591a80f75679be2ea855e660c6ee51721.zip |
marshaller: track if add_fd() was given -1
In some cases, it might be worth to be able to send a message with a -1
fd, has the protocol permits. Change add_fd/get_fd in order to track
if the caller wanted to send -1.
Signed-off-by: Marc-André Lureau <marcandre.lureau@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Diffstat (limited to 'common/marshaller.c')
-rw-r--r-- | common/marshaller.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/common/marshaller.c b/common/marshaller.c index c1d208e..cffc641 100644 --- a/common/marshaller.c +++ b/common/marshaller.c @@ -87,6 +87,7 @@ struct SpiceMarshaller { MarshallerItem *items; MarshallerItem static_items[N_STATIC_ITEMS]; + bool has_fd; int fd; }; @@ -624,19 +625,25 @@ void *spice_marshaller_add_int8(SpiceMarshaller *m, int8_t v) void spice_marshaller_add_fd(SpiceMarshaller *m, int fd) { - spice_assert(m->fd == -1); + spice_assert(m->has_fd == false); - m->fd = dup(fd); - if (m->fd == -1) { - perror("dup"); + m->has_fd = true; + if (fd != -1) { + m->fd = dup(fd); + if (m->fd == -1) { + perror("dup"); + } + } else { + m->fd = -1; } } -int spice_marshaller_get_fd(SpiceMarshaller *m) +bool spice_marshaller_get_fd(SpiceMarshaller *m, int *fd) { - int fd = m->fd; + bool had_fd = m->has_fd; - m->fd = -1; + *fd = m->fd; + m->has_fd = false; - return fd; + return had_fd; } |