[Spice-devel] [PATCH spice 07/10] client/red_peer: support SpiceDataHeaderNoSub

Yonit Halperin yhalperi at redhat.com
Wed Dec 28 09:15:16 PST 2011


---
 client/red_peer.cpp |   40 +++++++++++++++++++++++++++++++---------
 client/red_peer.h   |   11 +++++++++++
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/client/red_peer.cpp b/client/red_peer.cpp
index 17fcb45..22eb0a4 100644
--- a/client/red_peer.cpp
+++ b/client/red_peer.cpp
@@ -38,7 +38,8 @@ static void ssl_error()
 }
 
 RedPeer::RedPeer()
-    : _peer (INVALID_SOCKET)
+    : _header_size (sizeof(SpiceDataHeader))
+    , _peer (INVALID_SOCKET)
     , _shut (false)
     , _ctx (NULL)
     , _ssl (NULL)
@@ -340,7 +341,8 @@ RedPeer::CompoundInMessage* RedPeer::receive()
     SpiceDataHeader header;
     AutoRef<CompoundInMessage> message;
 
-    receive((uint8_t*)&header, sizeof(SpiceDataHeader));
+    header.sub_list = 0;
+    receive((uint8_t*)&header, _header_size);
     message.reset(new CompoundInMessage(header.serial, header.type, header.size, header.sub_list));
     receive((*message)->data(), (*message)->compound_size());
     return message.release();
@@ -423,21 +425,33 @@ uint32_t RedPeer::send(RedPeer::OutMessage& message)
 {
 
     message.header().serial = ++_serial;
-    message.header().size = message.message_size() - sizeof(SpiceDataHeader);
+    message.header().size = message.message_size() - _header_size;
 
     return do_send(message, 0);
 }
 
+void RedPeer::set_is_header_with_sub_list(bool with_sub)
+{
+    _header_size = with_sub ? sizeof(SpiceDataHeader) : sizeof(SpiceDataHeaderNoSub);
+    _is_header_with_sub = with_sub;
+    OutMessage::set_header_prop(with_sub, _header_size);
+}
+
+uint32_t RedPeer::OutMessage::_header_size = sizeof(SpiceDataHeader);
+bool RedPeer::OutMessage::_is_header_with_sub = true;
+
 RedPeer::OutMessage::OutMessage(uint32_t type)
     : _marshaller (spice_marshaller_new())
 {
     SpiceDataHeader *header;
     header = (SpiceDataHeader *)
-        spice_marshaller_reserve_space(_marshaller, sizeof(SpiceDataHeader));
-    spice_marshaller_set_base(_marshaller, sizeof(SpiceDataHeader));
+        spice_marshaller_reserve_space(_marshaller, _header_size);
+    spice_marshaller_set_base(_marshaller, _header_size);
 
     header->type = type;
-    header->sub_list = 0;
+    if (_is_header_with_sub) {
+        header->sub_list = 0;
+    }
 }
 
 void RedPeer::OutMessage::reset(uint32_t type)
@@ -446,11 +460,19 @@ void RedPeer::OutMessage::reset(uint32_t type)
 
     SpiceDataHeader *header;
     header = (SpiceDataHeader *)
-        spice_marshaller_reserve_space(_marshaller, sizeof(SpiceDataHeader));
-    spice_marshaller_set_base(_marshaller, sizeof(SpiceDataHeader));
+        spice_marshaller_reserve_space(_marshaller, _header_size);
+    spice_marshaller_set_base(_marshaller, _header_size);
 
     header->type = type;
-    header->sub_list = 0;
+    if (_is_header_with_sub) {
+        header->sub_list = 0;
+    }
+}
+
+void RedPeer::OutMessage::set_header_prop(bool with_sub, uint32_t header_size)
+{
+    _is_header_with_sub = with_sub;
+     _header_size = header_size;
 }
 
 RedPeer::OutMessage::~OutMessage()
diff --git a/client/red_peer.h b/client/red_peer.h
index 8932357..bf5c373 100644
--- a/client/red_peer.h
+++ b/client/red_peer.h
@@ -117,6 +117,8 @@ public:
     uint32_t receive(uint8_t* buf, uint32_t size);
     uint32_t send(uint8_t* buf, uint32_t size);
 
+    void set_is_header_with_sub_list(bool with_sub);
+
 protected:
     virtual void on_event() {}
     virtual int get_socket() { return _peer;}
@@ -126,6 +128,10 @@ private:
     void connect_to_peer(const char* host, int port);
     void shutdown();
 
+protected:
+    uint32_t _header_size;
+    bool _is_header_with_sub;
+
 private:
     SOCKET _peer;
     Mutex _lock;
@@ -198,9 +204,14 @@ private:
     uint8_t* base() { return spice_marshaller_get_ptr(_marshaller);}
     SpiceDataHeader& header() { return *(SpiceDataHeader *)base();}
 
+    static void set_header_prop(bool with_sub, uint32_t header_size);
+
 protected:
     SpiceMarshaller *_marshaller;
 
+private:
+    static uint32_t _header_size;
+    static bool _is_header_with_sub;
     friend class RedPeer;
     friend class RedChannel;
 };
-- 
1.7.6.4



More information about the Spice-devel mailing list