# HG changeset patch # User Carl Byington # Date 1406820047 25200 # Node ID 776a220dbcc6189462fd24579c259421c365b3ff # Parent 5351641c8a4682fd3b6aa811cea017bfabc6f9b8 add ecdsa key support everywhere diff -r 5351641c8a46 -r 776a220dbcc6 src/ch/ethz/ssh2/Connection.java --- a/src/ch/ethz/ssh2/Connection.java Wed Jul 30 17:46:06 2014 -0700 +++ b/src/ch/ethz/ssh2/Connection.java Thu Jul 31 08:20:47 2014 -0700 @@ -670,27 +670,17 @@ */ public void close() { + Throwable t = new Throwable("Closed due to user request."); + close(t, false); + } + + public void close(Throwable t, boolean hard) { if (cm != null) { cm.closeAllChannels(); } if (tm != null) { - tm.close(); - tm = null; - } - - am = null; - cm = null; - authenticated = false; - } - - public synchronized void close(IOException t) { - if (cm != null) { - cm.closeAllChannels(); - } - - if (tm != null) { - tm.close(t); + tm.close(t, hard == false); tm = null; } @@ -827,7 +817,7 @@ } state.timeoutSocketClosed = true; - tm.close(new SocketTimeoutException("The connect timeout expired")); + tm.close(new SocketTimeoutException("The connect timeout expired"), false); } } }; diff -r 5351641c8a46 -r 776a220dbcc6 src/ch/ethz/ssh2/transport/TransportManager.java --- a/src/ch/ethz/ssh2/transport/TransportManager.java Wed Jul 30 17:46:06 2014 -0700 +++ b/src/ch/ethz/ssh2/transport/TransportManager.java Thu Jul 31 08:20:47 2014 -0700 @@ -162,30 +162,47 @@ return km.sessionId; } - public void close() { - // It is safe now to acquire the semaphore. + public void close(Throwable cause, boolean useDisconnectPacket) { + if (useDisconnectPacket == false) { + // OK, hard shutdown - do not acquire the semaphore, + // perhaps somebody is inside (and waits until + // the remote side is ready to accept new data). + try { + socket.close(); + } + catch (IOException ignore) { + } + // OK, whoever tried to send data, should now agree that + // there is no point in further waiting =) + // It is safe now to acquire the semaphore. + } + synchronized (connectionSemaphore) { if (!connectionClosed) { - try { - tc.sendMessage(new PacketDisconnect( - PacketDisconnect.Reason.SSH_DISCONNECT_BY_APPLICATION, "").getPayload()); - } - catch (IOException ignore) { - // - } + if (useDisconnectPacket == true) { + try { + if (tc != null) + tc.sendMessage(new PacketDisconnect(PacketDisconnect.Reason.SSH_DISCONNECT_BY_APPLICATION, "").getPayload()); + } + catch (IOException ignore) { + } - try { - socket.close(); - } - catch (IOException ignore) { - // - } + try { + socket.close(); + } + catch (IOException ignore) { + } - connectionClosed = true; + connectionClosed = true; + reasonClosedCause = cause; synchronized (this) { for (ConnectionMonitor cmon : connectionMonitors) { - cmon.connectionLost(reasonClosedCause); + try { + cmon.connectionLost(reasonClosedCause); + } + catch (Exception ignore) { + } } } } @@ -194,29 +211,6 @@ } } - public void close(IOException cause) { - // Do not acquire the semaphore, perhaps somebody is inside (and waits until - // the remote side is ready to accept new data - try { - socket.close(); - } - catch (IOException ignore) { - } - - // It is safe now to acquire the semaphore. - synchronized (connectionSemaphore) { - connectionClosed = true; - reasonClosedCause = cause; - connectionSemaphore.notifyAll(); - } - - synchronized (this) { - for (ConnectionMonitor cmon : connectionMonitors) { - cmon.connectionLost(reasonClosedCause); - } - } - } - protected void startReceiver() throws IOException { final Thread receiveThread = new Thread(new Runnable() { public void run() {