[Spice-devel] [PATCH spice-streaming-agent v3 3/4] Handle capabilities

Frediano Ziglio fziglio at redhat.com
Wed Feb 21 10:48:05 UTC 2018


>
> On Tue, 2018-02-20 at 20:48 +0000, Frediano Ziglio wrote:
> > Do not bail if the server is attempting to communicate some extensions
> > but just ignore as at the moment we support none.
> > 
> > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> >  src/spice-streaming-agent.cpp | 30 ++++++++++++++++++++++++++++++
> >  1 file changed, 30 insertions(+)
> > 
> > diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp
> > index 8d91f2d..31c655c 100644
> > --- a/src/spice-streaming-agent.cpp
> > +++ b/src/spice-streaming-agent.cpp
> > @@ -40,6 +40,8 @@
> >  
> >  using namespace spice::streaming_agent;
> >  
> > +static size_t write_all(int fd, const void *buf, const size_t len);
> > +
> >  static ConcreteAgent agent;
> >  
> >  struct SpiceStreamFormatMessage
> > @@ -77,6 +79,7 @@ static int have_something_to_read(int timeout)
> >      return 0;
> >  }
> >  
> > +static void handle_stream_capabilities(uint32_t len);
> >  static void handle_stream_start_stop(uint32_t len);
> >  
> >  static void read_command_from_device(void)
> > @@ -96,6 +99,8 @@ static void read_command_from_device(void)
> >      }
> >  
> >      switch (hdr.type) {
> > +    case STREAM_TYPE_CAPABILITIES:
> > +        return handle_stream_capabilities(hdr.size);
> >      case STREAM_TYPE_START_STOP:
> >          return handle_stream_start_stop(hdr.size);
> >      }
> > @@ -124,6 +129,31 @@ static void handle_stream_start_stop(uint32_t len)
> >      }
> >  }
> >  
> > +static void handle_stream_capabilities(uint32_t len)
> > +{
> > +    uint8_t caps[STREAM_MSG_CAPABILITIES_MAX_BYTES];
> > +
> > +    if (len > sizeof(caps)) {
> > +        throw std::runtime_error("capability message too long");
> > +    }
> > +    int n = read(streamfd, caps, len);
> > +    if (n != len) {
> > +        throw std::runtime_error("read command from device FAILED -- read
> > " + std::to_string(n) +
> > +                                 " expected " + std::to_string(len));
> > +    }
> > +
> > +    // we currently do not support extensions so just reply so
> > +    StreamDevHeader hdr = {
> > +        STREAM_DEVICE_PROTOCOL,
> > +        0,
> > +        STREAM_TYPE_CAPABILITIES,
> > +        0
> > +    };
> > +    if (write_all(streamfd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
> > +        throw std::runtime_error("error writing capabilities");
> > +    }
> > +}
> > +
> >  static int read_command(bool blocking)
> >  {
> >      int timeout = blocking?-1:0;
> 
> LGTM, I'm not entirely knowledgable of the capabilities interaction
> though.
> 
> Reviewed-by: Lukáš Hrázký <lhrazky at redhat.com>
> 

>From stream-device.h:

/* Generic extension capabilities.
 * This is a set of bits to specify which capabilities host and guest support.
 * This message is sent by the host to the guest or by the guest to the host.
 * Should be sent as first message.
 * If it is not sent, it means that guest/host doesn't support any extension.
 * Guest should send this as a reply from same type of message
 * from the host.
 * This message should be limited to STREAM_MSG_CAPABILITIES_MAX_BYTES. This
 * allows plenty of negotiations.
 *
 * States allowed: Initial(host), Idle(guest)
 *   state will change to Idle.
 */
typedef struct StreamMsgCapabilities {
    uint8_t capabilities[0];
} StreamMsgCapabilities;

Frediano


More information about the Spice-devel mailing list