From d11e4f8a85a3cde402c86e73c8bef0714b4c6248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=8C?= Date: Thu, 21 Jan 2016 01:00:32 +0800 Subject: [PATCH 1/2] 7.0 retry 2 --- .../qiniu/android/storage/ResumeUploader.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java index 59048e144..da57d5585 100644 --- a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java +++ b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java @@ -209,7 +209,7 @@ public void complete(ResponseInfo info, JSONObject response) { return; } - if (isNotQiniu(info) || (info.needRetry() && retried < config.retryMax)) { + if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; } @@ -241,22 +241,22 @@ public void complete(ResponseInfo info, JSONObject response) { completionHandler.complete(key, i, null); return; } - if (info.statusCode == 701) { - nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried, address); + if (info.statusCode == 701 && retried < config.retryMax) { + nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried + 1, address); return; } - if (!isNotQiniu(info) && (retried >= config.retryMax || !info.needRetry())) { - completionHandler.complete(key, info, null); + if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) { + nextTask(offset, retried + 1, config.upBackup.address); return; } - nextTask(offset, retried + 1, config.upBackup.address); + completionHandler.complete(key, info, null); return; } String context = null; - if (response == null) { + if (response == null && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; } @@ -267,7 +267,7 @@ public void complete(ResponseInfo info, JSONObject response) { } catch (JSONException e) { e.printStackTrace(); } - if (context == null || crc != ResumeUploader.this.crc32) { + if ((context == null || crc != ResumeUploader.this.crc32) && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; } From 551200ab5e829a956ca37801545207fefb0af368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=8C?= Date: Thu, 21 Jan 2016 10:49:10 +0800 Subject: [PATCH 2/2] is cancelled --- .../qiniu/android/storage/ResumeUploader.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java index da57d5585..7f0150380 100644 --- a/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java +++ b/library/src/main/java/com/qiniu/android/storage/ResumeUploader.java @@ -192,6 +192,12 @@ private boolean isCancelled() { } private void nextTask(final int offset, final int retried, final URI address) { + if (isCancelled()) { + ResponseInfo i = ResponseInfo.cancelled(); + completionHandler.complete(key, i, null); + return; + } + if (offset == size) { CompletionHandler complete = new CompletionHandler() { @Override @@ -203,12 +209,6 @@ public void complete(ResponseInfo info, JSONObject response) { return; } - if (isCancelled()) { - ResponseInfo i = ResponseInfo.cancelled(); - completionHandler.complete(key, i, null); - return; - } - if ((isNotQiniu(info) || info.needRetry()) && retried < config.retryMax) { nextTask(offset, retried + 1, config.upBackup.address); return; @@ -236,11 +236,6 @@ public void onProgress(int bytesWritten, int totalSize) { @Override public void complete(ResponseInfo info, JSONObject response) { if (!info.isOK()) { - if (isCancelled()) { - ResponseInfo i = ResponseInfo.cancelled(); - completionHandler.complete(key, i, null); - return; - } if (info.statusCode == 701 && retried < config.retryMax) { nextTask((offset / Configuration.BLOCK_SIZE) * Configuration.BLOCK_SIZE, retried + 1, address); return; @@ -251,7 +246,7 @@ public void complete(ResponseInfo info, JSONObject response) { return; } - completionHandler.complete(key, info, null); + completionHandler.complete(key, info, response); return; } String context = null;