murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 34 | #import "GRPCWrappedCall.h" |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 35 | |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 36 | #import <Foundation/Foundation.h> |
| 37 | #include <grpc/grpc.h> |
| 38 | #include <grpc/byte_buffer.h> |
| 39 | #include <grpc/support/alloc.h> |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 40 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 41 | #import "GRPCCompletionQueue.h" |
| 42 | #import "GRPCHost.h" |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 43 | #import "NSDictionary+GRPC.h" |
| 44 | #import "NSData+GRPC.h" |
| 45 | #import "NSError+GRPC.h" |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 46 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 47 | @implementation GRPCOperation { |
| 48 | @protected |
Jorge Canizales | 8848704 | 2015-06-21 21:59:37 -0700 | [diff] [blame] | 49 | // Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being |
| 50 | // initialized to zero. |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 51 | grpc_op _op; |
| 52 | void(^_handler)(); |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 55 | - (void)finish { |
| 56 | if (_handler) { |
| 57 | _handler(); |
| 58 | } |
| 59 | } |
| 60 | @end |
| 61 | |
| 62 | @implementation GRPCOpSendMetadata |
| 63 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 64 | - (instancetype)init { |
| 65 | return [self initWithMetadata:nil handler:nil]; |
| 66 | } |
| 67 | |
Jorge Canizales | f4f150f | 2015-11-01 22:31:12 -0800 | [diff] [blame] | 68 | - (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 69 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 70 | _op.op = GRPC_OP_SEND_INITIAL_METADATA; |
| 71 | _op.data.send_initial_metadata.count = metadata.count; |
| 72 | _op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 73 | _handler = handler; |
| 74 | } |
| 75 | return self; |
| 76 | } |
| 77 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 78 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 79 | gpr_free(_op.data.send_initial_metadata.metadata); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 80 | } |
| 81 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 82 | @end |
| 83 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 84 | @implementation GRPCOpSendMessage |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 85 | |
| 86 | - (instancetype)init { |
| 87 | return [self initWithMessage:nil handler:nil]; |
| 88 | } |
| 89 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 90 | - (instancetype)initWithMessage:(NSData *)message handler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 91 | if (!message) { |
murgatroid99 | 2101a48 | 2015-04-29 11:42:26 -0700 | [diff] [blame] | 92 | [NSException raise:NSInvalidArgumentException format:@"message cannot be nil"]; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 93 | } |
| 94 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 95 | _op.op = GRPC_OP_SEND_MESSAGE; |
| 96 | _op.data.send_message = message.grpc_byteBuffer; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 97 | _handler = handler; |
| 98 | } |
| 99 | return self; |
| 100 | } |
| 101 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 102 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 103 | gpr_free(_op.data.send_message); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 104 | } |
| 105 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 106 | @end |
| 107 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 108 | @implementation GRPCOpSendClose |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 109 | |
| 110 | - (instancetype)init { |
| 111 | return [self initWithHandler:nil]; |
| 112 | } |
| 113 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 114 | - (instancetype)initWithHandler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 115 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 116 | _op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 117 | _handler = handler; |
| 118 | } |
| 119 | return self; |
| 120 | } |
| 121 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 122 | @end |
| 123 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 124 | @implementation GRPCOpRecvMetadata { |
| 125 | grpc_metadata_array _headers; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | - (instancetype) init { |
| 129 | return [self initWithHandler:nil]; |
| 130 | } |
| 131 | |
| 132 | - (instancetype) initWithHandler:(void (^)(NSDictionary *))handler { |
| 133 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 134 | _op.op = GRPC_OP_RECV_INITIAL_METADATA; |
| 135 | grpc_metadata_array_init(&_headers); |
| 136 | _op.data.recv_initial_metadata = &_headers; |
| 137 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 138 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 139 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 140 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 141 | __strong typeof(self) strongSelf = weakSelf; |
| 142 | NSDictionary *metadata = [NSDictionary |
| 143 | grpc_dictionaryFromMetadataArray:strongSelf->_headers]; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 144 | handler(metadata); |
| 145 | }; |
| 146 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 147 | } |
| 148 | return self; |
| 149 | } |
| 150 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 151 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 152 | grpc_metadata_array_destroy(&_headers); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 153 | } |
| 154 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 155 | @end |
| 156 | |
| 157 | @implementation GRPCOpRecvMessage{ |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 158 | grpc_byte_buffer *_receivedMessage; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | - (instancetype)init { |
| 162 | return [self initWithHandler:nil]; |
| 163 | } |
| 164 | |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 165 | - (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 166 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 167 | _op.op = GRPC_OP_RECV_MESSAGE; |
| 168 | _op.data.recv_message = &_receivedMessage; |
| 169 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 170 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 171 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 172 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 173 | __strong typeof(self) strongSelf = weakSelf; |
| 174 | handler(strongSelf->_receivedMessage); |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 175 | }; |
| 176 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 177 | } |
| 178 | return self; |
| 179 | } |
| 180 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 181 | @end |
| 182 | |
| 183 | @implementation GRPCOpRecvStatus{ |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 184 | grpc_status_code _statusCode; |
| 185 | char *_details; |
murgatroid99 | ca38ddb | 2015-04-29 13:16:42 -0700 | [diff] [blame] | 186 | size_t _detailsCapacity; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 187 | grpc_metadata_array _trailers; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | - (instancetype) init { |
| 191 | return [self initWithHandler:nil]; |
| 192 | } |
| 193 | |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 194 | - (instancetype) initWithHandler:(void (^)(NSError *, NSDictionary *))handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 195 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 196 | _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 197 | _op.data.recv_status_on_client.status = &_statusCode; |
| 198 | _op.data.recv_status_on_client.status_details = &_details; |
| 199 | _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity; |
| 200 | grpc_metadata_array_init(&_trailers); |
| 201 | _op.data.recv_status_on_client.trailing_metadata = &_trailers; |
| 202 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 203 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 204 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 205 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 206 | __strong typeof(self) strongSelf = weakSelf; |
| 207 | NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode |
| 208 | details:strongSelf->_details]; |
| 209 | NSDictionary *trailers = [NSDictionary |
| 210 | grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 211 | handler(error, trailers); |
| 212 | }; |
| 213 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 214 | } |
| 215 | return self; |
| 216 | } |
| 217 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 218 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 219 | grpc_metadata_array_destroy(&_trailers); |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 220 | gpr_free(_details); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 221 | } |
| 222 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 223 | @end |
| 224 | |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 225 | #pragma mark GRPCWrappedCall |
| 226 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 227 | @implementation GRPCWrappedCall { |
| 228 | GRPCCompletionQueue *_queue; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 229 | grpc_call *_call; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | - (instancetype)init { |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 233 | return [self initWithHost:nil path:nil]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 236 | - (instancetype)initWithHost:(NSString *)host |
| 237 | path:(NSString *)path { |
| 238 | if (!path || !host) { |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 239 | [NSException raise:NSInvalidArgumentException |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 240 | format:@"path and host cannot be nil."]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 241 | } |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 242 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 243 | if (self = [super init]) { |
| 244 | static dispatch_once_t initialization; |
| 245 | dispatch_once(&initialization, ^{ |
| 246 | grpc_init(); |
| 247 | }); |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 248 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 249 | // Each completion queue consumes one thread. There's a trade to be made between creating and |
| 250 | // consuming too many threads and having contention of multiple calls in a single completion |
| 251 | // queue. Currently we favor latency and use one per call. |
| 252 | _queue = [GRPCCompletionQueue completionQueue]; |
| 253 | |
| 254 | _call = [[GRPCHost hostWithAddress:host] unmanagedCallWithPath:path completionQueue:_queue]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 255 | if (_call == NULL) { |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 256 | return nil; |
| 257 | } |
| 258 | } |
| 259 | return self; |
| 260 | } |
| 261 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 262 | - (void)startBatchWithOperations:(NSArray *)operations { |
| 263 | [self startBatchWithOperations:operations errorHandler:nil]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 264 | } |
| 265 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 266 | - (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)())errorHandler { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 267 | size_t nops = operations.count; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 268 | grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op)); |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 269 | size_t i = 0; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 270 | for (GRPCOperation *operation in operations) { |
| 271 | ops_array[i++] = operation.op; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 272 | } |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 273 | grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops, |
murgatroid99 | 6b54244 | 2015-05-08 10:40:01 -0700 | [diff] [blame] | 274 | (__bridge_retained void *)(^(bool success){ |
| 275 | if (!success) { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 276 | if (errorHandler) { |
| 277 | errorHandler(); |
| 278 | } else { |
murgatroid99 | def47aa | 2015-04-29 10:28:26 -0700 | [diff] [blame] | 279 | return; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 280 | } |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 281 | } |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 282 | for (GRPCOperation *operation in operations) { |
murgatroid99 | 2101a48 | 2015-04-29 11:42:26 -0700 | [diff] [blame] | 283 | [operation finish]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 284 | } |
Jorge Canizales | b3584aa | 2015-08-08 15:01:24 -0700 | [diff] [blame] | 285 | }), NULL); |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 286 | gpr_free(ops_array); |
| 287 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 288 | if (error != GRPC_CALL_OK) { |
murgatroid99 | 6a084f4 | 2015-04-29 10:18:05 -0700 | [diff] [blame] | 289 | [NSException raise:NSInternalInconsistencyException |
Jorge Canizales | bae38d9 | 2015-06-20 20:21:25 -0700 | [diff] [blame] | 290 | format:@"A precondition for calling grpc_call_start_batch wasn't met. Error %i", |
| 291 | error]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
| 295 | - (void)cancel { |
Jorge Canizales | b3584aa | 2015-08-08 15:01:24 -0700 | [diff] [blame] | 296 | grpc_call_cancel(_call, NULL); |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | - (void)dealloc { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 300 | grpc_call_destroy(_call); |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 303 | @end |