Comment and rename GRPCChannel:ref and :unref

pull/16190/head
Muxi Yan 6 years ago
parent 8cecb2a86d
commit b3cb4e17f7
  1. 14
      src/objective-c/GRPCClient/private/GRPCChannel.h
  2. 4
      src/objective-c/GRPCClient/private/GRPCChannel.m
  3. 2
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  4. 2
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  5. 2
      src/objective-c/tests/ChannelTests/ChannelPoolTest.m

@ -51,10 +51,20 @@ struct grpc_channel_credentials;
completionQueue:(nonnull GRPCCompletionQueue *)queue completionQueue:(nonnull GRPCCompletionQueue *)queue
callOptions:(nonnull GRPCCallOptions *)callOptions; callOptions:(nonnull GRPCCallOptions *)callOptions;
- (void)unmanagedCallRef; /**
* Increase the refcount of the channel. If the channel was timed to be destroyed, cancel the timer.
*/
- (void)ref;
- (void)unmanagedCallUnref; /**
* Decrease the refcount of the channel. If the refcount of the channel decrease to 0, start a timer
* to destroy the channel
*/
- (void)unref;
/**
* Force the channel to be disconnected and destroyed immediately.
*/
- (void)disconnect; - (void)disconnect;
// TODO (mxyan): deprecate with GRPCCall:closeOpenConnections // TODO (mxyan): deprecate with GRPCCall:closeOpenConnections

@ -180,7 +180,7 @@ NSTimeInterval kChannelDestroyDelay = 30;
return call; return call;
} }
- (void)unmanagedCallRef { - (void)ref {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (self->_unmanagedChannel) { if (self->_unmanagedChannel) {
[self->_channelRef refChannel]; [self->_channelRef refChannel];
@ -188,7 +188,7 @@ NSTimeInterval kChannelDestroyDelay = 30;
}); });
} }
- (void)unmanagedCallUnref { - (void)unref {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
if (self->_unmanagedChannel) { if (self->_unmanagedChannel) {
[self->_channelRef unrefChannel]; [self->_channelRef unrefChannel];

@ -191,7 +191,7 @@ extern const char *kCFStreamVarName;
@synchronized(self) { @synchronized(self) {
if ([_channelPool objectForKey:configuration]) { if ([_channelPool objectForKey:configuration]) {
channel = _channelPool[configuration]; channel = _channelPool[configuration];
[channel unmanagedCallRef]; [channel ref];
} else { } else {
channel = [GRPCChannel createChannelWithConfiguration:configuration]; channel = [GRPCChannel createChannelWithConfiguration:configuration];
if (channel != nil) { if (channel != nil) {

@ -311,7 +311,7 @@
- (void)dealloc { - (void)dealloc {
grpc_call_unref(_call); grpc_call_unref(_call);
[_channel unmanagedCallUnref]; [_channel unref];
_channel = nil; _channel = nil;
} }

@ -74,7 +74,7 @@ extern NSTimeInterval kChannelDestroyDelay;
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options1]; [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options1];
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init]; GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 = [pool channelWithConfiguration:config1]; GRPCChannel *channel1 = [pool channelWithConfiguration:config1];
[channel1 unmanagedCallUnref]; [channel1 unref];
sleep(1); sleep(1);
GRPCChannel *channel2 = [pool channelWithConfiguration:config1]; GRPCChannel *channel2 = [pool channelWithConfiguration:config1];
XCTAssertEqual(channel1, channel2); XCTAssertEqual(channel1, channel2);

Loading…
Cancel
Save