[Spice-devel] [PATCH spice-server 06/10] reds: disconnect the session when an essential channel is disconnected

Yonit Halperin yhalperi at redhat.com
Wed May 8 07:06:21 PDT 2013


---
 server/reds.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/server/reds.c b/server/reds.c
index f6a1ce9..38923b0 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -194,12 +194,37 @@ static void reds_stream_push_channel_event(RedsStream *s, int event)
     main_dispatcher_channel_event(event, s->info);
 }
 
+static const int mandatory_channels[] = {SPICE_CHANNEL_MAIN, SPICE_CHANNEL_DISPLAY, SPICE_CHANNEL_INPUTS};
+
+static int channel_is_mandatory(int type)
+{
+    int i;
+    for (i = 0 ; i < sizeof(mandatory_channels)/sizeof(mandatory_channels[0]); ++i) {
+        if (type == mandatory_channels[i]) {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
 void reds_handle_channel_event(int event, SpiceChannelEventInfo *info)
 {
     if (core->base.minor_version >= 3 && core->channel_event != NULL)
         core->channel_event(event, info);
 
     if (event == SPICE_CHANNEL_EVENT_DISCONNECTED) {
+        if (channel_is_mandatory(info->type) && reds->main_channel) {
+            RedClient *client = main_channel_get_client_by_link_id(reds->main_channel,
+                                                                   info->connection_id);
+            /* if client == NULL, it means that main channel has already been disconnected.
+             * and since main channel is a mandatory channel, reds_client_disconnect has
+             * already been called */
+            if (client) {
+                spice_debug("client %p: mandatory channel (type %d id %d)"
+                            " has disconnected; closing session", client, info->type, info->id);
+                reds_client_disconnect(client);
+            }
+        }
         free(info);
     }
 }
-- 
1.8.1.4



More information about the Spice-devel mailing list