[gnome-boxes] Fix a connection race and code silliness



commit 2fbd92953da340a2b5c4c444e65f5602b5fd8e93
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Tue Feb 21 14:04:15 2012 +0100

    Fix a connection race and code silliness
    
    I noticed a bug when a VM is started, it may receive two connections
    very quickly, but since channel events are asynchrnous, we would
    disconnect and hide the display, even if the second connection
    succeeded.
    
    The current code is silly, trying to connect automatically when needed
    when the _connect_display member is set.
    
    Get rid of that, and make sure we try to connect only once. Do not
    connect/disconnect/reconnect etc..
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670539

 src/libvirt-machine.vala |   15 ++++-----------
 src/machine.vala         |    5 +----
 src/remote-machine.vala  |    5 +++--
 3 files changed, 8 insertions(+), 17 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index b7fcc6b..31de3c7 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -22,20 +22,18 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     }
 
     public override void disconnect_display () {
-        if (_connect_display == false)
+        if (display == null)
             return;
 
-        _connect_display = false;
         app.display_page.remove_display ();
+        display.disconnect_it ();
         display = null;
     }
 
     private ulong started_id;
     public override void connect_display () {
-        if (_connect_display) {
-            update_display ();
+        if (display != null)
             return;
-        }
 
         if (state != DomainState.RUNNING) {
             if (started_id != 0)
@@ -66,8 +64,8 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             }
         }
 
-        _connect_display = true;
         update_display ();
+        display.connect_it ();
     }
 
     struct MachineStat {
@@ -267,8 +265,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
     private void update_display () {
         string type, port, socket, host;
 
-        return_if_fail (_connect_display == true);
-
         update_domain_config ();
 
         try {
@@ -282,9 +278,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
             return;
         }
 
-        if (display != null)
-            display.disconnect_it ();
-
         if (host == null || host == "")
             host = "localhost";
 
diff --git a/src/machine.vala b/src/machine.vala
index 23796d3..2401417 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -62,6 +62,7 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             });
 
             disconnected_id = _display.disconnected.connect (() => {
+                message (@"display $name disconnected");
                 app.ui_state = Boxes.UIState.COLLECTION;
             });
 
@@ -74,9 +75,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
             });
 
             _display.password = machine_actor.get_password ();
-
-            if (_connect_display)
-                display.connect_it ();
         }
     }
 
@@ -127,7 +125,6 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
     public abstract bool is_running ();
     public abstract string get_screenshot_prefix ();
 
-    protected bool _connect_display;
     public abstract void connect_display ();
     public abstract void disconnect_display ();
 
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index 25493dd..3757090 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -12,7 +12,7 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
     }
 
     public override void connect_display () {
-        if (_connect_display == true)
+        if (display != null)
             return;
 
         try {
@@ -32,7 +32,8 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
     }
 
     public override void disconnect_display () {
-        _connect_display = false;
+        if (display == null)
+            return;
 
         app.display_page.remove_display ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]