From 09b637538f4e7e65d6d3994929f386a809317c21 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Jan 2015 13:02:09 -0800 Subject: [PATCH] clang-format --- include/grpc/grpc.h | 8 +++++--- src/core/surface/call.c | 17 +++++++++++------ src/cpp/client/channel.cc | 5 ++--- src/cpp/stream/stream_context.cc | 20 +++++++++----------- test/core/end2end/tests/thread_stress.c | 4 ++-- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 53e0d056305..8ab3d258732 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -370,12 +370,14 @@ grpc_call_error grpc_call_server_end_initial_metadata(grpc_call *call, grpc_call_error grpc_call_cancel(grpc_call *call); /* Called by clients to cancel an RPC on the server. - Can be called multiple times, from any thread. + Can be called multiple times, from any thread. If a status has not been received for the call, set it to the status code - and description passed in. + and description passed in. Importantly, this function does not send status nor description to the remote endpoint. */ -grpc_call_error grpc_call_cancel_with_status(grpc_call *call, grpc_status_code status, const char *description); +grpc_call_error grpc_call_cancel_with_status(grpc_call *call, + grpc_status_code status, + const char *description); /* Queue a byte buffer for writing. flags is a bit-field combination of the write flags defined above. diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 87e3de88e2d..24c1567db92 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -286,9 +286,9 @@ static void maybe_set_status_code(grpc_call *call, gpr_uint32 status) { } static void maybe_set_status_details(grpc_call *call, grpc_mdstr *status) { - if (!call->status_details) { - call->status_details = grpc_mdstr_ref(status); - } + if (!call->status_details) { + call->status_details = grpc_mdstr_ref(status); + } } grpc_call_error grpc_call_cancel(grpc_call *c) { @@ -307,8 +307,12 @@ grpc_call_error grpc_call_cancel(grpc_call *c) { return GRPC_CALL_OK; } -grpc_call_error grpc_call_cancel_with_status(grpc_call *c, grpc_status_code status, const char *description) { - grpc_mdstr *details = description? grpc_mdstr_from_string(c->metadata_context, description) : NULL; +grpc_call_error grpc_call_cancel_with_status(grpc_call *c, + grpc_status_code status, + const char *description) { + grpc_mdstr *details = + description ? grpc_mdstr_from_string(c->metadata_context, description) + : NULL; gpr_mu_lock(&c->read_mu); maybe_set_status_code(c, status); if (details) { @@ -898,7 +902,8 @@ void grpc_call_recv_metadata(grpc_call_element *elem, grpc_call_op *op) { grpc_call *call = CALL_FROM_TOP_ELEM(elem); grpc_mdelem *md = op->data.metadata; grpc_mdstr *key = md->key; - gpr_log(GPR_DEBUG, "call %p got metadata %s %s", call, grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)); + gpr_log(GPR_DEBUG, "call %p got metadata %s %s", call, + grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)); if (key == grpc_channel_get_status_string(call->channel)) { maybe_set_status_code(call, decode_status(md)); grpc_mdelem_unref(md); diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 223151932ca..f476f77a49e 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -114,9 +114,8 @@ Status Channel::StartBlockingRpc(const RpcMethod& method, // add_metadata from context // // invoke - GPR_ASSERT(grpc_call_invoke(call, cq, metadata_read_tag, - finished_tag, - GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK); + GPR_ASSERT(grpc_call_invoke(call, cq, metadata_read_tag, finished_tag, + GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK); // write request grpc_byte_buffer* write_buffer = nullptr; bool success = SerializeProto(request, &write_buffer); diff --git a/src/cpp/stream/stream_context.cc b/src/cpp/stream/stream_context.cc index aec226b23c0..ebe71594c02 100644 --- a/src/cpp/stream/stream_context.cc +++ b/src/cpp/stream/stream_context.cc @@ -80,9 +80,8 @@ void StreamContext::Start(bool buffered) { if (is_client_) { // TODO(yangg) handle metadata send path int flag = buffered ? GRPC_WRITE_BUFFER_HINT : 0; - grpc_call_error error = grpc_call_invoke(call(), cq(), - client_metadata_read_tag(), - finished_tag(), flag); + grpc_call_error error = grpc_call_invoke( + call(), cq(), client_metadata_read_tag(), finished_tag(), flag); GPR_ASSERT(GRPC_CALL_OK == error); } else { // TODO(yangg) metadata needs to be added before accept @@ -105,7 +104,8 @@ bool StreamContext::Read(google::protobuf::Message* msg) { if (read_ev->data.read) { if (!DeserializeProto(read_ev->data.read, msg)) { ret = false; - grpc_call_cancel_with_status(call(), GRPC_STATUS_DATA_LOSS, "Failed to parse incoming proto"); + grpc_call_cancel_with_status(call(), GRPC_STATUS_DATA_LOSS, + "Failed to parse incoming proto"); } } else { ret = false; @@ -123,7 +123,8 @@ bool StreamContext::Write(const google::protobuf::Message* msg, bool is_last) { if (msg) { grpc_byte_buffer* out_buf = nullptr; if (!SerializeProto(*msg, &out_buf)) { - grpc_call_cancel_with_status(call(), GRPC_STATUS_INVALID_ARGUMENT, "Failed to serialize outgoing proto"); + grpc_call_cancel_with_status(call(), GRPC_STATUS_INVALID_ARGUMENT, + "Failed to serialize outgoing proto"); return false; } int flag = is_last ? GRPC_WRITE_BUFFER_HINT : 0; @@ -162,20 +163,17 @@ const Status& StreamContext::Wait() { // TODO(yangg) protect states by a mutex, including other places. if (!self_halfclosed_ || !peer_halfclosed_) { Cancel(); - } + } grpc_event* finish_ev = grpc_completion_queue_pluck(cq(), finished_tag(), gpr_inf_future); GPR_ASSERT(finish_ev->type == GRPC_FINISHED); final_status_ = Status( static_cast(finish_ev->data.finished.status), - finish_ev->data.finished.details ? finish_ev->data.finished.details - : ""); + finish_ev->data.finished.details ? finish_ev->data.finished.details : ""); grpc_event_finish(finish_ev); return final_status_; } -void StreamContext::Cancel() { - grpc_call_cancel(call()); -} +void StreamContext::Cancel() { grpc_call_cancel(call()); } } // namespace grpc diff --git a/test/core/end2end/tests/thread_stress.c b/test/core/end2end/tests/thread_stress.c index 36da4950bbc..3b571ebd084 100644 --- a/test/core/end2end/tests/thread_stress.c +++ b/test/core/end2end/tests/thread_stress.c @@ -116,8 +116,8 @@ static void start_request() { gpr_slice_unref(slice); g_active_requests++; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(call, g_fixture.client_cq, - NULL, NULL, 0)); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_invoke(call, g_fixture.client_cq, NULL, NULL, 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read(call, NULL)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write(call, buf, NULL, 0));