summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLUploadFileOperation.m
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-11-07 10:02:16 -0500
committerJoel Fischer <joeljfischer@gmail.com>2016-11-07 10:02:16 -0500
commitc071ff5e0c2de8ac7b3bd8a46a87516a48794568 (patch)
treea748c5f11263f1f505e56eba7470b5625bc1081f /SmartDeviceLink/SDLUploadFileOperation.m
parent02b8c3847ee3701b0326fe1ffed6f6ea01736077 (diff)
downloadsdl_ios-c071ff5e0c2de8ac7b3bd8a46a87516a48794568.tar.gz
Update uploading file operations to use built in cancel mechanismhotfix/issue_467
* Fixed a threading issue only affecting tests
Diffstat (limited to 'SmartDeviceLink/SDLUploadFileOperation.m')
-rw-r--r--SmartDeviceLink/SDLUploadFileOperation.m13
1 files changed, 4 insertions, 9 deletions
diff --git a/SmartDeviceLink/SDLUploadFileOperation.m b/SmartDeviceLink/SDLUploadFileOperation.m
index aa9474972..65910ab5f 100644
--- a/SmartDeviceLink/SDLUploadFileOperation.m
+++ b/SmartDeviceLink/SDLUploadFileOperation.m
@@ -56,7 +56,6 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)sdl_sendPutFiles:(NSArray<SDLPutFile *> *)putFiles withCompletion:(SDLFileManagerUploadCompletionHandler)completion {
- __block BOOL stop = NO;
__block NSError *streamError = nil;
__block NSUInteger bytesAvailable = 0;
__block NSInteger highestCorrelationIDReceived = -1;
@@ -67,7 +66,8 @@ NS_ASSUME_NONNULL_BEGIN
// When the putfiles all complete, run this block
__weak typeof(self) weakself = self;
dispatch_group_notify(putFileGroup, dispatch_get_main_queue(), ^{
- if (streamError != nil || stop) {
+ typeof(weakself) strongself = weakself;
+ if (streamError != nil || strongself.isCancelled) {
completion(NO, bytesAvailable, streamError);
} else {
completion(YES, bytesAvailable, nil);
@@ -82,20 +82,15 @@ NS_ASSUME_NONNULL_BEGIN
[self.connectionManager sendManagerRequest:putFile
withResponseHandler:^(__kindof SDLRPCRequest *_Nullable request, __kindof SDLRPCResponse *_Nullable response, NSError *_Nullable error) {
typeof(weakself) strongself = weakself;
- // If we've already encountered an error, then just abort
// TODO: Is this the right way to handle this case? Should we just abort everything in the future? Should we be deleting what we sent? Should we have an automatic retry strategy based on what the error was?
if (strongself.isCancelled) {
- stop = YES;
- }
-
- if (stop) {
dispatch_group_leave(putFileGroup);
BLOCK_RETURN;
}
// If we encounted an error, abort in the future and call the completion handler
- if (error != nil || response == nil || ![response.success boolValue]) {
- stop = YES;
+ if (error != nil || response == nil || ![response.success boolValue] || strongself.isCancelled) {
+ [strongself cancel];
streamError = error;
dispatch_group_leave(putFileGroup);