change transport layer to use millisecond timeouts

This commit is contained in:
shikhar
2013-03-24 17:36:11 -04:00
parent 6656214803
commit 88a88c5dba
4 changed files with 13 additions and 13 deletions

View File

@@ -63,7 +63,7 @@ public class ConnectionImpl
*/ */
public ConnectionImpl(Transport trans) { public ConnectionImpl(Transport trans) {
super("ssh-connection", trans); super("ssh-connection", trans);
timeoutMs = trans.getTimeout() * 1000; timeoutMs = trans.getTimeoutMs();
} }
@Override @Override

View File

@@ -155,7 +155,7 @@ final class KeyExchanger
* @param waitForDone whether should block till key exchange completed * @param waitForDone whether should block till key exchange completed
* *
* @throws TransportException if there is an error during key exchange * @throws TransportException if there is an error during key exchange
* @see {@link Transport#setTimeout} for setting timeout for kex * @see {@link Transport#setTimeoutMs} for setting timeout for kex
*/ */
void startKex(boolean waitForDone) void startKex(boolean waitForDone)
throws TransportException { throws TransportException {
@@ -169,7 +169,7 @@ final class KeyExchanger
void waitForDone() void waitForDone()
throws TransportException { throws TransportException {
done.await(transport.getTimeout(), TimeUnit.SECONDS); done.await(transport.getTimeoutMs(), TimeUnit.MILLISECONDS);
} }
private synchronized void ensureKexOngoing() private synchronized void ensureKexOngoing()
@@ -360,7 +360,7 @@ final class KeyExchanger
* We block on this event to prevent a race condition where we may have received a SSH_MSG_KEXINIT before * We block on this event to prevent a race condition where we may have received a SSH_MSG_KEXINIT before
* having sent the packet ourselves (would cause gotKexInit() to fail) * having sent the packet ourselves (would cause gotKexInit() to fail)
*/ */
kexInitSent.await(transport.getTimeout(), TimeUnit.SECONDS); kexInitSent.await(transport.getTimeoutMs(), TimeUnit.MILLISECONDS);
gotKexInit(buf); gotKexInit(buf);
expected = Expected.FOLLOWUP; expected = Expected.FOLLOWUP;
break; break;

View File

@@ -86,14 +86,14 @@ public interface Transport
Config getConfig(); Config getConfig();
/** @return the timeout that is currently set for blocking operations. */ /** @return the timeout that is currently set for blocking operations. */
int getTimeout(); int getTimeoutMs();
/** /**
* Set a timeout for methods that may block. * Set a timeout for methods that may block.
* *
* @param timeout the timeout in seconds * @param timeout the timeout in milliseconds
*/ */
void setTimeout(int timeout); void setTimeoutMs(int timeout);
/** @return the interval in seconds at which a heartbeat message is sent to the server */ /** @return the interval in seconds at which a heartbeat message is sent to the server */
int getHeartbeatInterval(); int getHeartbeatInterval();

View File

@@ -113,7 +113,7 @@ public final class TransportImpl
/** Client version identification string */ /** Client version identification string */
private final String clientID; private final String clientID;
private volatile int timeout = 30; private volatile int timeoutMs = 30 * 1000; // Crazy long, but it was the original default
private volatile boolean authed = false; private volatile boolean authed = false;
@@ -241,13 +241,13 @@ public final class TransportImpl
} }
@Override @Override
public int getTimeout() { public int getTimeoutMs() {
return timeout; return timeoutMs;
} }
@Override @Override
public void setTimeout(int timeout) { public void setTimeoutMs(int timeoutMs) {
this.timeout = timeout; this.timeoutMs = timeoutMs;
} }
@Override @Override
@@ -311,7 +311,7 @@ public final class TransportImpl
try { try {
serviceAccept.clear(); serviceAccept.clear();
sendServiceRequest(service.getName()); sendServiceRequest(service.getName());
serviceAccept.await(timeout, TimeUnit.SECONDS); serviceAccept.await(timeoutMs, TimeUnit.MILLISECONDS);
setService(service); setService(service);
} finally { } finally {
serviceAccept.unlock(); serviceAccept.unlock();