[Spice-devel] [PATCH spice-server v4 3/3] red-channel: Use RedChannelCapabilities directly to pass capabilities

Frediano Ziglio fziglio at redhat.com
Thu Mar 2 15:15:15 UTC 2017


> 
> On Thu, Mar 02, 2017 at 12:30:26PM +0000, Frediano Ziglio wrote:
> > diff --git a/server/red-worker.c b/server/red-worker.c
> > index 8735cd1..fbb7070 100644
> > --- a/server/red-worker.c
> > +++ b/server/red-worker.c
> > @@ -736,7 +736,7 @@ static void handle_dev_display_connect(void *opaque,
> > void *payload)
> >      spice_return_if_fail(display);
> >  
> >      dcc = dcc_new(display, msg->client, msg->stream, msg->migration,
> > -                  msg->common_caps, msg->num_common_caps, msg->caps,
> > msg->num_caps,
> > +                  &msg->caps,
> 
> I'd put this one on the same line as msg->migration.
> 
> >                    worker->image_compression, worker->jpeg_state,
> >                    worker->zlib_glz_state);
> >      if (!dcc) {
> >          return;
> > @@ -745,8 +745,7 @@ static void handle_dev_display_connect(void *opaque,
> > void *payload)
> >      guest_set_client_capabilities(worker);
> >      dcc_start(dcc);
> >  
> > -    free(msg->caps);
> > -    free(msg->common_caps);
> > +    red_channel_capabilities_reset(&msg->caps);
> >  }
> >  
> >  static void handle_dev_display_disconnect(void *opaque, void *payload)
> > @@ -832,10 +831,8 @@ static void handle_dev_cursor_connect(void *opaque,
> > void *payload)
> >      spice_debug("cursor connect");
> >      cursor_channel_connect(worker->cursor_channel,
> >                             msg->client, msg->stream, msg->migration,
> > -                           msg->common_caps, msg->num_common_caps,
> > -                           msg->caps, msg->num_caps);
> > -    free(msg->caps);
> > -    free(msg->common_caps);
> > +                           &msg->caps);
> > +    red_channel_capabilities_reset(&msg->caps);
> >  }
> >  
> >  static void handle_dev_cursor_disconnect(void *opaque, void *payload)
> > diff --git a/server/reds.c b/server/reds.c
> > index f99dfda..6b8d1ef 100644
> > --- a/server/reds.c
> > +++ b/server/reds.c
> > @@ -1675,6 +1675,26 @@ static RedClient *reds_get_client(RedsState *reds)
> >      return reds->clients->data;
> >  }
> >  
> > +static void
> > +red_channel_capabilities_from_link_message(RedChannelCapabilities *caps,
> > +                                           const SpiceLinkMess *link_mess)
> > +{
> > +    const uint32_t *raw_caps = (uint32_t *)((uint8_t *)link_mess +
> > link_mess->caps_offset);
> > +
> > +    caps->num_common_caps = link_mess->num_common_caps;
> > +    caps->common_caps = NULL;
> > +    if (caps->num_common_caps) {
> > +        caps->common_caps = spice_memdup(raw_caps,
> > +                                         link_mess->num_common_caps *
> > sizeof(uint32_t));
> > +    }
> > +    caps->num_caps = link_mess->num_channel_caps;
> > +    caps->caps = NULL;
> > +    if (link_mess->num_channel_caps) {
> > +        caps->caps = spice_memdup(raw_caps + link_mess->num_common_caps,
> > +                                  link_mess->num_channel_caps *
> > sizeof(uint32_t));
> > +    }
> > +}
> 
> Not really a big fan of having this kind of functions because we use
> stack-allocated struct rather than just allocating a new struct. This
> function should only be used on non-initialized RedChannelCapabilities
> (this will leak otherwise), but it's non-obvious from the function name.
> 

Maybe red_channel_capabilities_init_from_link_message ?

> 
> Acked-by: Christophe Fergeau <cfergeau at redhat.com>
> 
> Christophe
> 

Frediano


More information about the Spice-devel mailing list