Merge \\\"Changes for upgrade to OkHttp 2.7.5\\\" am: 5c3bebd673 am: 1f44659b2f
am: 6b473f7b67 Change-Id: I3a0dc1da2ee96d71c38cab727141efcb686627e1
This commit is contained in:
@@ -34,9 +34,13 @@ import java.net.SocketException;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
import com.android.okhttp.ConnectionPool;
|
import com.android.okhttp.ConnectionPool;
|
||||||
|
import com.android.okhttp.Dns;
|
||||||
import com.android.okhttp.HttpHandler;
|
import com.android.okhttp.HttpHandler;
|
||||||
import com.android.okhttp.HttpsHandler;
|
import com.android.okhttp.HttpsHandler;
|
||||||
import com.android.okhttp.OkHttpClient;
|
import com.android.okhttp.OkHttpClient;
|
||||||
@@ -62,10 +66,10 @@ public class Network implements Parcelable {
|
|||||||
// Objects used to perform per-network operations such as getSocketFactory
|
// Objects used to perform per-network operations such as getSocketFactory
|
||||||
// and openConnection, and a lock to protect access to them.
|
// and openConnection, and a lock to protect access to them.
|
||||||
private volatile NetworkBoundSocketFactory mNetworkBoundSocketFactory = null;
|
private volatile NetworkBoundSocketFactory mNetworkBoundSocketFactory = null;
|
||||||
// mLock should be used to control write access to mConnectionPool and mNetwork.
|
// mLock should be used to control write access to mConnectionPool and mDns.
|
||||||
// maybeInitHttpClient() must be called prior to reading either variable.
|
// maybeInitHttpClient() must be called prior to reading either variable.
|
||||||
private volatile ConnectionPool mConnectionPool = null;
|
private volatile ConnectionPool mConnectionPool = null;
|
||||||
private volatile com.android.okhttp.internal.Network mNetwork = null;
|
private volatile Dns mDns = null;
|
||||||
private final Object mLock = new Object();
|
private final Object mLock = new Object();
|
||||||
|
|
||||||
// Default connection pool values. These are evaluated at startup, just
|
// Default connection pool values. These are evaluated at startup, just
|
||||||
@@ -219,17 +223,17 @@ public class Network implements Parcelable {
|
|||||||
// out) ConnectionPools.
|
// out) ConnectionPools.
|
||||||
private void maybeInitHttpClient() {
|
private void maybeInitHttpClient() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mNetwork == null) {
|
if (mDns == null) {
|
||||||
mNetwork = new com.android.okhttp.internal.Network() {
|
mDns = new Dns() {
|
||||||
@Override
|
@Override
|
||||||
public InetAddress[] resolveInetAddresses(String host) throws UnknownHostException {
|
public List<InetAddress> lookup(String hostname) throws UnknownHostException {
|
||||||
return Network.this.getAllByName(host);
|
return Arrays.asList(Network.this.getAllByName(hostname));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (mConnectionPool == null) {
|
if (mConnectionPool == null) {
|
||||||
mConnectionPool = new ConnectionPool(httpMaxConnections,
|
mConnectionPool = new ConnectionPool(httpMaxConnections,
|
||||||
httpKeepAliveDurationMs);
|
httpKeepAliveDurationMs, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,9 +292,8 @@ public class Network implements Parcelable {
|
|||||||
}
|
}
|
||||||
OkHttpClient client = okUrlFactory.client();
|
OkHttpClient client = okUrlFactory.client();
|
||||||
client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);
|
client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);
|
||||||
|
// Let network traffic go via mDns
|
||||||
// Use internal APIs to change the Network.
|
client.setDns(mDns);
|
||||||
Internal.instance.setNetwork(client, mNetwork);
|
|
||||||
|
|
||||||
return okUrlFactory.open(url);
|
return okUrlFactory.open(url);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user