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)setUserAgentSuffix:(nonnull NSString *)userAgentSuffix forHost:(nonnull NSString *)host { 34 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 35 hostConfig.userAgentSuffix = userAgentSuffix; 36} 37 38+ (void)setResponseSizeLimit:(NSUInteger)limit forHost:(nonnull NSString *)host { 39 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 40 hostConfig.responseSizeLimitOverride = limit; 41} 42 43+ (void)closeOpenConnections { 44 [[GRPCChannelPool sharedInstance] disconnectAllChannels]; 45} 46 47+ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm forhost:(nonnull NSString *)host { 48 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 49 switch (algorithm) { 50 case GRPCCompressNone: 51 hostConfig.compressAlgorithm = GRPC_COMPRESS_NONE; 52 break; 53 case GRPCCompressDeflate: 54 hostConfig.compressAlgorithm = GRPC_COMPRESS_DEFLATE; 55 break; 56 case GRPCCompressGzip: 57 hostConfig.compressAlgorithm = GRPC_COMPRESS_GZIP; 58 break; 59 default: 60 NSLog(@"Invalid compression algorithm"); 61 abort(); 62 } 63} 64 65+ (void)setKeepaliveWithInterval:(int)interval 66 timeout:(int)timeout 67 forHost:(nonnull NSString *)host { 68 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 69 hostConfig.keepaliveInterval = interval; 70 hostConfig.keepaliveTimeout = timeout; 71} 72 73+ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host { 74 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 75 hostConfig.retryEnabled = enabled; 76} 77 78+ (void)setMinConnectTimeout:(unsigned int)timeout 79 initialBackoff:(unsigned int)initialBackoff 80 maxBackoff:(unsigned int)maxBackoff 81 forHost:(nonnull NSString *)host { 82 GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; 83 hostConfig.minConnectTimeout = timeout; 84 hostConfig.initialConnectBackoff = initialBackoff; 85 hostConfig.maxConnectBackoff = maxBackoff; 86} 87 88@end 89