diff options
author | Christian Schneppe <christian@pix-art.de> | 2017-06-17 14:26:47 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2017-06-17 14:26:47 +0200 |
commit | 3eeeee523b5f3959b23349acd2f39028f6a498fa (patch) | |
tree | 1697986efa78a9b03864ec5f76af88fbaa7f1b64 /src/main/java | |
parent | 09a284ea4fb1ee6171db2f7c91940a3ffe67355a (diff) |
make http upload read timeout depend on file size
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/http/HttpUploadConnection.java | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java index 1488b3366..984e4dbcd 100644 --- a/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java +++ b/src/main/java/de/pixart/messenger/http/HttpUploadConnection.java @@ -162,7 +162,9 @@ public class HttpUploadConnection implements Transferable { PowerManager.WakeLock wakeLock = mHttpConnectionManager.createWakeLock("http_upload_" + message.getUuid()); try { wakeLock.acquire(); - Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString()); + final int expectedFileSize = (int) file.getExpectedSize(); + final int readTimeout = Math.max(Config.SOCKET_TIMEOUT, expectedFileSize / 2048); //assuming a minimum transfer speed of 16kbit/s + Log.d(Config.LOGTAG, "uploading to " + mPutUrl.toString() + " w/ read timeout of " + readTimeout + "s"); if (mUseTor) { connection = (HttpURLConnection) mPutUrl.openConnection(mHttpConnectionManager.getProxy()); } else { @@ -172,12 +174,12 @@ public class HttpUploadConnection implements Transferable { mHttpConnectionManager.setupTrustManager((HttpsURLConnection) connection, true); } connection.setRequestMethod("PUT"); - connection.setFixedLengthStreamingMode((int) file.getExpectedSize()); + connection.setFixedLengthStreamingMode(expectedFileSize); connection.setRequestProperty("Content-Type", mime == null ? "application/octet-stream" : mime); connection.setRequestProperty("User-Agent", mXmppConnectionService.getIqGenerator().getIdentityName()); connection.setDoOutput(true); connection.setConnectTimeout(Config.SOCKET_TIMEOUT * 1000); - connection.setReadTimeout(Config.CONNECT_TIMEOUT * 1000); + connection.setReadTimeout(readTimeout * 1000); connection.connect(); os = connection.getOutputStream(); transmitted = 0; |