[Mono.Debugger.Soft] Made Connection disposable.
authorJeffrey Stedfast <jeff@xamarin.com>
Wed, 29 Feb 2012 00:55:43 +0000 (19:55 -0500)
committerJeffrey Stedfast <jeff@xamarin.com>
Wed, 29 Feb 2012 00:55:43 +0000 (19:55 -0500)
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/Connection.cs
mcs/class/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachine.cs

index c771787ce4e7a130f4d1ada25d6a4fec1eb1133c..70bfb86a4ee2f33555fcf51e1188593016ded1a7 100644 (file)
@@ -353,7 +353,7 @@ namespace Mono.Debugger.Soft
        /*
         * Represents the connection to the debuggee
         */
-       public abstract class Connection
+       public abstract class Connection : IDisposable
        {
                /*
                 * The protocol and the packet format is based on JDWP, the differences 
@@ -2214,7 +2214,21 @@ namespace Mono.Debugger.Soft
                        res.domain_id = r.ReadId ();
                        return res;
                }
-
+               
+               public void Dispose ()
+               {
+                       Dispose (true);
+                       GC.SuppressFinalize (this);
+               }
+               
+               protected virtual void Dispose (bool disposing)
+               {
+               }
+               
+               ~Connection ()
+               {
+                       Dispose (false);
+               }
        }
        
        class TcpConnection : Connection
@@ -2253,6 +2267,15 @@ namespace Mono.Debugger.Soft
                {
                        socket.Close ();
                }
+               
+               protected override void Dispose (bool disposing)
+               {
+                       if (disposing) {
+                               //Socket.Dispose is explicit in < .NET 4.0
+                               ((IDisposable)socket).Dispose ();
+                       }
+                       base.Dispose (disposing);
+               }
        }
 
        /* This is the interface exposed by the debugger towards the debugger agent */
index 803ebc9c701e4a83c52fbf72fa80dd46e6deeddb..440e1c82f05fa37ba6aac7ecefc1242597042773 100644 (file)
@@ -137,6 +137,7 @@ namespace Mono.Debugger.Soft
                public void Dispose () {
                        conn.VM_Dispose ();
                        conn.Close ();
+                       conn.Dispose ();
                        notify_vm_event (EventType.VMDisconnect, SuspendPolicy.None, 0, 0, null);
                }