Flush host when network connectivity changes
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 4320434..bbfb5aa 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -375,20 +375,6 @@
_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.
NSString *host = [NSURL URLWithString:[@"https://" stringByAppendingString:_host]].host;
if (!host) {
@@ -397,15 +383,35 @@
}
__weak typeof(self) weakSelf = self;
_connectivityMonitor = [GRPCConnectivityMonitor monitorWithHost:host];
- [_connectivityMonitor handleLossWithHandler:^{
+ void (^handler)() = ^{
typeof(self) strongSelf = weakSelf;
if (strongSelf) {
[strongSelf finishWithError:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeUnavailable
userInfo:@{NSLocalizedDescriptionKey: @"Connectivity lost."}]];
- [[GRPCHost hostWithAddress:strongSelf->_host] disconnect];
}
- }];
+ };
+ [_connectivityMonitor handleLossWithHandler:handler
+ wifiStatusChangeHandler:handler];
+
+ // 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 {