[Spice-devel] [PATCH server v2 05/13] red-channel: send marshaller message fd

Frediano Ziglio fziglio at redhat.com
Tue Jan 19 02:21:12 PST 2016


> 
> Maybe it's just me, but I don't really understand the purpose of this patch.
> Can
> you give a big-picture explanation?
> 
> 

Adding the possibility to pass a file descriptor to the client using messages.
This is possible only with unix sockets and local clients.

In this case is used to pass a DRM object with the scanout (a gl version of the
framebuffer) to the client. But can be used to pass a SHM object, events to talk
directly to the VM, log file or whatever file descriptor.

The file descriptor is "attached" to the end of the message.

Frediano

> 
> 
> On Thu, 2016-01-14 at 22:01 +0100, Marc-André Lureau wrote:
> > From: Marc-André Lureau <mlureau at redhat.com>
> > 
> > Send the fd associated to the last message sent.
> > 
> > Even if the fd is invalid, the sendfd msg is appended to the protocol,
> > for 2 reasons:
> > - trying to send an invalid fd does not have to close the connection (it
> >   would with an invalid fd)
> > - even if the fd is invalid, the protocol expects an extra byte for the
> >   ancillary data
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau at gmail.com>
> > ---
> >  server/red-channel.c | 16 ++++++++++++++++
> >  1 file changed, 16 insertions(+)
> > 
> > diff --git a/server/red-channel.c b/server/red-channel.c
> > index 306c87d..b33c91d 100644
> > --- a/server/red-channel.c
> > +++ b/server/red-channel.c
> > @@ -608,8 +608,24 @@ static inline void
> > red_channel_client_release_sent_item(RedChannelClient *rcc)
> >  static void red_channel_peer_on_out_msg_done(void *opaque)
> >  {
> >      RedChannelClient *rcc = (RedChannelClient *)opaque;
> > +    int fd = spice_marshaller_get_fd(rcc->send_data.marshaller);
> >  
> >      rcc->send_data.size = 0;
> > +
> > +    if (fd != -1) {
> > +        if (fcntl(fd, F_GETFD) == -1) {
> > +            close(fd);
> > +            fd = -1;
> > +        }
> > +
> > +        if (reds_stream_send_msgfd(rcc->stream, fd) < 0) {
> > +            perror("sendfd");
> > +            red_channel_client_disconnect(rcc);
> > +            return;
> > +        }
> > +        close(fd);
> > +    }
> > +
> >      red_channel_client_release_sent_item(rcc);
> >      if (rcc->send_data.blocked) {
> >          rcc->send_data.blocked = FALSE;



More information about the Spice-devel mailing list