Skip to content

Commit

Permalink
Add retry delay (XPC)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Sep 1, 2016
1 parent 321b070 commit ec921f4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ DerivedData
.idea/
*.hmap
*.xccheckout
*.xcscmblueprint

#CocoaPods
Pods

Cartfile.resolved
Carthage

2 changes: 1 addition & 1 deletion MPMessagePack.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MPMessagePack"
s.version = "1.3.9"
s.version = "1.3.10"
s.summary = "Library for MessagePack"
s.homepage = "https://github.com/gabriel/MPMessagePack"
s.license = { :type => "MIT" }
Expand Down
2 changes: 1 addition & 1 deletion XPC/MPXPCClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

- (void)sendRequest:(NSString *)method params:(NSArray *)params completion:(void (^)(NSError *error, id value))completion;

- (void)sendRequest:(NSString *)method params:(NSArray *)params maxAttempts:(NSInteger)maxAttempts completion:(void (^)(NSError *error, id value))completion;
- (void)sendRequest:(NSString *)method params:(NSArray *)params maxAttempts:(NSInteger)maxAttempts retryDelay:(NSTimeInterval)retryDelay completion:(void (^)(NSError *error, id value))completion;

- (void)close;

Expand Down
12 changes: 7 additions & 5 deletions XPC/MPXPCClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ - (void)close {
}

- (void)sendRequest:(NSString *)method params:(NSArray *)params completion:(void (^)(NSError *error, id value))completion {
[self sendRequest:method params:params attempt:1 maxAttempts:2 completion:completion];
[self sendRequest:method params:params attempt:1 maxAttempts:2 retryDelay:0 completion:completion];
}

- (void)sendRequest:(NSString *)method params:(NSArray *)params maxAttempts:(NSInteger)maxAttempts completion:(void (^)(NSError *error, id value))completion {
[self sendRequest:method params:params attempt:1 maxAttempts:maxAttempts completion:completion];
- (void)sendRequest:(NSString *)method params:(NSArray *)params maxAttempts:(NSInteger)maxAttempts retryDelay:(NSTimeInterval)retryDelay completion:(void (^)(NSError *error, id value))completion {
[self sendRequest:method params:params attempt:1 maxAttempts:maxAttempts retryDelay:retryDelay completion:completion];
}

- (void)sendRequest:(NSString *)method params:(NSArray *)params attempt:(NSInteger)attempt maxAttempts:(NSInteger)maxAttempts completion:(void (^)(NSError *error, id value))completion {
- (void)sendRequest:(NSString *)method params:(NSArray *)params attempt:(NSInteger)attempt maxAttempts:(NSInteger)maxAttempts retryDelay:(NSTimeInterval)retryDelay completion:(void (^)(NSError *error, id value))completion {
if (!_connection) {
NSError *error = nil;
if (![self connect:&error]) {
Expand Down Expand Up @@ -127,7 +127,9 @@ - (void)sendRequest:(NSString *)method params:(NSArray *)params attempt:(NSInteg
NSString *errorMessage = [NSString stringWithCString:description encoding:NSUTF8StringEncoding];
completion(MPMakeError(MPXPCErrorCodeInvalidConnection, @"XPC Error: %@", errorMessage), nil);
} else {
[self sendRequest:method params:params attempt:attempt+1 maxAttempts:maxAttempts completion:completion];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, retryDelay * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self sendRequest:method params:params attempt:attempt+1 maxAttempts:maxAttempts retryDelay:retryDelay completion:completion];
});
}
} else if (xpc_get_type(event) == XPC_TYPE_DICTIONARY) {
replied = YES;
Expand Down

0 comments on commit ec921f4

Please sign in to comment.