changeset 322:a713e91c59c8 ganymed

add ecdsa key support everywhere
author Carl Byington <carl@five-ten-sg.com>
date Thu, 31 Jul 2014 09:03:50 -0700
parents c19b24adf6c9
children 90537ba71897
files src/ch/ethz/ssh2/transport/TransportManager.java
diffstat 1 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/ch/ethz/ssh2/transport/TransportManager.java	Thu Jul 31 08:49:37 2014 -0700
+++ b/src/ch/ethz/ssh2/transport/TransportManager.java	Thu Jul 31 09:03:50 2014 -0700
@@ -133,11 +133,10 @@
     private TransportConnection tc;
     private KexManager km;
 
-    private final List<HandlerEntry> messageHandlers
-        = new ArrayList<HandlerEntry>();
+    private final List<HandlerEntry> messageHandlers = new ArrayList<HandlerEntry>();
 
-    private List<ConnectionMonitor> connectionMonitors
-        = new ArrayList<ConnectionMonitor>();
+    private List<ConnectionMonitor> connectionMonitors = new ArrayList<ConnectionMonitor>();
+    boolean monitorsWereInformed = false;
 
     protected void init(TransportConnection tc, KexManager km) {
         this.tc = tc;
@@ -152,7 +151,7 @@
         return km.getOrWaitForConnectionInfo(kexNumber);
     }
 
-    public IOException getReasonClosedCause() {
+    public Throwable getReasonClosedCause() {
         synchronized (connectionSemaphore) {
             return reasonClosedCause;
         }
@@ -192,22 +191,34 @@
                     }
                     catch (IOException ignore) {
                     }
+                }
+                connectionClosed = true;
+                reasonClosedCause = cause;
+            }
+            connectionSemaphore.notifyAll();
+        }
 
-                    connectionClosed = true;
-                    reasonClosedCause = cause;
+        // check if we need to inform the monitors
+        List monitors = null;
 
-                synchronized (this) {
-                    for (ConnectionMonitor cmon : connectionMonitors) {
-                        try {
-                            cmon.connectionLost(reasonClosedCause);
-                        }
-                        catch (Exception ignore) {
-                        }
-                    }
+        synchronized (this) {
+            // Short term lock to protect "connectionMonitors"
+            // and "monitorsWereInformed"
+            // (they may be modified concurrently)
+            if (monitorsWereInformed == false) {
+                monitorsWereInformed = true;
+                monitors = (List) connectionMonitors.clone();
+            }
+        }
+
+        if (monitors != null) {
+            for (ConnectionMonitor cmon : monitors) {
+                try {
+                    cmon.connectionLost(reasonClosedCause);
+                }
+                catch (Exception ignore) {
                 }
             }
-
-            connectionSemaphore.notifyAll();
         }
     }