Skip to content

Commit

Permalink
block retry
Browse files Browse the repository at this point in the history
  • Loading branch information
lintianzhi committed Feb 26, 2014
1 parent 8f0091f commit 4b17877
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions QiniuSDK/QiniuResumableUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,37 @@ - (void) uploadFile:(NSString *)filePath

for (int blockIndex=0; blockIndex<blockCount; blockIndex++) {

UInt32 offbase = blockIndex << QiniuBlockBits;
__block UInt32 blockSize1;
__block NSFileHandle *fileHandle;
__block UInt32 retryTime = client.retryTime;

QNCompleteBlock __block blockComplete = ^(AFHTTPRequestOperation *operation, NSError *error)
{
if (error != Nil) {
[self.delegate uploadFailed:filePath error:error];

/****
// for retry test
if (retryTime == client.retryTime) {
error = @"errxxx";
}
****/

if (error != nil) {
if (retryTime > 0) {
retryTime --;
[fileHandle seekToFileOffset:offbase];

[client blockPut:fileHandle
blockIndex:blockIndex
blockSize:blockSize1
extra:extra
progress:^(float percent) {
[self.delegate uploadProgressUpdated:filePath percent:percent];
}
complete:blockComplete];
} else {
[self.delegate uploadFailed:filePath error:error];
}
return;
}

Expand Down Expand Up @@ -99,14 +126,14 @@ - (void) uploadFile:(NSString *)filePath
continue;
}

UInt32 blockSize1 = blockSize;
UInt32 offbase = blockIndex << QiniuBlockBits;
blockSize1 = blockSize;
if (blockIndex == blockCount - 1) {
blockSize1 = fileSize - offbase;
}

NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath];
[fileHandle seekToFileOffset:offbase];

[client blockPut:fileHandle
blockIndex:blockIndex
blockSize:blockSize1
Expand Down

0 comments on commit 4b17877

Please sign in to comment.