diff options
author | 2015-02-06 17:18:10 -0800 | |
---|---|---|
committer | 2015-02-06 17:18:10 -0800 | |
commit | d78a657980df9dbb902a5effb99d37f7a4ad1ab1 (patch) | |
tree | 2162dcb13b6f8232af1a5af7d4a23a4f77ba3dd4 /src/core/surface/call.c | |
parent | 41efbf3a96d1caa8066ab46cad5934ad30da2e8f (diff) | |
parent | a99bfe5e8ebd4b4b4e509cbd73e37c0a024d1308 (diff) |
Merge github.com:grpc/grpc into async-api-new
Diffstat (limited to 'src/core/surface/call.c')
-rw-r--r-- | src/core/surface/call.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/core/surface/call.c b/src/core/surface/call.c index b3f272e068..37ae42676d 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -54,7 +54,9 @@ typedef enum { REQ_INITIAL = 0, REQ_READY, REQ_DONE } req_state; typedef enum { SEND_NOTHING, SEND_INITIAL_METADATA, + SEND_BUFFERED_INITIAL_METADATA, SEND_MESSAGE, + SEND_BUFFERED_MESSAGE, SEND_TRAILING_METADATA_AND_FINISH, SEND_FINISH } send_action; @@ -534,19 +536,29 @@ static send_action choose_send_action(grpc_call *call) { case WRITE_STATE_INITIAL: if (is_op_live(call, GRPC_IOREQ_SEND_INITIAL_METADATA)) { call->write_state = WRITE_STATE_STARTED; - return SEND_INITIAL_METADATA; + if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE) || is_op_live(call, GRPC_IOREQ_SEND_CLOSE)) { + return SEND_BUFFERED_INITIAL_METADATA; + } else { + return SEND_INITIAL_METADATA; + } } return SEND_NOTHING; case WRITE_STATE_STARTED: if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE)) { - return SEND_MESSAGE; - } - if (is_op_live(call, GRPC_IOREQ_SEND_CLOSE)) { + if (is_op_live(call, GRPC_IOREQ_SEND_CLOSE)) { + return SEND_BUFFERED_MESSAGE; + } else { + return SEND_MESSAGE; + } + } else if (is_op_live(call, GRPC_IOREQ_SEND_CLOSE)) { call->write_state = WRITE_STATE_WRITE_CLOSED; finish_ioreq_op(call, GRPC_IOREQ_SEND_TRAILING_METADATA, GRPC_OP_OK); finish_ioreq_op(call, GRPC_IOREQ_SEND_STATUS, GRPC_OP_OK); - return call->is_client ? SEND_FINISH - : SEND_TRAILING_METADATA_AND_FINISH; + if (call->is_client) { + return SEND_FINISH; + } else { + return SEND_TRAILING_METADATA_AND_FINISH; + } } return SEND_NOTHING; case WRITE_STATE_WRITE_CLOSED: @@ -561,7 +573,7 @@ static void send_metadata(grpc_call *call, grpc_mdelem *elem) { grpc_call_op op; op.type = GRPC_SEND_METADATA; op.dir = GRPC_CALL_DOWN; - op.flags = 0; + op.flags = GRPC_WRITE_BUFFER_HINT; op.data.metadata = elem; op.done_cb = do_nothing; op.user_data = NULL; @@ -572,12 +584,16 @@ static void enact_send_action(grpc_call *call, send_action sa) { grpc_ioreq_data data; grpc_call_op op; size_t i; + gpr_uint32 flags = 0; char status_str[GPR_LTOA_MIN_BUFSIZE]; switch (sa) { case SEND_NOTHING: abort(); break; + case SEND_BUFFERED_INITIAL_METADATA: + flags |= GRPC_WRITE_BUFFER_HINT; + /* fallthrough */ case SEND_INITIAL_METADATA: data = call->request_data[GRPC_IOREQ_SEND_INITIAL_METADATA]; for (i = 0; i < data.send_metadata.count; i++) { @@ -589,17 +605,20 @@ static void enact_send_action(grpc_call *call, send_action sa) { } op.type = GRPC_SEND_START; op.dir = GRPC_CALL_DOWN; - op.flags = 0; + op.flags = flags; op.data.start.pollset = grpc_cq_pollset(call->cq); op.done_cb = finish_start_step; op.user_data = call; grpc_call_execute_op(call, &op); break; + case SEND_BUFFERED_MESSAGE: + flags |= GRPC_WRITE_BUFFER_HINT; + /* fallthrough */ case SEND_MESSAGE: data = call->request_data[GRPC_IOREQ_SEND_MESSAGE]; op.type = GRPC_SEND_MESSAGE; op.dir = GRPC_CALL_DOWN; - op.flags = 0; + op.flags = flags; op.data.message = data.send_message; op.done_cb = finish_write_step; op.user_data = call; |