Skip to content
Snippets Groups Projects
Commit 4f6a19b2 authored by Muxi Yan's avatar Muxi Yan
Browse files

Create connectivityMonitor after call is set up

parent 7f773102
No related branches found
No related tags found
No related merge requests found
...@@ -409,9 +409,26 @@ static NSMutableDictionary *callFlags; ...@@ -409,9 +409,26 @@ static NSMutableDictionary *callFlags;
_state = GRXWriterStateStarted; _state = GRXWriterStateStarted;
} }
// Create a retain cycle so that this instance lives until the RPC finishes
// (or is cancelled). This makes RPCs in which the call isn't externally
// retained possible (as long as it is started before being autoreleased).
// Care is taken not to retain self strongly in any of the blocks used in this
// implementation, so that the life of the instance is determined by this
// retain cycle.
_retainSelf = self;
_responseWriteable =
[[GRXConcurrentWriteable alloc] initWithWriteable:writeable];
_wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host path:_path];
NSAssert(_wrappedCall, @"Error allocating RPC objects. Low memory?");
[self sendHeaders:_requestHeaders];
[self invokeCall];
// TODO(jcanizales): Extract this logic somewhere common. // TODO(jcanizales): Extract this logic somewhere common.
NSString *host = NSString *host =
[NSURL URLWithString:[@"https://" stringByAppendingString:_host]].host; [NSURL URLWithString:[@"https://" stringByAppendingString:_host]].host;
if (!host) { if (!host) {
// TODO(jcanizales): Check this on init. // TODO(jcanizales): Check this on init.
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
...@@ -423,34 +440,17 @@ static NSMutableDictionary *callFlags; ...@@ -423,34 +440,17 @@ static NSMutableDictionary *callFlags;
typeof(self) strongSelf = weakSelf; typeof(self) strongSelf = weakSelf;
if (strongSelf) { if (strongSelf) {
[strongSelf [strongSelf
finishWithError:[NSError errorWithDomain:kGRPCErrorDomain finishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable code:GRPCErrorCodeUnavailable
userInfo:@{ userInfo:@{
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Connectivity lost." @"Connectivity lost."
}]]; }]];
} }
}; };
[_connectivityMonitor handleLossWithHandler:handler [_connectivityMonitor handleLossWithHandler:handler
wifiStatusChangeHandler:^{ wifiStatusChangeHandler:^{
}]; }];
// Create a retain cycle so that this instance lives until the RPC finishes
// (or is cancelled). This makes RPCs in which the call isn't externally
// retained possible (as long as it is started before being autoreleased).
// Care is taken not to retain self strongly in any of the blocks used in this
// implementation, so that the life of the instance is determined by this
// retain cycle.
_retainSelf = self;
_responseWriteable =
[[GRXConcurrentWriteable alloc] initWithWriteable:writeable];
_wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host path:_path];
NSAssert(_wrappedCall, @"Error allocating RPC objects. Low memory?");
[self sendHeaders:_requestHeaders];
[self invokeCall];
} }
- (void)setState:(GRXWriterState)newState { - (void)setState:(GRXWriterState)newState {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment