diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index f9d8cce8475ecf8ca6dde36b4b378f18704994da..45915cbfadfb48aaea715eedee5d836e48428b36 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -366,12 +366,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/support/log_posix.c b/src/core/support/log_posix.c index 55a38b136d0de0e7cab567a5d98bbddd5115149d..ee2705a2c200189ddda33e2022344f51f206899b 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -31,7 +31,6 @@ * */ - #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L #endif diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 4ce958171b54d648824fd23753cd2276ed6d56c9..3579a5bb9fa42a22b7919930b830634e8c26a29a 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -278,9 +278,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) { @@ -299,8 +299,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) { @@ -825,7 +829,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/stream/stream_context.cc b/src/cpp/stream/stream_context.cc index d46ba6e56ae2807106f264a6974a96fce5915363..5ccf8c9682880d7c4c22eb831084507f1122a976 100644 --- a/src/cpp/stream/stream_context.cc +++ b/src/cpp/stream/stream_context.cc @@ -112,7 +112,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; @@ -130,7 +131,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; @@ -169,20 +171,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<StatusCode>(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/util/test_config.c b/test/core/util/test_config.c index ab2c0d80a992ab1fa617b5d278acc7134479a8e4..a9a687835e776513205b83fc4341f99149f78de1 100644 --- a/test/core/util/test_config.c +++ b/test/core/util/test_config.c @@ -38,16 +38,12 @@ #if GPR_GETPID_IN_UNISTD_H #include <unistd.h> -static int seed() { - return getpid(); -} +static int seed() { return getpid(); } #endif #if GPR_GETPID_IN_PROCESS_H #include <process.h> -static int seed(void) { - return _getpid(); -} +static int seed(void) { return _getpid(); } #endif void grpc_test_init(int argc, char **argv) {