From 80fa15c15121a7d0ec020dec8bfa3697a96058b6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 13 Jan 2015 16:10:49 -0800 Subject: Moving prototype from Google to GitHub I'd started some prototyping work on this change before the move to GitHub; this change restores things. --- include/grpc/grpc.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 323a944f93..f479fb8a40 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -158,6 +158,7 @@ typedef struct grpc_byte_buffer grpc_byte_buffer; /* Sample helpers to obtain byte buffers (these will certainly move place */ grpc_byte_buffer *grpc_byte_buffer_create(gpr_slice *slices, size_t nslices); +grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb); size_t grpc_byte_buffer_length(grpc_byte_buffer *bb); void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer); @@ -319,6 +320,10 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata, Produces a GRPC_FINISHED event with finished_tag when the call has been completed (there may be other events for the call pending at this time) */ +grpc_call_error grpc_call_invoke(grpc_call *call, + grpc_completion_queue *cq, + void *metadata_read_tag, + void *finished_tag, gpr_uint32 flags); grpc_call_error grpc_call_start_invoke(grpc_call *call, grpc_completion_queue *cq, void *invoke_accepted_tag, -- cgit v1.2.3 From 40fc7a66323d74b4303d582345807c4577584a77 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 13 Jan 2015 16:11:58 -0800 Subject: clang-format codebase --- include/grpc/grpc.h | 7 ++-- src/core/surface/byte_buffer.c | 3 +- src/core/surface/call.c | 53 ++++++++++++------------ test/core/end2end/dualstack_socket_test.c | 3 +- test/core/end2end/no_server_test.c | 3 +- test/core/end2end/tests/disappearing_server.c | 4 +- test/core/end2end/tests/max_concurrent_streams.c | 8 ++-- test/core/end2end/tests/simple_delayed_request.c | 4 +- test/core/end2end/tests/thread_stress.c | 5 +-- test/core/surface/lame_client_test.c | 3 +- 10 files changed, 45 insertions(+), 48 deletions(-) (limited to 'include') diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index cc7ed4a9fb..e51a1668e8 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -320,10 +320,9 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata, Produces a GRPC_FINISHED event with finished_tag when the call has been completed (there may be other events for the call pending at this time) */ -grpc_call_error grpc_call_invoke(grpc_call *call, - grpc_completion_queue *cq, - void *metadata_read_tag, - void *finished_tag, gpr_uint32 flags); +grpc_call_error grpc_call_invoke(grpc_call *call, grpc_completion_queue *cq, + void *metadata_read_tag, void *finished_tag, + gpr_uint32 flags); grpc_call_error grpc_call_start_invoke(grpc_call *call, grpc_completion_queue *cq, void *invoke_accepted_tag, diff --git a/src/core/surface/byte_buffer.c b/src/core/surface/byte_buffer.c index 4087622894..d1be41074d 100644 --- a/src/core/surface/byte_buffer.c +++ b/src/core/surface/byte_buffer.c @@ -52,7 +52,8 @@ grpc_byte_buffer *grpc_byte_buffer_create(gpr_slice *slices, size_t nslices) { grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) { switch (bb->type) { case GRPC_BB_SLICE_BUFFER: - return grpc_byte_buffer_create(bb->data.slice_buffer.slices, bb->data.slice_buffer.count); + return grpc_byte_buffer_create(bb->data.slice_buffer.slices, + bb->data.slice_buffer.count); } gpr_log(GPR_INFO, "should never get here"); abort(); diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 297d9587eb..262fbe381a 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -357,10 +357,12 @@ grpc_call_error grpc_call_start_invoke(grpc_call *call, void *invoke_accepted_tag, void *metadata_read_tag, void *finished_tag, gpr_uint32 flags) { - grpc_call_error err = grpc_call_invoke(call, cq, metadata_read_tag, finished_tag, flags); + grpc_call_error err = + grpc_call_invoke(call, cq, metadata_read_tag, finished_tag, flags); if (err == GRPC_CALL_OK) { grpc_cq_begin_op(call->cq, call, GRPC_INVOKE_ACCEPTED); - grpc_cq_end_invoke_accepted(call->cq, invoke_accepted_tag, call, do_nothing, NULL, GRPC_OP_OK); + grpc_cq_end_invoke_accepted(call->cq, invoke_accepted_tag, call, do_nothing, + NULL, GRPC_OP_OK); } return err; } @@ -421,11 +423,11 @@ static void call_started(void *user_data, grpc_op_error error) { } if (pending_writes_done) { if (ok) { - op.type = GRPC_SEND_FINISH; - op.dir = GRPC_CALL_DOWN; - op.flags = 0; - op.done_cb = done_writes_done; - op.user_data = call; + op.type = GRPC_SEND_FINISH; + op.dir = GRPC_CALL_DOWN; + op.flags = 0; + op.done_cb = done_writes_done; + op.user_data = call; elem = CALL_ELEM_FROM_CALL(call, 0); elem->filter->call_op(elem, NULL, &op); @@ -435,10 +437,9 @@ static void call_started(void *user_data, grpc_op_error error) { } } -grpc_call_error grpc_call_invoke(grpc_call *call, - grpc_completion_queue *cq, - void *metadata_read_tag, - void *finished_tag, gpr_uint32 flags) { +grpc_call_error grpc_call_invoke(grpc_call *call, grpc_completion_queue *cq, + void *metadata_read_tag, void *finished_tag, + gpr_uint32 flags) { grpc_call_element *elem; grpc_call_op op; @@ -708,15 +709,15 @@ grpc_call_error grpc_call_start_write(grpc_call *call, } else { gpr_mu_unlock(&call->read_mu); - op.type = GRPC_SEND_MESSAGE; - op.dir = GRPC_CALL_DOWN; - op.flags = flags; - op.done_cb = done_write; - op.user_data = call; - op.data.message = byte_buffer; + op.type = GRPC_SEND_MESSAGE; + op.dir = GRPC_CALL_DOWN; + op.flags = flags; + op.done_cb = done_write; + op.user_data = call; + op.data.message = byte_buffer; - elem = CALL_ELEM_FROM_CALL(call, 0); - elem->filter->call_op(elem, NULL, &op); + elem = CALL_ELEM_FROM_CALL(call, 0); + elem->filter->call_op(elem, NULL, &op); } return GRPC_CALL_OK; @@ -757,14 +758,14 @@ grpc_call_error grpc_call_writes_done(grpc_call *call, void *tag) { } else { gpr_mu_unlock(&call->read_mu); - op.type = GRPC_SEND_FINISH; - op.dir = GRPC_CALL_DOWN; - op.flags = 0; - op.done_cb = done_writes_done; - op.user_data = call; + op.type = GRPC_SEND_FINISH; + op.dir = GRPC_CALL_DOWN; + op.flags = 0; + op.done_cb = done_writes_done; + op.user_data = call; - elem = CALL_ELEM_FROM_CALL(call, 0); - elem->filter->call_op(elem, NULL, &op); + elem = CALL_ELEM_FROM_CALL(call, 0); + elem->filter->call_op(elem, NULL, &op); } return GRPC_CALL_OK; diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index ac656d3719..b765d3d43e 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -115,8 +115,7 @@ void test_connect(const char *server_host, const char *client_host, int port, c = grpc_channel_create_call(client, "/foo", "test.google.com", deadline); GPR_ASSERT(c); - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_invoke(c, client_cq, tag(2), tag(3), 0)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(c, client_cq, tag(2), tag(3), 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done(c, tag(4))); if (expect_ok) { /* Check for a successful request. */ diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c index 0c251ab467..2c432456ce 100644 --- a/test/core/end2end/no_server_test.c +++ b/test/core/end2end/no_server_test.c @@ -57,8 +57,7 @@ int main(int argc, char **argv) { /* create a call, channel to a non existant server */ chan = grpc_channel_create("nonexistant:54321", NULL); call = grpc_channel_create_call(chan, "/foo", "nonexistant", deadline); - GPR_ASSERT(grpc_call_invoke(call, cq, tag(2), tag(3), 0) == - GRPC_CALL_OK); + GPR_ASSERT(grpc_call_invoke(call, cq, tag(2), tag(3), 0) == GRPC_CALL_OK); /* verify that all tags get completed */ cq_expect_client_metadata_read(cqv, tag(2), NULL); cq_expect_finished_with_status(cqv, tag(3), GRPC_STATUS_CANCELLED, NULL, diff --git a/test/core/end2end/tests/disappearing_server.c b/test/core/end2end/tests/disappearing_server.c index 1cbb15f32e..d30e9eae5f 100644 --- a/test/core/end2end/tests/disappearing_server.c +++ b/test/core/end2end/tests/disappearing_server.c @@ -100,8 +100,8 @@ static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f, c = grpc_channel_create_call(f->client, "/foo", "test.google.com", deadline); GPR_ASSERT(c); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(c, f->client_cq, - tag(2), tag(3), 0)); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_invoke(c, f->client_cq, tag(2), tag(3), 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done(c, tag(4))); cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK); diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index e2f30d0778..6e5cb1316b 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -189,10 +189,10 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, tag(100))); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(c1, f.client_cq, - tag(301), tag(302), 0)); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(c2, f.client_cq, - tag(401), tag(402), 0)); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_invoke(c1, f.client_cq, tag(301), tag(302), 0)); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_invoke(c2, f.client_cq, tag(401), tag(402), 0)); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done(c1, tag(303))); GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done(c2, tag(303))); diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c index c1b528cc3f..6e2e16714a 100644 --- a/test/core/end2end/tests/simple_delayed_request.c +++ b/test/core/end2end/tests/simple_delayed_request.c @@ -106,8 +106,8 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, c = grpc_channel_create_call(f->client, "/foo", "test.google.com", deadline); GPR_ASSERT(c); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(c, f->client_cq, - tag(2), tag(3), 0)); + GPR_ASSERT(GRPC_CALL_OK == + grpc_call_invoke(c, f->client_cq, tag(2), tag(3), 0)); config.init_server(f, server_args); diff --git a/test/core/end2end/tests/thread_stress.c b/test/core/end2end/tests/thread_stress.c index 65a7930c1c..4ce85df22e 100644 --- a/test/core/end2end/tests/thread_stress.c +++ b/test/core/end2end/tests/thread_stress.c @@ -118,9 +118,8 @@ static void start_request() { g_active_requests++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_invoke(call, g_fixture.client_cq, NULL, 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)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_read(call, NULL)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write(call, buf, NULL, 0)); grpc_byte_buffer_destroy(buf); } diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index 11d5e4a495..9b9f0202d6 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -62,8 +62,7 @@ int main(int argc, char **argv) { GPR_ASSERT(GRPC_CALL_OK == grpc_call_add_metadata(call, &md, 0)); /* and invoke the call */ - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_invoke(call, cq, tag(2), tag(3), 0)); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_invoke(call, cq, tag(2), tag(3), 0)); /* the call should immediately fail */ cq_expect_client_metadata_read(cqv, tag(2), NULL); -- cgit v1.2.3 From 2ba0dacbde45ed3a491d78134244b3175c556494 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Jan 2015 11:49:12 -0800 Subject: Update C++ code to set status via the C api. This prevents mismatches from breaking tests. --- include/grpc++/stream.h | 6 ++--- include/grpc++/stream_context_interface.h | 2 +- include/grpc/grpc.h | 8 +++++++ src/core/surface/call.c | 33 +++++++++++++++++++++------ src/cpp/stream/stream_context.cc | 38 +++++++++++-------------------- src/cpp/stream/stream_context.h | 4 ++-- third_party/libevent | 1 + 7 files changed, 54 insertions(+), 38 deletions(-) create mode 160000 third_party/libevent (limited to 'include') diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index 49f88a6f13..b8982f4d93 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -96,7 +96,7 @@ class ClientReader : public ClientStreamingInterface, virtual bool Read(R* msg) { return context_->Read(msg); } - virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); } + virtual void Cancel() { context_->Cancel(); } virtual const Status& Wait() { return context_->Wait(); } @@ -122,7 +122,7 @@ class ClientWriter : public ClientStreamingInterface, virtual void WritesDone() { context_->Write(nullptr, true); } - virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); } + virtual void Cancel() { context_->Cancel(); } // Read the final response and wait for the final status. virtual const Status& Wait() { @@ -165,7 +165,7 @@ class ClientReaderWriter : public ClientStreamingInterface, virtual void WritesDone() { context_->Write(nullptr, true); } - virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); } + virtual void Cancel() { context_->Cancel(); } virtual const Status& Wait() { return context_->Wait(); } diff --git a/include/grpc++/stream_context_interface.h b/include/grpc++/stream_context_interface.h index 535c0048e6..a84119800b 100644 --- a/include/grpc++/stream_context_interface.h +++ b/include/grpc++/stream_context_interface.h @@ -53,7 +53,7 @@ class StreamContextInterface { virtual bool Read(google::protobuf::Message* msg) = 0; virtual bool Write(const google::protobuf::Message* msg, bool is_last) = 0; virtual const Status& Wait() = 0; - virtual void FinishStream(const Status& status, bool send) = 0; + virtual void Cancel() = 0; virtual google::protobuf::Message* request() = 0; virtual google::protobuf::Message* response() = 0; diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index e51a1668e8..53e0d05630 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -369,6 +369,14 @@ grpc_call_error grpc_call_server_end_initial_metadata(grpc_call *call, Can be called multiple times, from any thread. */ 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. + If a status has not been received for the call, set it to the status code + 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); + /* Queue a byte buffer for writing. flags is a bit-field combination of the write flags defined above. A write with byte_buffer null is allowed, and will not send any bytes on the diff --git a/src/core/surface/call.c b/src/core/surface/call.c index ae6fa6336b..87e3de88e2 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -278,6 +278,19 @@ void grpc_call_destroy(grpc_call *c) { grpc_call_internal_unref(c); } +static void maybe_set_status_code(grpc_call *call, gpr_uint32 status) { + if (!call->got_status_code) { + call->status_code = status; + call->got_status_code = 1; + } +} + +static void maybe_set_status_details(grpc_call *call, grpc_mdstr *status) { + if (!call->status_details) { + call->status_details = grpc_mdstr_ref(status); + } +} + grpc_call_error grpc_call_cancel(grpc_call *c) { grpc_call_element *elem; grpc_call_op op; @@ -294,6 +307,17 @@ 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; + gpr_mu_lock(&c->read_mu); + maybe_set_status_code(c, status); + if (details) { + maybe_set_status_details(c, details); + } + gpr_mu_unlock(&c->read_mu); + return grpc_call_cancel(c); +} + void grpc_call_execute_op(grpc_call *call, grpc_call_op *op) { grpc_call_element *elem; GPR_ASSERT(op->dir == GRPC_CALL_DOWN); @@ -876,16 +900,11 @@ void grpc_call_recv_metadata(grpc_call_element *elem, grpc_call_op *op) { 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)); if (key == grpc_channel_get_status_string(call->channel)) { - if (!call->got_status_code) { - call->status_code = decode_status(md); - call->got_status_code = 1; - } + maybe_set_status_code(call, decode_status(md)); grpc_mdelem_unref(md); op->done_cb(op->user_data, GRPC_OP_OK); } else if (key == grpc_channel_get_message_string(call->channel)) { - if (!call->status_details) { - call->status_details = grpc_mdstr_ref(md->value); - } + maybe_set_status_details(call, md->value); grpc_mdelem_unref(md); op->done_cb(op->user_data, GRPC_OP_OK); } else { diff --git a/src/cpp/stream/stream_context.cc b/src/cpp/stream/stream_context.cc index 720f3e27fe..aec226b23c 100644 --- a/src/cpp/stream/stream_context.cc +++ b/src/cpp/stream/stream_context.cc @@ -105,9 +105,7 @@ bool StreamContext::Read(google::protobuf::Message* msg) { if (read_ev->data.read) { if (!DeserializeProto(read_ev->data.read, msg)) { ret = false; - FinishStream( - Status(StatusCode::DATA_LOSS, "Failed to parse incoming proto"), - true); + grpc_call_cancel_with_status(call(), GRPC_STATUS_DATA_LOSS, "Failed to parse incoming proto"); } } else { ret = false; @@ -125,9 +123,7 @@ bool StreamContext::Write(const google::protobuf::Message* msg, bool is_last) { if (msg) { grpc_byte_buffer* out_buf = nullptr; if (!SerializeProto(*msg, &out_buf)) { - FinishStream(Status(StatusCode::INVALID_ARGUMENT, - "Failed to serialize outgoing proto"), - true); + 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; @@ -165,29 +161,21 @@ const Status& StreamContext::Wait() { grpc_event_finish(metadata_ev); // TODO(yangg) protect states by a mutex, including other places. if (!self_halfclosed_ || !peer_halfclosed_) { - FinishStream(Status::Cancelled, true); - } else { - 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 - : ""); - grpc_event_finish(finish_ev); - } - return final_status_; -} - -void StreamContext::FinishStream(const Status& status, bool send) { - if (send) { - grpc_call_cancel(call()); - } + 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 + : ""); grpc_event_finish(finish_ev); - final_status_ = status; + return final_status_; +} + +void StreamContext::Cancel() { + grpc_call_cancel(call()); } } // namespace grpc diff --git a/src/cpp/stream/stream_context.h b/src/cpp/stream/stream_context.h index c1a8d8ae52..d6bd7a2370 100644 --- a/src/cpp/stream/stream_context.h +++ b/src/cpp/stream/stream_context.h @@ -48,7 +48,7 @@ namespace grpc { class ClientContext; class RpcMethod; -class StreamContext : public StreamContextInterface { +class StreamContext final : public StreamContextInterface { public: StreamContext(const RpcMethod& method, ClientContext* context, const google::protobuf::Message* request, @@ -63,7 +63,7 @@ class StreamContext : public StreamContextInterface { bool Read(google::protobuf::Message* msg) override; bool Write(const google::protobuf::Message* msg, bool is_last) override; const Status& Wait() override; - void FinishStream(const Status& status, bool send) override; + void Cancel() override; google::protobuf::Message* request() override { return request_; } google::protobuf::Message* response() override { return result_; } diff --git a/third_party/libevent b/third_party/libevent new file mode 160000 index 0000000000..f7d92c6392 --- /dev/null +++ b/third_party/libevent @@ -0,0 +1 @@ +Subproject commit f7d92c63928a1460f3d99b9bc418bd3b686a0dca -- cgit v1.2.3 From 09b637538f4e7e65d6d3994929f386a809317c21 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Jan 2015 13:02:09 -0800 Subject: 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(-) (limited to 'include') diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 53e0d05630..8ab3d25873 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 87e3de88e2..24c1567db9 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 223151932c..f476f77a49 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 aec226b23c..ebe71594c0 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 36da4950bb..3b571ebd08 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)); -- cgit v1.2.3 From 808632ed4b9757c79bfbb8917ec79ca4a4a614d0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Jan 2015 16:17:21 -0800 Subject: Remove grpc_call_start_invoke --- include/grpc/grpc.h | 7 ------- src/core/surface/call.c | 15 --------------- 2 files changed, 22 deletions(-) (limited to 'include') diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 8ab3d25873..f9a28e6f69 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -313,8 +313,6 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata, flags is a bit-field combination of the write flags defined above. REQUIRES: Can be called at most once per call. Can only be called on the client. - Produces a GRPC_INVOKE_ACCEPTED event with invoke_accepted_tag when the - call has been invoked (meaning bytes can start flowing to the wire). Produces a GRPC_CLIENT_METADATA_READ event with metadata_read_tag when the servers initial metadata has been read. Produces a GRPC_FINISHED event with finished_tag when the call has been @@ -323,11 +321,6 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata, grpc_call_error grpc_call_invoke(grpc_call *call, grpc_completion_queue *cq, void *metadata_read_tag, void *finished_tag, gpr_uint32 flags); -grpc_call_error grpc_call_start_invoke(grpc_call *call, - grpc_completion_queue *cq, - void *invoke_accepted_tag, - void *metadata_read_tag, - void *finished_tag, gpr_uint32 flags); /* DEPRECATED: users should use grpc_call_server_accept, and grpc_call_server_end_initial_metadata instead now. diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 6f8e0d5db7..eb39044e93 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -382,21 +382,6 @@ static void finish_call(grpc_call *call) { elements, count); } -grpc_call_error grpc_call_start_invoke(grpc_call *call, - grpc_completion_queue *cq, - void *invoke_accepted_tag, - void *metadata_read_tag, - void *finished_tag, gpr_uint32 flags) { - grpc_call_error err = - grpc_call_invoke(call, cq, metadata_read_tag, finished_tag, flags); - if (err == GRPC_CALL_OK) { - grpc_cq_begin_op(call->cq, call, GRPC_INVOKE_ACCEPTED); - grpc_cq_end_invoke_accepted(call->cq, invoke_accepted_tag, call, do_nothing, - NULL, GRPC_OP_OK); - } - return err; -} - static void done_write(void *user_data, grpc_op_error error) { grpc_call *call = user_data; void *tag = call->write_tag; -- cgit v1.2.3 From c0fc6a1f1fe54f0b83a7089bf65cff39d91e611f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 11:12:46 -0800 Subject: Add gpr_ltoa --- include/grpc/support/string.h | 7 +++++++ src/core/support/string.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'include') diff --git a/include/grpc/support/string.h b/include/grpc/support/string.h index 68e7452a7f..2ce19036f2 100644 --- a/include/grpc/support/string.h +++ b/include/grpc/support/string.h @@ -60,6 +60,13 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags); int gpr_parse_bytes_to_uint32(const char *data, size_t length, gpr_uint32 *result); +/* Convert a long to a string in base 10; returns the length of the + output string (or 0 on failure) */ +int gpr_ltoa(long value, char *output); + +/* Reverse a run of bytes */ +void gpr_reverse_bytes(char *str, int len); + /* printf to a newly-allocated string. The set of supported formats may vary between platforms. diff --git a/src/core/support/string.c b/src/core/support/string.c index 7960547735..7e84437fac 100644 --- a/src/core/support/string.c +++ b/src/core/support/string.c @@ -122,3 +122,33 @@ int gpr_parse_bytes_to_uint32(const char *buf, size_t len, gpr_uint32 *result) { *result = out; return 1; } + +void gpr_reverse_bytes(char *str, int len) { + char *p1, *p2; + for (p1 = str, p2 = str + len - 1; p2 > p1; ++p1, --p2) { + char temp = *p1; + *p1 = *p2; + *p2 = temp; + } +} + +int gpr_ltoa(long value, char *string) { + int i = 0; + int neg = value < 0; + + if (value == 0) { + string[0] = '0'; + string[1] = 0; + return 1; + } + + if (neg) value = -value; + while (value) { + string[i++] = '0' + value % 10; + value /= 10; + } + if (neg) string[i++] = '-'; + gpr_reverse_bytes(string, i); + string[i] = 0; + return i; +} -- cgit v1.2.3 From 1fa4e15f7e935b06f1fc6bb3613ab1eab7028c61 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 12:00:11 -0800 Subject: Add define --- include/grpc/support/string.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/grpc/support/string.h b/include/grpc/support/string.h index 2ce19036f2..71bd3f84e3 100644 --- a/include/grpc/support/string.h +++ b/include/grpc/support/string.h @@ -60,6 +60,9 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags); int gpr_parse_bytes_to_uint32(const char *data, size_t length, gpr_uint32 *result); +/* minimum buffer size for calling ltoa */ +#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long)) + /* Convert a long to a string in base 10; returns the length of the output string (or 0 on failure) */ int gpr_ltoa(long value, char *output); -- cgit v1.2.3 From 485d77628d0ce8889a420576d5bc41ccbbf48963 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 23 Jan 2015 12:54:05 -0800 Subject: Move string.h to internal code --- include/grpc/support/string.h | 87 ------------------------ src/core/channel/call_op_string.c | 2 +- src/core/channel/channel_args.c | 2 +- src/core/channel/client_channel.c | 2 +- src/core/channel/connected_channel.c | 2 +- src/core/httpcli/httpcli.c | 2 +- src/core/httpcli/httpcli_security_context.c | 2 +- src/core/iomgr/resolve_address_posix.c | 2 +- src/core/iomgr/sockaddr_utils.c | 2 +- src/core/iomgr/socket_utils_common_posix.c | 2 +- src/core/iomgr/tcp_posix.c | 2 +- src/core/security/credentials.c | 2 +- src/core/security/json_token.c | 2 +- src/core/security/secure_endpoint.c | 2 +- src/core/security/security_context.c | 2 +- src/core/statistics/census_rpc_stats.c | 2 +- src/core/statistics/census_tracing.c | 2 +- src/core/support/cmdline.c | 2 +- src/core/support/host_port.c | 2 +- src/core/support/string.c | 2 +- src/core/support/string.h | 87 ++++++++++++++++++++++++ src/core/surface/call.c | 2 +- src/core/surface/channel_create.c | 2 +- src/core/surface/client.c | 2 +- src/core/surface/completion_queue.c | 2 +- src/core/surface/event_string.c | 2 +- src/core/surface/lame_client.c | 2 +- src/core/surface/secure_channel_create.c | 2 +- src/core/surface/server.c | 2 +- src/core/transport/chttp2/frame_data.c | 2 +- src/core/transport/chttp2/hpack_parser.c | 2 +- src/core/transport/chttp2/timeout_encoding.c | 2 +- src/core/transport/chttp2_transport.c | 2 +- test/core/echo/echo_test.c | 2 +- test/core/echo/server.c | 2 +- test/core/end2end/cq_verifier.c | 2 +- test/core/fling/fling_stream_test.c | 2 +- test/core/fling/fling_test.c | 2 +- test/core/security/credentials_test.c | 2 +- test/core/support/string_test.c | 2 +- test/core/transport/chttp2/bin_encoder_test.c | 2 +- test/core/transport/chttp2/stream_encoder_test.c | 2 +- test/core/transport/transport_end2end_tests.c | 2 +- 43 files changed, 128 insertions(+), 128 deletions(-) delete mode 100644 include/grpc/support/string.h create mode 100644 src/core/support/string.h (limited to 'include') diff --git a/include/grpc/support/string.h b/include/grpc/support/string.h deleted file mode 100644 index 71bd3f84e3..0000000000 --- a/include/grpc/support/string.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * Copyright 2014, Google Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef __GRPC_SUPPORT_STRING_H__ -#define __GRPC_SUPPORT_STRING_H__ - -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* String utility functions */ - -/* Returns a copy of src that can be passed to gpr_free(). - If allocation fails or if src is NULL, returns NULL. */ -char *gpr_strdup(const char *src); - -/* flag to include plaintext after a hexdump */ -#define GPR_HEXDUMP_PLAINTEXT 0x00000001 - -/* Converts array buf, of length len, into a hexadecimal dump. Result should - be freed with gpr_free() */ -char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags); - -/* Parses an array of bytes into an integer (base 10). Returns 1 on success, - 0 on failure. */ -int gpr_parse_bytes_to_uint32(const char *data, size_t length, - gpr_uint32 *result); - -/* minimum buffer size for calling ltoa */ -#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long)) - -/* Convert a long to a string in base 10; returns the length of the - output string (or 0 on failure) */ -int gpr_ltoa(long value, char *output); - -/* Reverse a run of bytes */ -void gpr_reverse_bytes(char *str, int len); - -/* printf to a newly-allocated string. The set of supported formats may vary - between platforms. - - On success, returns the number of bytes printed (excluding the final '\0'), - and *strp points to a string which must later be destroyed with gpr_free(). - - On error, returns -1 and sets *strp to NULL. If the format string is bad, - the result is undefined. */ -int gpr_asprintf(char **strp, const char *format, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* __GRPC_SUPPORT_STRING_H__ */ diff --git a/src/core/channel/call_op_string.c b/src/core/channel/call_op_string.c index 9a7838ce2f..789913901a 100644 --- a/src/core/channel/call_op_string.c +++ b/src/core/channel/call_op_string.c @@ -37,8 +37,8 @@ #include #include +#include "src/core/support/string.h" #include -#include #include #define MAX_APPEND 1024 diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 36312e54de..04ce519ff3 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -33,9 +33,9 @@ #include #include "src/core/channel/channel_args.h" +#include "src/core/support/string.h" #include -#include #include diff --git a/src/core/channel/client_channel.c b/src/core/channel/client_channel.c index fa75561c78..f6078aa808 100644 --- a/src/core/channel/client_channel.c +++ b/src/core/channel/client_channel.c @@ -40,9 +40,9 @@ #include "src/core/channel/connected_channel.h" #include "src/core/channel/metadata_buffer.h" #include "src/core/iomgr/iomgr.h" +#include "src/core/support/string.h" #include #include -#include #include #include diff --git a/src/core/channel/connected_channel.c b/src/core/channel/connected_channel.c index e01cb81a89..cfa76f9e48 100644 --- a/src/core/channel/connected_channel.c +++ b/src/core/channel/connected_channel.c @@ -37,12 +37,12 @@ #include #include +#include "src/core/support/string.h" #include "src/core/transport/transport.h" #include #include #include #include -#include #define MAX_BUFFER_LENGTH 8192 /* the protobuf library will (by default) start warning at 100megs */ diff --git a/src/core/httpcli/httpcli.c b/src/core/httpcli/httpcli.c index 2143eeb63d..d6fd8ca865 100644 --- a/src/core/httpcli/httpcli.c +++ b/src/core/httpcli/httpcli.c @@ -44,9 +44,9 @@ #include "src/core/security/security_context.h" #include "src/core/security/google_root_certs.h" #include "src/core/security/secure_transport_setup.h" +#include "src/core/support/string.h" #include #include -#include typedef struct { gpr_slice request_text; diff --git a/src/core/httpcli/httpcli_security_context.c b/src/core/httpcli/httpcli_security_context.c index c7b9b330f0..d074e163f1 100644 --- a/src/core/httpcli/httpcli_security_context.c +++ b/src/core/httpcli/httpcli_security_context.c @@ -36,9 +36,9 @@ #include #include "src/core/security/secure_transport_setup.h" +#include "src/core/support/string.h" #include #include -#include #include "src/core/tsi/ssl_transport_security.h" typedef struct { diff --git a/src/core/iomgr/resolve_address_posix.c b/src/core/iomgr/resolve_address_posix.c index c9c2c5378a..f80eea7f46 100644 --- a/src/core/iomgr/resolve_address_posix.c +++ b/src/core/iomgr/resolve_address_posix.c @@ -44,9 +44,9 @@ #include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/socket_utils_posix.h" +#include "src/core/support/string.h" #include #include -#include #include #include diff --git a/src/core/iomgr/sockaddr_utils.c b/src/core/iomgr/sockaddr_utils.c index eca14a4f39..5bb1124284 100644 --- a/src/core/iomgr/sockaddr_utils.c +++ b/src/core/iomgr/sockaddr_utils.c @@ -37,8 +37,8 @@ #include #include +#include "src/core/support/string.h" #include -#include #include #include diff --git a/src/core/iomgr/socket_utils_common_posix.c b/src/core/iomgr/socket_utils_common_posix.c index 3a0639f356..1854285b5a 100644 --- a/src/core/iomgr/socket_utils_common_posix.c +++ b/src/core/iomgr/socket_utils_common_posix.c @@ -50,8 +50,8 @@ #include #include "src/core/iomgr/sockaddr_utils.h" +#include "src/core/support/string.h" #include -#include #include #include #include diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index 64996bd07d..a9b59df885 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -44,10 +44,10 @@ #include #include +#include "src/core/support/string.h" #include #include #include -#include #include #include diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 628963e46c..db73c01c1d 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -36,9 +36,9 @@ #include "src/core/httpcli/httpcli.h" #include "src/core/iomgr/iomgr.h" #include "src/core/security/json_token.h" +#include "src/core/support/string.h" #include #include -#include #include #include diff --git a/src/core/security/json_token.c b/src/core/security/json_token.c index 14ee758e8b..82bd9b505a 100644 --- a/src/core/security/json_token.c +++ b/src/core/security/json_token.c @@ -37,9 +37,9 @@ #include #include -#include #include "src/core/security/base64.h" +#include "src/core/support/string.h" #include #include diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c index e73767c1aa..9f12cf5d60 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -32,11 +32,11 @@ */ #include "src/core/security/secure_endpoint.h" +#include "src/core/support/string.h" #include #include #include #include -#include #include #include "src/core/tsi/transport_security_interface.h" diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c index cce3c7fe04..58cd458415 100644 --- a/src/core/security/security_context.c +++ b/src/core/security/security_context.c @@ -39,12 +39,12 @@ #include "src/core/channel/http_client_filter.h" #include "src/core/security/credentials.h" #include "src/core/security/secure_endpoint.h" +#include "src/core/support/string.h" #include "src/core/surface/lame_client.h" #include "src/core/transport/chttp2/alpn.h" #include #include #include -#include #include "src/core/tsi/fake_transport_security.h" #include "src/core/tsi/ssl_transport_security.h" diff --git a/src/core/statistics/census_rpc_stats.c b/src/core/statistics/census_rpc_stats.c index 39094b5f65..dd3c07e80b 100644 --- a/src/core/statistics/census_rpc_stats.c +++ b/src/core/statistics/census_rpc_stats.c @@ -39,9 +39,9 @@ #include "src/core/statistics/census_tracing.h" #include "src/core/statistics/window_stats.h" #include "src/core/support/murmur_hash.h" +#include "src/core/support/string.h" #include #include -#include #include #define NUM_INTERVALS 3 diff --git a/src/core/statistics/census_tracing.c b/src/core/statistics/census_tracing.c index 1e61602071..3c4ba66f5f 100644 --- a/src/core/statistics/census_tracing.c +++ b/src/core/statistics/census_tracing.c @@ -38,10 +38,10 @@ #include "src/core/statistics/census_rpc_stats.h" #include "src/core/statistics/hash_table.h" +#include "src/core/support/string.h" #include #include #include -#include #include #include diff --git a/src/core/support/cmdline.c b/src/core/support/cmdline.c index ff163a1f6c..a55da9dd18 100644 --- a/src/core/support/cmdline.c +++ b/src/core/support/cmdline.c @@ -37,9 +37,9 @@ #include #include +#include "src/core/support/string.h" #include #include -#include typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype; diff --git a/src/core/support/host_port.c b/src/core/support/host_port.c index 02500551fc..446c11ebec 100644 --- a/src/core/support/host_port.c +++ b/src/core/support/host_port.c @@ -35,8 +35,8 @@ #include +#include "src/core/support/string.h" #include -#include int gpr_join_host_port(char **out, const char *host, int port) { if (host[0] != '[' && strchr(host, ':') != NULL) { diff --git a/src/core/support/string.c b/src/core/support/string.c index 7e84437fac..9b5cac7596 100644 --- a/src/core/support/string.c +++ b/src/core/support/string.c @@ -31,7 +31,7 @@ * */ -#include +#include "src/core/support/string.h" #include #include diff --git a/src/core/support/string.h b/src/core/support/string.h new file mode 100644 index 0000000000..71bd3f84e3 --- /dev/null +++ b/src/core/support/string.h @@ -0,0 +1,87 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __GRPC_SUPPORT_STRING_H__ +#define __GRPC_SUPPORT_STRING_H__ + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* String utility functions */ + +/* Returns a copy of src that can be passed to gpr_free(). + If allocation fails or if src is NULL, returns NULL. */ +char *gpr_strdup(const char *src); + +/* flag to include plaintext after a hexdump */ +#define GPR_HEXDUMP_PLAINTEXT 0x00000001 + +/* Converts array buf, of length len, into a hexadecimal dump. Result should + be freed with gpr_free() */ +char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags); + +/* Parses an array of bytes into an integer (base 10). Returns 1 on success, + 0 on failure. */ +int gpr_parse_bytes_to_uint32(const char *data, size_t length, + gpr_uint32 *result); + +/* minimum buffer size for calling ltoa */ +#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long)) + +/* Convert a long to a string in base 10; returns the length of the + output string (or 0 on failure) */ +int gpr_ltoa(long value, char *output); + +/* Reverse a run of bytes */ +void gpr_reverse_bytes(char *str, int len); + +/* printf to a newly-allocated string. The set of supported formats may vary + between platforms. + + On success, returns the number of bytes printed (excluding the final '\0'), + and *strp points to a string which must later be destroyed with gpr_free(). + + On error, returns -1 and sets *strp to NULL. If the format string is bad, + the result is undefined. */ +int gpr_asprintf(char **strp, const char *format, ...); + +#ifdef __cplusplus +} +#endif + +#endif /* __GRPC_SUPPORT_STRING_H__ */ diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 46502fb6b1..1786523db2 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -35,11 +35,11 @@ #include "src/core/channel/channel_stack.h" #include "src/core/channel/metadata_buffer.h" #include "src/core/iomgr/alarm.h" +#include "src/core/support/string.h" #include "src/core/surface/channel.h" #include "src/core/surface/completion_queue.h" #include #include -#include #include #include diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index 41093d78ef..6939b92c60 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -48,10 +48,10 @@ #include "src/core/iomgr/tcp_client.h" #include "src/core/surface/channel.h" #include "src/core/surface/client.h" +#include "src/core/support/string.h" #include "src/core/transport/chttp2_transport.h" #include #include -#include #include #include diff --git a/src/core/surface/client.c b/src/core/surface/client.c index 74c79bdf9b..fe3a81f1b9 100644 --- a/src/core/surface/client.c +++ b/src/core/surface/client.c @@ -34,9 +34,9 @@ #include "src/core/surface/client.h" #include "src/core/surface/call.h" +#include "src/core/support/string.h" #include #include -#include typedef struct { void *unused; } call_data; diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 652f23e888..e1cc114cda 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -37,13 +37,13 @@ #include #include "src/core/iomgr/pollset.h" +#include "src/core/support/string.h" #include "src/core/surface/call.h" #include "src/core/surface/event_string.h" #include "src/core/surface/surface_trace.h" #include #include #include -#include #define NUM_TAG_BUCKETS 31 diff --git a/src/core/surface/event_string.c b/src/core/surface/event_string.c index 8ae2af7472..e38ef06c9f 100644 --- a/src/core/surface/event_string.c +++ b/src/core/surface/event_string.c @@ -35,7 +35,7 @@ #include -#include +#include "src/core/support/string.h" #include static size_t addhdr(char *p, grpc_event *ev) { diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c index a5244dbe61..056c98646b 100644 --- a/src/core/surface/lame_client.c +++ b/src/core/surface/lame_client.c @@ -36,11 +36,11 @@ #include #include "src/core/channel/channel_stack.h" +#include "src/core/support/string.h" #include "src/core/surface/channel.h" #include "src/core/surface/call.h" #include #include -#include typedef struct { void *unused; } call_data; diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index 3d5727927d..a231b2708e 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -48,13 +48,13 @@ #include "src/core/security/auth.h" #include "src/core/security/security_context.h" #include "src/core/security/secure_transport_setup.h" +#include "src/core/support/string.h" #include "src/core/surface/channel.h" #include "src/core/surface/client.h" #include "src/core/transport/chttp2_transport.h" #include #include #include -#include #include #include #include "src/core/tsi/transport_security_interface.h" diff --git a/src/core/surface/server.c b/src/core/surface/server.c index cbdd3bfa30..9585e4e8ea 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -40,12 +40,12 @@ #include "src/core/channel/channel_args.h" #include "src/core/channel/connected_channel.h" #include "src/core/iomgr/iomgr.h" +#include "src/core/support/string.h" #include "src/core/surface/call.h" #include "src/core/surface/channel.h" #include "src/core/surface/completion_queue.h" #include #include -#include #include typedef enum { PENDING_START, ALL_CALLS, CALL_LIST_COUNT } call_list; diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c index 00b020b31b..dee61cee50 100644 --- a/src/core/transport/chttp2/frame_data.c +++ b/src/core/transport/chttp2/frame_data.c @@ -35,9 +35,9 @@ #include +#include "src/core/support/string.h" #include #include -#include #include #include "src/core/transport/transport.h" diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index 64e08ffac7..c98b90e5d1 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -38,10 +38,10 @@ #include #include "src/core/transport/chttp2/bin_encoder.h" +#include "src/core/support/string.h" #include #include #include -#include #include typedef enum { diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 7217afa478..23c4554cf2 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -36,7 +36,7 @@ #include #include -#include +#include "src/core/support/string.h" static int round_up(int x, int divisor) { return (x / divisor + (x % divisor != 0)) * divisor; diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index 17b37d6d4a..6dfffa1fc5 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -37,6 +37,7 @@ #include #include +#include "src/core/support/string.h" #include "src/core/transport/chttp2/frame_data.h" #include "src/core/transport/chttp2/frame_goaway.h" #include "src/core/transport/chttp2/frame_ping.h" @@ -53,7 +54,6 @@ #include #include #include -#include #include #define DEFAULT_WINDOW 65535 diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c index 16d381fb65..6449b2414f 100644 --- a/test/core/echo/echo_test.c +++ b/test/core/echo/echo_test.c @@ -42,10 +42,10 @@ #include #include "src/core/iomgr/socket_utils_posix.h" +#include "src/core/support/string.h" #include #include #include -#include #include "test/core/util/port.h" int test_client(const char *root, const char *host, int port) { diff --git a/test/core/echo/server.c b/test/core/echo/server.c index 35f118dc9b..57b083779c 100644 --- a/test/core/echo/server.c +++ b/test/core/echo/server.c @@ -39,11 +39,11 @@ #include #include +#include "src/core/support/string.h" #include "test/core/util/test_config.h" #include #include #include -#include #include #include "test/core/util/port.h" diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 7a7f197907..37a7f7e32c 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -45,10 +45,10 @@ #include #include "src/core/surface/event_string.h" +#include "src/core/support/string.h" #include #include #include -#include #include #include diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c index f6fe69824b..7f52fb1bad 100644 --- a/test/core/fling/fling_stream_test.c +++ b/test/core/fling/fling_stream_test.c @@ -41,9 +41,9 @@ #include #include +#include "src/core/support/string.h" #include #include -#include #include "test/core/util/port.h" int main(int argc, char **argv) { diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c index 4607aa5f98..b2272f20c8 100644 --- a/test/core/fling/fling_test.c +++ b/test/core/fling/fling_test.c @@ -43,7 +43,7 @@ #include #include -#include +#include "src/core/support/string.h" #include "test/core/util/port.h" int main(int argc, char **argv) { diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index 9c60f4c233..ec21e0d42f 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -37,9 +37,9 @@ #include "src/core/httpcli/httpcli.h" #include "src/core/security/json_token.h" +#include "src/core/support/string.h" #include #include -#include #include #include "test/core/util/test_config.h" #include diff --git a/test/core/support/string_test.c b/test/core/support/string_test.c index e87a606aba..a01ec6f87f 100644 --- a/test/core/support/string_test.c +++ b/test/core/support/string_test.c @@ -31,7 +31,7 @@ * */ -#include +#include "src/core/support/string.h" #include #include diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c index ea24f5cbd7..048ed7edd3 100644 --- a/test/core/transport/chttp2/bin_encoder_test.c +++ b/test/core/transport/chttp2/bin_encoder_test.c @@ -35,9 +35,9 @@ #include +#include "src/core/support/string.h" #include #include -#include static int all_ok = 1; diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index cebc2634fb..eb0f688f58 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -35,10 +35,10 @@ #include +#include "src/core/support/string.h" #include "src/core/transport/chttp2/hpack_parser.h" #include #include -#include #include "test/core/util/parse_hexstring.h" #include "test/core/util/slice_splitter.h" #include "test/core/util/test_config.h" diff --git a/test/core/transport/transport_end2end_tests.c b/test/core/transport/transport_end2end_tests.c index 5d26ef53b9..8e9b4a2cc9 100644 --- a/test/core/transport/transport_end2end_tests.c +++ b/test/core/transport/transport_end2end_tests.c @@ -37,10 +37,10 @@ #include #include +#include "src/core/support/string.h" #include "src/core/transport/transport.h" #include #include -#include #include #include -- cgit v1.2.3