|
|
@ -53,13 +53,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)(void))handler { |
|
|
|
- (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)(void))handler { |
|
|
|
if (self = [super init]) { |
|
|
|
if (self = [super init]) { |
|
|
|
if (metadata) { |
|
|
|
_send_metadata = [metadata grpc_getMetadataArray]; |
|
|
|
[metadata grpc_getMetadataArray:&_send_metadata]; |
|
|
|
|
|
|
|
_count = metadata.count; |
|
|
|
_count = metadata.count; |
|
|
|
} else { |
|
|
|
|
|
|
|
_send_metadata = NULL; |
|
|
|
|
|
|
|
_count = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_handler = handler; |
|
|
|
_handler = handler; |
|
|
|
} |
|
|
|
} |
|
|
|
return self; |
|
|
|
return self; |
|
|
@ -68,6 +63,7 @@ |
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
|
|
|
op->op = GRPC_OP_SEND_INITIAL_METADATA; |
|
|
|
op->data.send_initial_metadata.count = _count; |
|
|
|
op->data.send_initial_metadata.count = _count; |
|
|
|
|
|
|
|
op->data.send_initial_metadata.metadata = _send_metadata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
- (void (^)(void))opProcessor { |
|
|
@ -148,7 +144,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
@implementation GRPCOpRecvMetadata{ |
|
|
|
@implementation GRPCOpRecvMetadata{ |
|
|
|
void(^_handler)(NSDictionary *); |
|
|
|
void(^_handler)(NSDictionary *); |
|
|
|
grpc_metadata_array *_recv_initial_metadata; |
|
|
|
grpc_metadata_array _recv_initial_metadata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype) init { |
|
|
|
- (instancetype) init { |
|
|
@ -158,23 +154,22 @@ |
|
|
|
- (instancetype) initWithHandler:(void (^)(NSDictionary *))handler { |
|
|
|
- (instancetype) initWithHandler:(void (^)(NSDictionary *))handler { |
|
|
|
if (self = [super init]) { |
|
|
|
if (self = [super init]) { |
|
|
|
_handler = handler; |
|
|
|
_handler = handler; |
|
|
|
_recv_initial_metadata = gpr_malloc(sizeof(grpc_metadata_array)); |
|
|
|
grpc_metadata_array_init(&_recv_initial_metadata); |
|
|
|
grpc_metadata_array_init(_recv_initial_metadata); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return self; |
|
|
|
return self; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
op->op = GRPC_OP_RECV_INITIAL_METADATA; |
|
|
|
op->op = GRPC_OP_RECV_INITIAL_METADATA; |
|
|
|
op->data.recv_initial_metadata = _recv_initial_metadata; |
|
|
|
op->data.recv_initial_metadata = &_recv_initial_metadata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
return ^{ |
|
|
|
return ^{ |
|
|
|
NSDictionary *metadata = [NSDictionary |
|
|
|
NSDictionary *metadata = [NSDictionary |
|
|
|
grpc_dictionaryFromMetadata:_recv_initial_metadata->metadata |
|
|
|
grpc_dictionaryFromMetadata:_recv_initial_metadata.metadata |
|
|
|
count:_recv_initial_metadata->count]; |
|
|
|
count:_recv_initial_metadata.count]; |
|
|
|
grpc_metadata_array_destroy(_recv_initial_metadata); |
|
|
|
grpc_metadata_array_destroy(&_recv_initial_metadata); |
|
|
|
if (_handler) { |
|
|
|
if (_handler) { |
|
|
|
_handler(metadata); |
|
|
|
_handler(metadata); |
|
|
|
} |
|
|
|
} |
|
|
@ -185,7 +180,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
@implementation GRPCOpRecvMessage{ |
|
|
|
@implementation GRPCOpRecvMessage{ |
|
|
|
void(^_handler)(grpc_byte_buffer *); |
|
|
|
void(^_handler)(grpc_byte_buffer *); |
|
|
|
grpc_byte_buffer **_recv_message; |
|
|
|
grpc_byte_buffer *_recv_message; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)init { |
|
|
|
- (instancetype)init { |
|
|
@ -195,21 +190,19 @@ |
|
|
|
- (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler { |
|
|
|
- (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler { |
|
|
|
if (self = [super init]) { |
|
|
|
if (self = [super init]) { |
|
|
|
_handler = handler; |
|
|
|
_handler = handler; |
|
|
|
_recv_message = gpr_malloc(sizeof(grpc_byte_buffer*)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return self; |
|
|
|
return self; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
op->op = GRPC_OP_RECV_MESSAGE; |
|
|
|
op->op = GRPC_OP_RECV_MESSAGE; |
|
|
|
op->data.recv_message = _recv_message; |
|
|
|
op->data.recv_message = &_recv_message; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
return ^{ |
|
|
|
return ^{ |
|
|
|
if (_handler) { |
|
|
|
if (_handler) { |
|
|
|
_handler(*_recv_message); |
|
|
|
_handler(_recv_message); |
|
|
|
gpr_free(_recv_message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
@ -218,10 +211,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
@implementation GRPCOpRecvStatus{ |
|
|
|
@implementation GRPCOpRecvStatus{ |
|
|
|
void(^_handler)(NSError *); |
|
|
|
void(^_handler)(NSError *); |
|
|
|
grpc_status_code *_code; |
|
|
|
size_t _details_capacity; |
|
|
|
char **_details; |
|
|
|
grpc_status _status; |
|
|
|
size_t *_details_capacity; |
|
|
|
|
|
|
|
grpc_metadata_array *_recv_trailing_metadata; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype) init { |
|
|
|
- (instancetype) init { |
|
|
@ -231,34 +222,27 @@ |
|
|
|
- (instancetype) initWithHandler:(void (^)(NSError *))handler { |
|
|
|
- (instancetype) initWithHandler:(void (^)(NSError *))handler { |
|
|
|
if (self = [super init]) { |
|
|
|
if (self = [super init]) { |
|
|
|
_handler = handler; |
|
|
|
_handler = handler; |
|
|
|
_code = gpr_malloc(sizeof(grpc_status_code)); |
|
|
|
_status.details = NULL; |
|
|
|
_details = gpr_malloc(sizeof(char*)); |
|
|
|
_details_capacity = 0; |
|
|
|
_details_capacity = gpr_malloc(sizeof(size_t)); |
|
|
|
grpc_metadata_array_init(&_status.metadata); |
|
|
|
*_details_capacity = 0; |
|
|
|
|
|
|
|
_recv_trailing_metadata = gpr_malloc(sizeof(grpc_metadata_array)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return self; |
|
|
|
return self; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
- (void)getOp:(grpc_op *)op { |
|
|
|
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
|
|
|
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
|
|
|
op->data.recv_status_on_client.status = _code; |
|
|
|
op->data.recv_status_on_client.status = &_status.status; |
|
|
|
op->data.recv_status_on_client.status_details = _details; |
|
|
|
op->data.recv_status_on_client.status_details = &_status.details; |
|
|
|
op->data.recv_status_on_client.status_details_capacity = _details_capacity; |
|
|
|
op->data.recv_status_on_client.status_details_capacity = &_details_capacity; |
|
|
|
op->data.recv_status_on_client.trailing_metadata = _recv_trailing_metadata; |
|
|
|
op->data.recv_status_on_client.trailing_metadata = &_status.metadata; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
- (void (^)(void))opProcessor { |
|
|
|
return ^{ |
|
|
|
return ^{ |
|
|
|
grpc_status status; |
|
|
|
|
|
|
|
status.status = *_code; |
|
|
|
|
|
|
|
status.details = *_details; |
|
|
|
|
|
|
|
status.metadata = _recv_trailing_metadata; |
|
|
|
|
|
|
|
gpr_free(_code); |
|
|
|
|
|
|
|
gpr_free(_details); |
|
|
|
|
|
|
|
gpr_free(_details_capacity); |
|
|
|
|
|
|
|
if (_handler) { |
|
|
|
if (_handler) { |
|
|
|
_handler([NSError grpc_errorFromStatus:&status]); |
|
|
|
NSError *error = [NSError grpc_errorFromStatus:&_status]; |
|
|
|
|
|
|
|
grpc_metadata_array_destroy(&_status.metadata); |
|
|
|
|
|
|
|
_handler(error); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
@ -326,7 +310,8 @@ |
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
if (error != GRPC_CALL_OK) { |
|
|
|
[NSException raise:NSInvalidArgumentException format:@"The batch did not start successfully"]; |
|
|
|
[NSException raise:NSInternalInconsistencyException |
|
|
|
|
|
|
|
format:@"A precondition for calling grpc_call_start_batch wasn't met"]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|