remove channel from pool with pointer rather than config

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

@ -204,7 +204,7 @@ NSTimeInterval kChannelDestroyDelay = 30;
if (self->_unmanagedChannel) {
grpc_channel_destroy(self->_unmanagedChannel);
self->_unmanagedChannel = nil;
[gChannelPool removeChannelWithConfiguration:self->_configuration];
[gChannelPool removeChannel:self];
}
});
}

@ -55,8 +55,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (GRPCChannel *)channelWithConfiguration:(GRPCChannelConfiguration *)configuration;
/** Remove a channel with particular configuration. */
- (void)removeChannelWithConfiguration:(GRPCChannelConfiguration *)configuration;
/** Remove a channel from the pool. */
- (void)removeChannel:(GRPCChannel *)channel;
/** Clear all channels in the pool. */
- (void)removeAllChannels;

@ -199,9 +199,13 @@ extern const char *kCFStreamVarName;
return channel;
}
- (void)removeChannelWithConfiguration:(GRPCChannelConfiguration *)configuration {
- (void)removeChannel:(GRPCChannel *)channel {
@synchronized(self) {
[self->_channelPool removeObjectForKey:configuration];
[_channelPool enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration * _Nonnull key, GRPCChannel * _Nonnull obj, BOOL * _Nonnull stop) {
if (obj == channel) {
[self->_channelPool removeObjectForKey:key];
}
}];
}
}

@ -59,7 +59,7 @@ NSString *kDummyHost = @"dummy.host";
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCChannel *channel1 =
[pool channelWithConfiguration:config1];
[pool removeChannelWithConfiguration:config1];
[pool removeChannel:channel1];
GRPCChannel *channel2 =
[pool channelWithConfiguration:config1];
XCTAssertNotEqual(channel1, channel2);

Loading…
Cancel
Save