Timeout and backoff

pull/15838/head
Muxi Yan 7 years ago
parent b13eda3cb4
commit c635e41c22
  1. 10
      src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
  2. 10
      src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
  3. 4
      src/objective-c/GRPCClient/private/GRPCHost.h
  4. 10
      src/objective-c/GRPCClient/private/GRPCHost.m

@ -60,4 +60,14 @@ typedef NS_ENUM(NSInteger, GRPCCompressAlgorithm) {
* immediately returned to the application layer. */
+ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host;
/** Set channel connection timeout and backoff parameters. All parameters are positive integers in
* milliseconds. Set a parameter to 0 to make gRPC use default value for that parameter.
*
* Refer to gRPC's doc at https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md for the
* details of each parameter. */
+ (void)setMinConnectTimeout:(unsigned int)timeout
initialBackoff:(unsigned int)initialBackoff
maxBackoff:(unsigned int)maxBackoff
forHost:(nonnull NSString *)host;
@end

@ -69,4 +69,14 @@
hostConfig.retryEnabled = enabled;
}
+ (void)setMinConnectTimeout:(unsigned int)timeout
initialBackoff:(unsigned int)initialBackoff
maxBackoff:(unsigned int)maxBackoff
forHost:(nonnull NSString *)host {
GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
hostConfig.minConnectTimeout = timeout;
hostConfig.initialConnectBackoff = initialBackoff;
hostConfig.maxConnectBackoff = maxBackoff;
}
@end

@ -40,6 +40,10 @@ struct grpc_channel_credentials;
@property(nonatomic) id logContext;
@property(nonatomic) BOOL retryEnabled;
@property(nonatomic) unsigned int minConnectTimeout;
@property(nonatomic) unsigned int initialConnectBackoff;
@property(nonatomic) unsigned int maxConnectBackoff;
/** The following properties should only be modified for testing: */
@property(nonatomic, getter=isSecure) BOOL secure;

@ -245,6 +245,16 @@ static NSMutableDictionary *kHostCache;
args[@GRPC_ARG_ENABLE_RETRIES] = [NSNumber numberWithInt:0];
}
if (_minConnectTimeout > 0) {
args[@GRPC_ARG_MIN_RECONNECT_BACKOFF_MS] = [NSNumber numberWithInt:_minConnectTimeout];
}
if (_initialConnectBackoff > 0) {
args[@GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS] = [NSNumber numberWithInt:_initialConnectBackoff];
}
if (_maxConnectBackoff > 0) {
args[@GRPC_ARG_MAX_RECONNECT_BACKOFF_MS] = [NSNumber numberWithInt:_maxConnectBackoff];
}
return args;
}

Loading…
Cancel
Save