diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.h b/src/objective-c/GRPCClient/GRPCCall+Cronet.h index d623ed61a3800d7e5394c915285bfb4dfe535324..b7676d024530f0e2678112bd08be00033b9504f9 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.h +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.h @@ -39,9 +39,16 @@ */ @interface GRPCCall (Cronet) -+(void)useCronet:(cronet_engine *)cronet_engine; +/* This method should be called before issuing the first RPC. It should be + * called only once. Create an instance of Cronet engine in your app elsewhere + * and pass the instance pointer in the cronet_engine parameter. Once set, + * all subsequent RPCs will use Cronet transport. The method is not thread + * safe. + */ + ++(void)useCronetWithEngine:(cronet_engine *)engine; -+(void *)getCronetEngine; ++(cronet_engine *)cronetEngine; +(BOOL)isUsingCronet; diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.m b/src/objective-c/GRPCClient/GRPCCall+Cronet.m index 2409cd4645d4b96115e18346fd89753fb0903d2e..69a410e95ac84909b1996e79cf903a8a9422893b 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.m +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.m @@ -33,22 +33,22 @@ #import "GRPCCall+Cronet.h" -static BOOL use_cronet = NO; -static void *g_cronet_engine; +static BOOL useCronet = NO; +static cronet_engine *globalCronetEngine; @implementation GRPCCall (Cronet) -+ (void)useCronet:(cronet_engine *)cronet_engine { - use_cronet = YES; - g_cronet_engine = cronet_engine; ++ (void)useCronetWithEngine:(cronet_engine *)engine { + useCronet = YES; + globalCronetEngine = engine; } -+ (void *)getCronetEngine { - return g_cronet_engine; ++ (cronet_engine *)cronetEngine { + return globalCronetEngine; } + (BOOL)isUsingCronet { - return use_cronet; + return useCronet; } @end diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 412e8b01fbd0e2b055e92e2927932aebf996e9cf..e4e0dbe6d2c773f269f3614eb6608ec544d330ae 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -154,7 +154,7 @@ grpc_channel_args * buildChannelArgs(NSDictionary *dictionary) { + (GRPCChannel *)secureCronetChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)channelArgs { - void *engine = [GRPCCall getCronetEngine]; + cronet_engine *engine = [GRPCCall cronetEngine]; if (!engine) { [NSException raise:NSInvalidArgumentException format:@"cronet_engine is NULL. Set it first."]; diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index 06ed56d54629c26123778455666055d7b2267e8b..7da508810ce0bc4b55a7cfdd23367b06da0f1f13 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -201,14 +201,14 @@ NS_ASSUME_NONNULL_BEGIN - (GRPCChannel *)newChannel { NSDictionary *args = [self channelArgs]; - BOOL use_cronet = [GRPCCall isUsingCronet]; + BOOL useCronet = [GRPCCall isUsingCronet]; if (_secure) { GRPCChannel *channel; @synchronized(self) { if (_channelCreds == nil) { [self setTLSPEMRootCerts:nil withPrivateKey:nil withCertChain:nil error:nil]; } - if (use_cronet) { + if (useCronet) { channel = [GRPCChannel secureCronetChannelWithHost:_address channelArgs:args]; } else { diff --git a/src/objective-c/tests/InteropTests.m b/src/objective-c/tests/InteropTests.m index 361294d4acc6f1b57532deb412593e49c9bf2dd7..781c500f73e976fcb8f479803829e13f8a823dd6 100644 --- a/src/objective-c/tests/InteropTests.m +++ b/src/objective-c/tests/InteropTests.m @@ -80,7 +80,7 @@ #pragma mark Tests -static cronet_engine *_engine = NULL; +static cronet_engine *cronetEngine = NULL; @implementation InteropTests { RMTTestService *_service; @@ -93,12 +93,12 @@ static cronet_engine *_engine = NULL; - (void)setUp { _service = self.class.host ? [RMTTestService serviceWithHost:self.class.host] : nil; #ifdef GRPC_COMPILE_WITH_CRONET - if (_engine == NULL) { + if (cronetEngine == NULL) { + // Cronet setup [Cronet setHttp2Enabled:YES]; - [Cronet setSslKeyLogFileName:@"cronetkeylogfile.pem"]; [Cronet start]; - _engine = [Cronet getGlobalEngine]; - [GRPCCall useCronet:_engine]; + cronetEngine = [Cronet getGlobalEngine]; + [GRPCCall useCronetWithEngine:cronetEngine]; } #endif }