[Spice-devel] [spice-server v2 09/14] rcc: Pass RedChannelClient to red_peer_handle_outgoing()

Christophe Fergeau cfergeau at redhat.com
Tue Feb 14 14:17:34 UTC 2017


There is only one implementation of OutgoingHandler which relies
OutgoingHandler::opaque being a RedChannelClient. This commit makes this
explicit in order to get rid of the OutgoingHandler::opaque data member.

This renames red_peer_handle_outgoing() to
red_channel_client_handle_outgoing() as the method is now very much tied
to RedChannelClient.

If we want to keep some genericity, we could return error codes from
red_channel_client_handle_outgoing() and handle RedChannelClient
disconnection/... from the caller rather than directly in the
_handle_outgoing() method. This would probably allow to move the
data reading logic to reds-stream.c

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 server/red-channel-client-private.h |  1 -
 server/red-channel-client.c         | 23 ++++++++++++-----------
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/server/red-channel-client-private.h b/server/red-channel-client-private.h
index a7167e5..08ac6ca 100644
--- a/server/red-channel-client-private.h
+++ b/server/red-channel-client-private.h
@@ -41,7 +41,6 @@ typedef struct RedChannelClientConnectivityMonitor {
 } RedChannelClientConnectivityMonitor;
 
 typedef struct OutgoingHandler {
-    void *opaque;
     struct iovec vec_buf[IOV_MAX];
     int vec_size;
     struct iovec *vec;
diff --git a/server/red-channel-client.c b/server/red-channel-client.c
index c907842..8b2434c 100644
--- a/server/red-channel-client.c
+++ b/server/red-channel-client.c
@@ -268,7 +268,6 @@ static void red_channel_client_constructed(GObject *object)
 {
     RedChannelClient *self =  RED_CHANNEL_CLIENT(object);
 
-    self->priv->outgoing.opaque = self;
     self->priv->outgoing.pos = 0;
     self->priv->outgoing.size = 0;
 
@@ -1016,8 +1015,10 @@ static void red_channel_client_release_msg_buf(RedChannelClient *rcc,
     klass->release_recv_buf(rcc, type, size, msg);
 }
 
-static void red_peer_handle_outgoing(RedsStream *stream, OutgoingHandler *handler)
+static void red_channel_client_handle_outgoing(RedChannelClient *rcc)
 {
+    RedsStream *stream = rcc->priv->stream;
+    OutgoingHandler *handler = &rcc->priv->outgoing;
     ssize_t n;
 
     if (!stream) {
@@ -1026,41 +1027,41 @@ static void red_peer_handle_outgoing(RedsStream *stream, OutgoingHandler *handle
 
     if (handler->size == 0) {
         handler->vec = handler->vec_buf;
-        handler->size = red_channel_client_get_out_msg_size(handler->opaque);
+        handler->size = red_channel_client_get_out_msg_size(rcc);
         if (!handler->size) {  // nothing to be sent
             return;
         }
     }
 
     for (;;) {
-        red_channel_client_prepare_out_msg(handler->opaque, handler->vec, &handler->vec_size, handler->pos);
+        red_channel_client_prepare_out_msg(rcc, handler->vec, &handler->vec_size, handler->pos);
         n = reds_stream_writev(stream, handler->vec, handler->vec_size);
         if (n == -1) {
             switch (errno) {
             case EAGAIN:
-                red_channel_client_set_blocked(handler->opaque);
+                red_channel_client_set_blocked(rcc);
                 return;
             case EINTR:
                 continue;
             case EPIPE:
-                red_channel_client_disconnect(handler->opaque);
+                red_channel_client_disconnect(rcc);
                 return;
             default:
                 spice_printerr("%s", strerror(errno));
-                red_channel_client_disconnect(handler->opaque);
+                red_channel_client_disconnect(rcc);
                 return;
             }
         } else {
             handler->pos += n;
-            red_channel_client_data_sent(handler->opaque, n);
+            red_channel_client_data_sent(rcc, n);
             if (handler->pos == handler->size) { // finished writing data
                 /* reset handler before calling on_msg_done, since it
-                 * can trigger another call to red_peer_handle_outgoing (when
+                 * can trigger another call to red_channel_client_handle_outgoing (when
                  * switching from the urgent marshaller to the main one */
                 handler->vec = handler->vec_buf;
                 handler->pos = 0;
                 handler->size = 0;
-                red_channel_client_msg_sent(handler->opaque);
+                red_channel_client_msg_sent(rcc);
                 return;
             }
         }
@@ -1231,7 +1232,7 @@ void red_channel_client_receive(RedChannelClient *rcc)
 void red_channel_client_send(RedChannelClient *rcc)
 {
     g_object_ref(rcc);
-    red_peer_handle_outgoing(rcc->priv->stream, &rcc->priv->outgoing);
+    red_channel_client_handle_outgoing(rcc);
     g_object_unref(rcc);
 }
 
-- 
2.9.3



More information about the Spice-devel mailing list