aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-06-19 13:44:57 -0700
committerGravatar Muxi Yan <mxyan@google.com>2018-06-19 13:49:44 -0700
commitc635e41c22fb939f781837b9705b8642c13af9ae (patch)
tree9aa06ff9af72b3e5044d272c843830cf0f33982c
parentb13eda3cb49bcbf5cb8926aef419acc1fffdb98f (diff)
Timeout and backoff
-rw-r--r--src/objective-c/GRPCClient/GRPCCall+ChannelArg.h10
-rw-r--r--src/objective-c/GRPCClient/GRPCCall+ChannelArg.m10
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.h4
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m10
4 files changed, 34 insertions, 0 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
index 0b6855f6a4..803f19dedf 100644
--- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
+++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h
@@ -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
diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
index 78bf3fd79f..0e631fb3ad 100644
--- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
+++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m
@@ -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
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h
index 9a5293d90b..291b07df37 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.h
+++ b/src/objective-c/GRPCClient/private/GRPCHost.h
@@ -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;
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 13c2baada5..2e9f9f243b 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -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;
}