# HG changeset patch # User Carl Byington # Date 1406822630 25200 # Node ID a713e91c59c8709c4bd5e9dc45f164c7c2b3b68d # Parent c19b24adf6c98a93fbb5a42d243009431c7846a1 add ecdsa key support everywhere diff -r c19b24adf6c9 -r a713e91c59c8 src/ch/ethz/ssh2/transport/TransportManager.java --- 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 messageHandlers - = new ArrayList(); + private final List messageHandlers = new ArrayList(); - private List connectionMonitors - = new ArrayList(); + private List connectionMonitors = new ArrayList(); + 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(); } }