pull/16190/head
Muxi Yan 6 years ago
parent eeced98fc5
commit f9e50322bf
  1. 16
      src/objective-c/GRPCClient/GRPCCall.h
  2. 4
      src/objective-c/GRPCClient/GRPCCall.m
  3. 49
      src/objective-c/GRPCClient/private/GRPCChannelPool+Test.h
  4. 28
      src/objective-c/GRPCClient/private/GRPCChannelPool.h
  5. 7
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  6. 16
      src/objective-c/ProtoRPC/ProtoRPC.h
  7. 5
      src/objective-c/ProtoRPC/ProtoRPC.m
  8. 2
      src/objective-c/tests/ChannelTests/ChannelPoolTest.m
  9. 1
      src/objective-c/tests/ChannelTests/ChannelTests.m

@ -153,6 +153,14 @@ extern NSString *const kGRPCTrailersKey;
/** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCResponseHandler<NSObject>
@required
/**
* All the responses must be issued to a user-provided dispatch queue. This property specifies the
* dispatch queue to be used for issuing the notifications.
*/
@property(atomic, readonly) dispatch_queue_t dispatchQueue;
@optional
/**
@ -175,14 +183,6 @@ extern NSString *const kGRPCTrailersKey;
- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(nullable NSError *)error;
@required
/**
* All the responses must be issued to a user-provided dispatch queue. This property specifies the
* dispatch queue to be used for issuing the notifications.
*/
@property(atomic, readonly) dispatch_queue_t dispatchQueue;
@end
/**

@ -856,9 +856,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
_retainSelf = self;
if (_callOptions == nil) {
GRPCMutableCallOptions *callOptions;
callOptions = [[GRPCHost callOptionsForHost:_host] mutableCopy];
GRPCMutableCallOptions *callOptions = [[GRPCHost callOptionsForHost:_host] mutableCopy];
if (_serverName.length != 0) {
callOptions.serverAuthority = _serverName;
}

@ -0,0 +1,49 @@
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#import "GRPCChannelPool.h"
/** Test-only interface for \a GRPCPooledChannel. */
@interface GRPCPooledChannel (Test)
/**
* Initialize a pooled channel with non-default destroy delay for testing purpose.
*/
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay;
/**
* Return the pointer to the raw channel wrapped.
*/
@property(atomic, readonly) GRPCChannel *wrappedChannel;
@end
/** Test-only interface for \a GRPCChannelPool. */
@interface GRPCChannelPool (Test)
/**
* Get an instance of pool isolated from the global shared pool with channels' destroy delay being
* \a destroyDelay.
*/
- (nullable instancetype)initTestPool;
@end

@ -75,23 +75,6 @@ NS_ASSUME_NONNULL_BEGIN
@end
/** Test-only interface for \a GRPCPooledChannel. */
@interface GRPCPooledChannel (Test)
/**
* Initialize a pooled channel with non-default destroy delay for testing purpose.
*/
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay;
/**
* Return the pointer to the raw channel wrapped.
*/
@property(atomic, readonly) GRPCChannel *wrappedChannel;
@end
/**
* Manage the pool of connected channels. When a channel is no longer referenced by any call,
* destroy the channel after a certain period of time elapsed.
@ -119,15 +102,4 @@ NS_ASSUME_NONNULL_BEGIN
@end
/** Test-only interface for \a GRPCChannelPool. */
@interface GRPCChannelPool (Test)
/**
* Get an instance of pool isolated from the global shared pool with channels' destroy delay being
* \a destroyDelay.
*/
- (nullable instancetype)initTestPool;
@end
NS_ASSUME_NONNULL_END

@ -22,6 +22,7 @@
#import "GRPCChannel.h"
#import "GRPCChannelFactory.h"
#import "GRPCChannelPool.h"
#import "GRPCChannelPool+Test.h"
#import "GRPCConnectivityMonitor.h"
#import "GRPCCronetChannelFactory.h"
#import "GRPCInsecureChannelFactory.h"
@ -59,9 +60,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
- (void)dealloc {
// Disconnect GRPCWrappedCall objects created but not yet removed
if (_wrappedCalls.allObjects.count != 0) {
NSEnumerator *enumerator = [_wrappedCalls objectEnumerator];
GRPCWrappedCall *wrappedCall;
while ((wrappedCall = [enumerator nextObject])) {
for (GRPCWrappedCall *wrappedCall in _wrappedCalls.allObjects) {
[wrappedCall channelDisconnected];
};
}
@ -73,7 +72,7 @@ callOptions:(GRPCCallOptions *)callOptions {
NSAssert(path.length > 0, @"path must not be empty.");
NSAssert(queue != nil, @"completionQueue must not be empty.");
NSAssert(callOptions, @"callOptions must not be empty.");
if (path.length == 0 || queue == nil || callOptions == nil) return NULL;
if (path.length == 0 || queue == nil || callOptions == nil) return nil;
GRPCWrappedCall *call = nil;

@ -28,6 +28,14 @@ NS_ASSUME_NONNULL_BEGIN
/** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCProtoResponseHandler<NSObject>
@required
/**
* All the responses must be issued to a user-provided dispatch queue. This property specifies the
* dispatch queue to be used for issuing the notifications.
*/
@property(atomic, readonly) dispatch_queue_t dispatchQueue;
@optional
/**
@ -49,14 +57,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(nullable NSError *)error;
@required
/**
* All the responses must be issued to a user-provided dispatch queue. This property specifies the
* dispatch queue to be used for issuing the notifications.
*/
@property(atomic, readonly) dispatch_queue_t dispatchQueue;
@end
/** A unary-request RPC call with Protobuf. */

@ -75,7 +75,6 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
- (void)cancel {
[_call cancel];
_call = nil;
}
@end
@ -124,7 +123,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
#else
{
#endif
_dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL);
_dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
}
dispatch_set_target_queue(_dispatchQueue, handler.dispatchQueue);
@ -145,7 +144,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
copiedCall = _call;
_call = nil;
if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_handler.dispatchQueue, ^{
dispatch_async(_dispatchQueue, ^{
id<GRPCProtoResponseHandler> copiedHandler = nil;
@synchronized(self) {
copiedHandler = self->_handler;

@ -19,7 +19,7 @@
#import <XCTest/XCTest.h>
#import "../../GRPCClient/private/GRPCChannel.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCChannelPool+Test.h"
#import "../../GRPCClient/private/GRPCCompletionQueue.h"
#define TEST_TIMEOUT 32

@ -21,6 +21,7 @@
#import "../../GRPCClient/GRPCCallOptions.h"
#import "../../GRPCClient/private/GRPCChannel.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCChannelPool+Test.h"
#import "../../GRPCClient/private/GRPCCompletionQueue.h"
#import "../../GRPCClient/private/GRPCWrappedCall.h"

Loading…
Cancel
Save