Skip to content

Commit d39fd5a

Browse files
author
Henrik Baard
committed
Changing connect and response timeout.
In bad network conditions and where switches often occur between 2G and 3G the timeout of 20s is too short. Setting this timeout to 60 seconds will improve functionality in bad conditions while it will not affect functionality in good networks. This change also aligns the timeouts with the timeouts used by the Browser (Connection.java). Change-Id: I0fbe3cbfe734f8d55a41bfa5d8ab6b332a19f912
1 parent bf1439c commit d39fd5a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

core/java/android/net/http/AndroidHttpClient.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public final class AndroidHttpClient implements HttpClient {
7979
// Gzip of data shorter than this probably won't be worthwhile
8080
public static long DEFAULT_SYNC_MIN_GZIP_BYTES = 256;
8181

82+
// Default connection and socket timeout of 60 seconds. Tweak to taste.
83+
private static final int SOCKET_OPERATION_TIMEOUT = 60 * 1000;
84+
8285
private static final String TAG = "AndroidHttpClient";
8386

8487

@@ -107,9 +110,8 @@ public static AndroidHttpClient newInstance(String userAgent, Context context) {
107110
// and it's not worth it to pay the penalty of checking every time.
108111
HttpConnectionParams.setStaleCheckingEnabled(params, false);
109112

110-
// Default connection and socket timeout of 20 seconds. Tweak to taste.
111-
HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
112-
HttpConnectionParams.setSoTimeout(params, 20 * 1000);
113+
HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
114+
HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);
113115
HttpConnectionParams.setSocketBufferSize(params, 8192);
114116

115117
// Don't handle redirects -- return them to the caller. Our code
@@ -125,7 +127,8 @@ public static AndroidHttpClient newInstance(String userAgent, Context context) {
125127
schemeRegistry.register(new Scheme("http",
126128
PlainSocketFactory.getSocketFactory(), 80));
127129
schemeRegistry.register(new Scheme("https",
128-
SSLCertificateSocketFactory.getHttpSocketFactory(30 * 1000, sessionCache), 443));
130+
SSLCertificateSocketFactory.getHttpSocketFactory(
131+
SOCKET_OPERATION_TIMEOUT, sessionCache), 443));
129132

130133
ClientConnectionManager manager =
131134
new ThreadSafeClientConnManager(params, schemeRegistry);

0 commit comments

Comments
 (0)