[Spice-devel] [RFC v4 19/62] server/red_channel: add RedChannel.clients_num

Alon Levy alevy at redhat.com
Tue Apr 26 03:54:44 PDT 2011


---
 server/red_channel.c |   20 ++++++++++++--------
 server/red_channel.h |    3 ++-
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/server/red_channel.c b/server/red_channel.c
index 7e1edbe..24ad67f 100644
--- a/server/red_channel.c
+++ b/server/red_channel.c
@@ -364,6 +364,7 @@ static void red_channel_add_client(RedChannel *channel, RedChannelClient *rcc)
 {
     ASSERT(rcc && !channel->rcc);
 	channel->rcc = rcc;
+    channel->clients_num++;
 }
 
 RedChannelClient *red_channel_client_create(
@@ -402,7 +403,7 @@ RedChannelClient *red_channel_client_create(
     stream->watch = channel->core->watch_add(stream->socket,
                                            SPICE_WATCH_EVENT_READ,
                                            red_channel_client_event, rcc);
-    rcc->id = 0;
+    rcc->id = channel->clients_num;
     red_channel_add_client(channel, rcc);
     red_client_add_channel(client, rcc);
     return rcc;
@@ -861,6 +862,15 @@ void red_channel_ack_set_client_window(RedChannel* channel, int client_window)
     }
 }
 
+static void red_channel_client_unlink(RedChannelClient *rcc)
+{
+    ring_remove(&rcc->client_link);
+    rcc->client->channels_num--;
+    ASSERT(rcc->channel->rcc == rcc);
+    rcc->channel->rcc = NULL;
+    rcc->channel->clients_num--;
+}
+
 void red_channel_client_disconnect(RedChannelClient *rcc)
 {
     red_printf("%p (channel %p)", rcc, rcc->channel);
@@ -873,7 +883,7 @@ void red_channel_client_disconnect(RedChannelClient *rcc)
     rcc->send_data.item = NULL;
     rcc->send_data.blocked = FALSE;
     rcc->send_data.size = 0;
-    rcc->channel->rcc = NULL;
+    red_channel_client_unlink(rcc);
 }
 
 void red_channel_disconnect(RedChannel *channel)
@@ -1037,12 +1047,6 @@ static void red_client_add_channel(RedClient *client, RedChannelClient *rcc)
     client->channels_num++;
 }
 
-void red_client_remove_channel(RedClient *client, RedChannelClient *rcc)
-{
-    ring_remove(&rcc->client_link);
-    client->channels_num--;
-}
-
 MainChannelClient *red_client_get_main(RedClient *client) {
     return client->mcc;
 }
diff --git a/server/red_channel.h b/server/red_channel.h
index 15d70b6..844e374 100644
--- a/server/red_channel.h
+++ b/server/red_channel.h
@@ -176,6 +176,7 @@ struct RedChannel {
     int handle_acks;
 
     RedChannelClient *rcc;
+    uint32_t clients_num;
 
     OutgoingHandlerInterface outgoing_cb;
     IncomingHandlerInterface incoming_cb;
@@ -384,4 +385,4 @@ void red_client_destroy(RedClient *client);
 void red_client_set_main(RedClient *client, MainChannelClient *mcc);
 MainChannelClient *red_client_get_main(RedClient *client);
 
-#endif
\ No newline at end of file
+#endif
-- 
1.7.4.4



More information about the Spice-devel mailing list