1/* 2 * 3 * Copyright 2016 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19#import "GRPCCall+ChannelArg.h" 20 21#import "private/GRPCCore/GRPCChannelPool.h" 22#import "private/GRPCCore/GRPCHost.h" 23 24#import <grpc/impl/codegen/compression_types.h> 25 26@implementation GRPCCall (ChannelArg) 27 28+ (void)setUserAgentPrefix:(nonnull NSString *)userAgentPrefix forHost:(nonnull NSString *)host { 29 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 30 hostConfig.userAgentPrefix = userAgentPrefix; 31} 32 33+ (void)setResponseSizeLimit:(NSUInteger)limit forHost:(nonnull NSString *)host { 34 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 35 hostConfig.responseSizeLimitOverride = limit; 36} 37 38+ (void)closeOpenConnections { 39 [[GRPCChannelPool sharedInstance] disconnectAllChannels]; 40} 41 42+ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm forhost:(nonnull NSString *)host { 43 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 44 switch (algorithm) { 45 case GRPCCompressNone: 46 hostConfig.compressAlgorithm = GRPC_COMPRESS_NONE; 47 break; 48 case GRPCCompressDeflate: 49 hostConfig.compressAlgorithm = GRPC_COMPRESS_DEFLATE; 50 break; 51 case GRPCCompressGzip: 52 hostConfig.compressAlgorithm = GRPC_COMPRESS_GZIP; 53 break; 54 default: 55 NSLog(@"Invalid compression algorithm"); 56 abort(); 57 } 58} 59 60+ (void)setKeepaliveWithInterval:(int)interval 61 timeout:(int)timeout 62 forHost:(nonnull NSString *)host { 63 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 64 hostConfig.keepaliveInterval = interval; 65 hostConfig.keepaliveTimeout = timeout; 66} 67 68+ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host { 69 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 70 hostConfig.retryEnabled = enabled; 71} 72 73+ (void)setMinConnectTimeout:(unsigned int)timeout 74 initialBackoff:(unsigned int)initialBackoff 75 maxBackoff:(unsigned int)maxBackoff 76 forHost:(nonnull NSString *)host { 77 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 78 hostConfig.minConnectTimeout = timeout; 79 hostConfig.initialConnectBackoff = initialBackoff; 80 hostConfig.maxConnectBackoff = maxBackoff; 81} 82 83@end 84