summaryrefslogtreecommitdiffstats
path: root/src/org/apache
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2010-03-09 07:50:51 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-03-09 07:50:51 -0800
commit335d1d4d38ed77fd20bf2bd2a25e1293f994cc25 (patch)
tree268799d5981940e9d8f0db30f4e90718d9069bfb /src/org/apache
parent3f73cec644d5033a20c5ae38c4c8f255639b6a47 (diff)
parent6c446082cd6a8b9ff2b94870f5022f5dfdc11693 (diff)
downloadexternal_apache-http-335d1d4d38ed77fd20bf2bd2a25e1293f994cc25.zip
external_apache-http-335d1d4d38ed77fd20bf2bd2a25e1293f994cc25.tar.gz
external_apache-http-335d1d4d38ed77fd20bf2bd2a25e1293f994cc25.tar.bz2
Merge "Implement proper multihoming support, second attempt."
Diffstat (limited to 'src/org/apache')
-rw-r--r--src/org/apache/http/conn/scheme/PlainSocketFactory.java10
-rw-r--r--src/org/apache/http/impl/conn/DefaultClientConnectionOperator.java56
2 files changed, 54 insertions, 12 deletions
diff --git a/src/org/apache/http/conn/scheme/PlainSocketFactory.java b/src/org/apache/http/conn/scheme/PlainSocketFactory.java
index acc13f7..b15df44 100644
--- a/src/org/apache/http/conn/scheme/PlainSocketFactory.java
+++ b/src/org/apache/http/conn/scheme/PlainSocketFactory.java
@@ -35,7 +35,9 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.SocketTimeoutException;
+import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@@ -113,9 +115,11 @@ public final class PlainSocketFactory implements SocketFactory {
} else {
remoteAddress = new InetSocketAddress(host, port);
}
-
- sock.connect(remoteAddress, timeout);
-
+ try {
+ sock.connect(remoteAddress, timeout);
+ } catch (SocketTimeoutException ex) {
+ throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
+ }
return sock;
} // connectSocket
diff --git a/src/org/apache/http/impl/conn/DefaultClientConnectionOperator.java b/src/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
index 41488e1..854b2b0 100644
--- a/src/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
+++ b/src/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
@@ -44,7 +44,9 @@ import org.apache.http.protocol.HttpContext;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.ClientConnectionOperator;
+import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.scheme.LayeredSocketFactory;
+import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SocketFactory;
@@ -67,6 +69,7 @@ import org.apache.http.conn.scheme.SocketFactory;
public class DefaultClientConnectionOperator
implements ClientConnectionOperator {
+ private static final PlainSocketFactory staticPlainSocketFactory = new PlainSocketFactory();
/** The scheme registry for looking up socket factories. */
protected SchemeRegistry schemeRegistry;
@@ -121,19 +124,55 @@ public class DefaultClientConnectionOperator
final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
final SocketFactory sf = schm.getSocketFactory();
+ final SocketFactory plain_sf;
+ final LayeredSocketFactory layered_sf;
+ if (sf instanceof LayeredSocketFactory) {
+ plain_sf = staticPlainSocketFactory;
+ layered_sf = (LayeredSocketFactory)sf;
+ } else {
+ plain_sf = sf;
+ layered_sf = null;
+ }
+ InetAddress[] addresses = InetAddress.getAllByName(target.getHostName());
- Socket sock = sf.createSocket();
- conn.opening(sock, target);
+ for (int i = 0; i < addresses.length; ++i) {
+ Socket sock = plain_sf.createSocket();
+ conn.opening(sock, target);
- try {
- sock = sf.connectSocket(sock, target.getHostName(),
+ try {
+ Socket connsock = plain_sf.connectSocket(sock,
+ addresses[i].getHostAddress(),
schm.resolvePort(target.getPort()),
local, 0, params);
- } catch (ConnectException ex) {
- throw new HttpHostConnectException(target, ex);
+ if (sock != connsock) {
+ sock = connsock;
+ conn.opening(sock, target);
+ }
+ if (layered_sf != null) {
+ Socket layeredsock = layered_sf.createSocket(sock,
+ target.getHostName(),
+ schm.resolvePort(target.getPort()),
+ true);
+ if (layeredsock != sock) {
+ conn.opening(layeredsock, target);
+ }
+ prepareSocket(layeredsock, context, params);
+ conn.openCompleted(sf.isSecure(layeredsock), params);
+ } else {
+ prepareSocket(sock, context, params);
+ conn.openCompleted(sf.isSecure(sock), params);
+ }
+ break;
+ } catch (ConnectException ex) {
+ if (i == addresses.length - 1) {
+ throw new HttpHostConnectException(target, ex);
+ }
+ } catch (ConnectTimeoutException ex) {
+ if (i == addresses.length - 1) {
+ throw ex;
+ }
+ }
}
- prepareSocket(sock, context, params);
- conn.openCompleted(sf.isSecure(sock), params);
} // openConnection
@@ -213,4 +252,3 @@ public class DefaultClientConnectionOperator
} // class DefaultClientConnectionOperator
-