summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2010-02-10 14:32:15 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-02-10 14:32:15 -0800
commitc9bea4c100b0b5bc2b896c4d3c647aff2aba652e (patch)
treee55b31aeee8c045d0e634bf7a9e71bcfa1f7c6ab
parentc6c22fb5363f7ee1fe799c92f93d4e47d05fdebc (diff)
parent9d48f97ae59510bac2b91dac2cc22d519cbf1bc7 (diff)
downloadlibcore-c9bea4c100b0b5bc2b896c4d3c647aff2aba652e.zip
libcore-c9bea4c100b0b5bc2b896c4d3c647aff2aba652e.tar.gz
libcore-c9bea4c100b0b5bc2b896c4d3c647aff2aba652e.tar.bz2
Merge "Add a setHandshakeTimeout() to OpenSSLSocketImpl, which sets a read timeout that only applies to the SSL handshake step."
-rw-r--r--x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
index d287bbd..8006757 100644
--- a/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
+++ b/x-net/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
@@ -68,6 +68,9 @@ public class OpenSSLSocketImpl extends javax.net.ssl.SSLSocket {
private ArrayList<HandshakeCompletedListener> listeners;
private long ssl_op_no = 0x00000000L;
private int timeout = 0;
+ // BEGIN android-added
+ private int handshakeTimeout = -1; // -1 = same as timeout; 0 = infinite
+ // END android-added
private InetSocketAddress address;
private static final String[] supportedProtocols = new String[] {
@@ -298,6 +301,14 @@ public class OpenSSLSocketImpl extends javax.net.ssl.SSLSocket {
if (session == null && !sslParameters.getEnableSessionCreation()) {
throw new SSLHandshakeException("SSL Session may not be created");
} else {
+ // BEGIN android-added
+ // Temporarily use a different timeout for the handshake process
+ int savedTimeout = timeout;
+ if (handshakeTimeout >= 0) {
+ setSoTimeout(handshakeTimeout);
+ }
+ // END android-added
+
Socket socket = this.socket != null ? this.socket : this;
int sessionId = session != null ? session.session : 0;
boolean reusedSession;
@@ -360,6 +371,13 @@ public class OpenSSLSocketImpl extends javax.net.ssl.SSLSocket {
throw new SSLException("Not trusted server certificate", e);
}
}
+
+ // BEGIN android-added
+ // Restore the original timeout now that the handshake is complete
+ if (handshakeTimeout >= 0) {
+ setSoTimeout(savedTimeout);
+ }
+ // END android-added
}
if (listeners != null) {
@@ -882,6 +900,18 @@ public class OpenSSLSocketImpl extends javax.net.ssl.SSLSocket {
this.timeout = timeout;
}
+ // BEGIN android-added
+ /**
+ * Set the handshake timeout on this socket. This timeout is specified in
+ * milliseconds and will be used only during the handshake process.
+ *
+ * @param timeout the handshake timeout value
+ */
+ public synchronized void setHandshakeTimeout(int timeout) throws SocketException {
+ this.handshakeTimeout = timeout;
+ }
+ // END android-added
+
private native void nativeinterrupt() throws IOException;
private native void nativeclose() throws IOException;