• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/GRPCHost.h"
22
23#import <grpc/impl/codegen/compression_types.h>
24
25@implementation GRPCCall (ChannelArg)
26
27+ (void)setUserAgentPrefix:(nonnull NSString *)userAgentPrefix forHost:(nonnull NSString *)host {
28  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
29  hostConfig.userAgentPrefix = userAgentPrefix;
30}
31
32+ (void)setResponseSizeLimit:(NSUInteger)limit forHost:(nonnull NSString *)host {
33  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
34  hostConfig.responseSizeLimitOverride = @(limit);
35}
36
37+ (void)closeOpenConnections {
38  [GRPCHost flushChannelCache];
39}
40
41+ (void)setDefaultCompressMethod:(GRPCCompressAlgorithm)algorithm forhost:(nonnull NSString *)host {
42  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
43  switch (algorithm) {
44    case GRPCCompressNone:
45      hostConfig.compressAlgorithm = GRPC_COMPRESS_NONE;
46      break;
47    case GRPCCompressDeflate:
48      hostConfig.compressAlgorithm = GRPC_COMPRESS_DEFLATE;
49      break;
50    case GRPCCompressGzip:
51      hostConfig.compressAlgorithm = GRPC_COMPRESS_GZIP;
52      break;
53    default:
54      NSLog(@"Invalid compression algorithm");
55      abort();
56  }
57}
58
59+ (void)setKeepaliveWithInterval:(int)interval
60                         timeout:(int)timeout
61                         forHost:(nonnull NSString *)host {
62  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
63  hostConfig.keepaliveInterval = interval;
64  hostConfig.keepaliveTimeout = timeout;
65}
66
67+ (void)enableRetry:(BOOL)enabled forHost:(nonnull NSString *)host {
68  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
69  hostConfig.retryEnabled = enabled;
70}
71
72+ (void)setMinConnectTimeout:(unsigned int)timeout
73              initialBackoff:(unsigned int)initialBackoff
74                  maxBackoff:(unsigned int)maxBackoff
75                     forHost:(nonnull NSString *)host {
76  GRPCHost *hostConfig = [GRPCHost hostWithAddress:host];
77  hostConfig.minConnectTimeout = timeout;
78  hostConfig.initialConnectBackoff = initialBackoff;
79  hostConfig.maxConnectBackoff = maxBackoff;
80}
81
82@end
83