diff options
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | build.json | 2 | ||||
-rw-r--r-- | include/grpc/grpc.h | 12 | ||||
-rw-r--r-- | src/core/surface/call_details.c | 13 | ||||
-rw-r--r-- | src/core/surface/metadata_array.c | 17 | ||||
-rw-r--r-- | src/core/surface/server.c | 2 | ||||
-rw-r--r-- | test/core/end2end/cq_verifier.c | 4 | ||||
-rw-r--r-- | test/core/end2end/cq_verifier.h | 1 | ||||
-rw-r--r-- | test/core/end2end/tests/simple_request.c | 127 | ||||
-rw-r--r-- | vsprojects/vs2013/grpc.vcxproj | 4 | ||||
-rw-r--r-- | vsprojects/vs2013/grpc.vcxproj.filters | 6 | ||||
-rw-r--r-- | vsprojects/vs2013/grpc_unsecure.vcxproj | 4 | ||||
-rw-r--r-- | vsprojects/vs2013/grpc_unsecure.vcxproj.filters | 6 |
13 files changed, 122 insertions, 86 deletions
@@ -1834,6 +1834,7 @@ LIBGRPC_SRC = \ src/core/surface/byte_buffer_queue.c \ src/core/surface/byte_buffer_reader.c \ src/core/surface/call.c \ + src/core/surface/call_details.c \ src/core/surface/channel.c \ src/core/surface/channel_create.c \ src/core/surface/client.c \ @@ -1841,6 +1842,7 @@ LIBGRPC_SRC = \ src/core/surface/event_string.c \ src/core/surface/init.c \ src/core/surface/lame_client.c \ + src/core/surface/metadata_array.c \ src/core/surface/secure_channel_create.c \ src/core/surface/secure_server_create.c \ src/core/surface/server.c \ @@ -1961,6 +1963,7 @@ src/core/surface/byte_buffer.c: $(OPENSSL_DEP) src/core/surface/byte_buffer_queue.c: $(OPENSSL_DEP) src/core/surface/byte_buffer_reader.c: $(OPENSSL_DEP) src/core/surface/call.c: $(OPENSSL_DEP) +src/core/surface/call_details.c: $(OPENSSL_DEP) src/core/surface/channel.c: $(OPENSSL_DEP) src/core/surface/channel_create.c: $(OPENSSL_DEP) src/core/surface/client.c: $(OPENSSL_DEP) @@ -1968,6 +1971,7 @@ src/core/surface/completion_queue.c: $(OPENSSL_DEP) src/core/surface/event_string.c: $(OPENSSL_DEP) src/core/surface/init.c: $(OPENSSL_DEP) src/core/surface/lame_client.c: $(OPENSSL_DEP) +src/core/surface/metadata_array.c: $(OPENSSL_DEP) src/core/surface/secure_channel_create.c: $(OPENSSL_DEP) src/core/surface/secure_server_create.c: $(OPENSSL_DEP) src/core/surface/server.c: $(OPENSSL_DEP) @@ -2110,6 +2114,7 @@ objs/$(CONFIG)/src/core/surface/byte_buffer.o: objs/$(CONFIG)/src/core/surface/byte_buffer_queue.o: objs/$(CONFIG)/src/core/surface/byte_buffer_reader.o: objs/$(CONFIG)/src/core/surface/call.o: +objs/$(CONFIG)/src/core/surface/call_details.o: objs/$(CONFIG)/src/core/surface/channel.o: objs/$(CONFIG)/src/core/surface/channel_create.o: objs/$(CONFIG)/src/core/surface/client.o: @@ -2117,6 +2122,7 @@ objs/$(CONFIG)/src/core/surface/completion_queue.o: objs/$(CONFIG)/src/core/surface/event_string.o: objs/$(CONFIG)/src/core/surface/init.o: objs/$(CONFIG)/src/core/surface/lame_client.o: +objs/$(CONFIG)/src/core/surface/metadata_array.o: objs/$(CONFIG)/src/core/surface/secure_channel_create.o: objs/$(CONFIG)/src/core/surface/secure_server_create.o: objs/$(CONFIG)/src/core/surface/server.o: @@ -2278,6 +2284,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/surface/byte_buffer_queue.c \ src/core/surface/byte_buffer_reader.c \ src/core/surface/call.c \ + src/core/surface/call_details.c \ src/core/surface/channel.c \ src/core/surface/channel_create.c \ src/core/surface/client.c \ @@ -2285,6 +2292,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/surface/event_string.c \ src/core/surface/init.c \ src/core/surface/lame_client.c \ + src/core/surface/metadata_array.c \ src/core/surface/secure_channel_create.c \ src/core/surface/secure_server_create.c \ src/core/surface/server.c \ @@ -2410,6 +2418,7 @@ objs/$(CONFIG)/src/core/surface/byte_buffer.o: objs/$(CONFIG)/src/core/surface/byte_buffer_queue.o: objs/$(CONFIG)/src/core/surface/byte_buffer_reader.o: objs/$(CONFIG)/src/core/surface/call.o: +objs/$(CONFIG)/src/core/surface/call_details.o: objs/$(CONFIG)/src/core/surface/channel.o: objs/$(CONFIG)/src/core/surface/channel_create.o: objs/$(CONFIG)/src/core/surface/client.o: @@ -2417,6 +2426,7 @@ objs/$(CONFIG)/src/core/surface/completion_queue.o: objs/$(CONFIG)/src/core/surface/event_string.o: objs/$(CONFIG)/src/core/surface/init.o: objs/$(CONFIG)/src/core/surface/lame_client.o: +objs/$(CONFIG)/src/core/surface/metadata_array.o: objs/$(CONFIG)/src/core/surface/secure_channel_create.o: objs/$(CONFIG)/src/core/surface/secure_server_create.o: objs/$(CONFIG)/src/core/surface/server.o: diff --git a/build.json b/build.json index 291c7e6f53..03a421f714 100644 --- a/build.json +++ b/build.json @@ -163,6 +163,7 @@ "src/core/surface/byte_buffer_queue.c", "src/core/surface/byte_buffer_reader.c", "src/core/surface/call.c", + "src/core/surface/call_details.c", "src/core/surface/channel.c", "src/core/surface/channel_create.c", "src/core/surface/client.c", @@ -170,6 +171,7 @@ "src/core/surface/event_string.c", "src/core/surface/init.c", "src/core/surface/lame_client.c", + "src/core/surface/metadata_array.c", "src/core/surface/secure_channel_create.c", "src/core/surface/secure_server_create.c", "src/core/surface/server.c", diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index b4e87a0c20..f628f58364 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -239,14 +239,20 @@ typedef struct { grpc_metadata *metadata; } grpc_metadata_array; +void grpc_metadata_array_init(grpc_metadata_array *array); +void grpc_metadata_array_destroy(grpc_metadata_array *array); + typedef struct { - const char *method; + char *method; size_t method_capacity; - const char *host; + char *host; size_t host_capacity; gpr_timespec deadline; } grpc_call_details; +void grpc_call_details_init(grpc_call_details *details); +void grpc_call_details_destroy(grpc_call_details *details); + typedef enum { GRPC_OP_SEND_INITIAL_METADATA = 0, GRPC_OP_SEND_MESSAGE, @@ -486,7 +492,7 @@ grpc_call_error grpc_server_request_call_old(grpc_server *server, void *tag_new); grpc_call_error grpc_server_request_call( - grpc_server *server, grpc_call_details *details, + grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *request_metadata, grpc_completion_queue *completion_queue, void *tag_new); diff --git a/src/core/surface/call_details.c b/src/core/surface/call_details.c new file mode 100644 index 0000000000..51c05da640 --- /dev/null +++ b/src/core/surface/call_details.c @@ -0,0 +1,13 @@ +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> + +#include <string.h> + +void grpc_call_details_init(grpc_call_details *cd) { + memset(cd, 0, sizeof(*cd)); +} + +void grpc_call_details_destroy(grpc_call_details *cd) { + gpr_free(cd->method); + gpr_free(cd->host); +} diff --git a/src/core/surface/metadata_array.c b/src/core/surface/metadata_array.c new file mode 100644 index 0000000000..257ff1f820 --- /dev/null +++ b/src/core/surface/metadata_array.c @@ -0,0 +1,17 @@ +#include <grpc/grpc.h> +#include <grpc/support/alloc.h> + +#include <string.h> + +void grpc_metadata_array_init(grpc_metadata_array *array) { + memset(array, 0, sizeof(*array)); +} + +void grpc_metadata_array_destroy(grpc_metadata_array *array) { + size_t i; + for (i = 0; i < array->count; i++) { + gpr_free(array->metadata[i].key); + gpr_free(array->metadata[i].value); + } + gpr_free(array->metadata); +} diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 4cba41d1f8..60eeab68b0 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -711,7 +711,7 @@ static void begin_request(grpc_server *server, grpc_completion_queue *cq, abort(); } -grpc_call_error grpc_server_request_call(grpc_server *server, +grpc_call_error grpc_server_request_call(grpc_server *server, grpc_call **call, grpc_call_details *details, grpc_metadata_array *initial_metadata, grpc_completion_queue *cq, void *tag) { diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 955bab6265..e7c42b1d60 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -424,6 +424,10 @@ void cq_expect_write_accepted(cq_verifier *v, void *tag, grpc_op_error result) { add(v, GRPC_WRITE_ACCEPTED, tag)->data.write_accepted = result; } +void cq_expect_completion(cq_verifier *v, void *tag, grpc_op_error result) { + add(v, GRPC_OP_COMPLETE, tag)->data.op_complete = result; +} + void cq_expect_finish_accepted(cq_verifier *v, void *tag, grpc_op_error result) { add(v, GRPC_FINISH_ACCEPTED, tag)->data.finish_accepted = result; diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h index 6e031d8152..c936912864 100644 --- a/test/core/end2end/cq_verifier.h +++ b/test/core/end2end/cq_verifier.h @@ -60,6 +60,7 @@ void cq_expect_write_accepted(cq_verifier *v, void *tag, grpc_op_error result); void cq_expect_finish_accepted(cq_verifier *v, void *tag, grpc_op_error result); void cq_expect_read(cq_verifier *v, void *tag, gpr_slice bytes); void cq_expect_empty_read(cq_verifier *v, void *tag); +void cq_expect_completion(cq_verifier *v, void *tag, grpc_op_error result); /* *output_call is set the the server call instance */ void cq_expect_server_rpc_new(cq_verifier *v, grpc_call **output_call, void *tag, const char *method, const char *host, diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index 4204ee3af7..f51db8cc08 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -39,6 +39,7 @@ #include "src/core/support/string.h" #include <grpc/byte_buffer.h> +#include <grpc/grpc.h> #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include <grpc/support/time.h> @@ -109,19 +110,22 @@ static void simple_request_body(grpc_end2end_test_fixture f) { gpr_timespec deadline = five_seconds_time(); cq_verifier *v_client = cq_verifier_create(f.client_cq); cq_verifier *v_server = cq_verifier_create(f.server_cq); - grpc_op ops[4]; + grpc_op ops[6]; grpc_op *op; + grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_metadata_array request_metadata_recv; grpc_call_details call_details; grpc_status_code status; char *details = NULL; size_t details_capacity = NULL; + int was_cancelled = 2; c = grpc_channel_create_call(f.client, f.client_cq, "/foo", "test.google.com", - deadline); + deadline); GPR_ASSERT(c); + grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); grpc_metadata_array_init(&request_metadata_recv); grpc_call_details_init(&call_details); @@ -130,86 +134,54 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op++; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = &trailing_metadata; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op++; - GPR_ASSERT(GRPC_CALL_OK == grpc_call_send_batch(call, ops, op - ops, tag(1))); - GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &call_details, &request_metadata_recv, f.server_cq, tag(101))); - cq_expect_ - - GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100))); - cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com", - deadline, NULL); - cq_verify(v_server); - - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_server_accept_old(s, f.server_cq, tag(102))); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0)); - cq_expect_client_metadata_read(v_client, tag(2), NULL); - cq_verify(v_client); - - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old( - s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5))); - cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED, - "xyz", NULL); - cq_verify(v_client); + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(c, ops, op - ops, tag(1))); - cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK); - cq_expect_finished(v_server, tag(102), NULL); + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(f.server, &s, + &call_details, + &request_metadata_recv, + f.server_cq, tag(101))); + cq_expect_completion(v_server, tag(101), GRPC_OP_OK); cq_verify(v_server); - grpc_call_destroy(c); - grpc_call_destroy(s); - - cq_verifier_destroy(v_client); - cq_verifier_destroy(v_server); -} - -/* an alternative ordering of the simple request body */ -static void simple_request_body2(grpc_end2end_test_fixture f) { - grpc_call *c; - grpc_call *s; - gpr_timespec deadline = five_seconds_time(); - cq_verifier *v_client = cq_verifier_create(f.client_cq); - cq_verifier *v_server = cq_verifier_create(f.server_cq); - - c = grpc_channel_create_call_old(f.client, "/foo", "test.google.com", - deadline); - GPR_ASSERT(c); - - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_invoke_old(c, f.client_cq, tag(2), tag(3), 0)); - - GPR_ASSERT(GRPC_CALL_OK == grpc_call_writes_done_old(c, tag(4))); - cq_expect_finish_accepted(v_client, tag(4), GRPC_OP_OK); - cq_verify(v_client); - - GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call_old(f.server, tag(100))); - cq_expect_server_rpc_new(v_server, &s, tag(100), "/foo", "test.google.com", - deadline, NULL); - cq_verify(v_server); - - GPR_ASSERT(GRPC_CALL_OK == - grpc_call_server_accept_old(s, f.server_cq, tag(102))); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_server_end_initial_metadata_old(s, 0)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; + op->data.send_status_from_server.status_details = "xyz"; + op++; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op++; + GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(s, ops, op - ops, tag(102))); - GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_write_status_old( - s, GRPC_STATUS_UNIMPLEMENTED, "xyz", tag(5))); + cq_expect_completion(v_server, tag(102), GRPC_OP_OK); cq_verify(v_server); - cq_expect_client_metadata_read(v_client, tag(2), NULL); - cq_expect_finished_with_status(v_client, tag(3), GRPC_STATUS_UNIMPLEMENTED, - "xyz", NULL); + cq_expect_completion(v_client, tag(1), GRPC_OP_OK); cq_verify(v_client); - cq_expect_finish_accepted(v_server, tag(5), GRPC_OP_OK); - cq_expect_finished(v_server, tag(102), NULL); - cq_verify(v_server); + GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.host, "test.google.com")); + GPR_ASSERT(was_cancelled == 0); + GPR_ASSERT(initial_metadata_recv.count == 0); + GPR_ASSERT(trailing_metadata_recv.count == 0); + GPR_ASSERT(request_metadata_recv.count == 0); grpc_call_destroy(c); grpc_call_destroy(s); @@ -218,19 +190,13 @@ static void simple_request_body2(grpc_end2end_test_fixture f) { cq_verifier_destroy(v_server); } -static void test_invoke_simple_request( - grpc_end2end_test_config config, const char *name, - void (*body)(grpc_end2end_test_fixture f)) { - char *fullname; +static void test_invoke_simple_request(grpc_end2end_test_config config) { grpc_end2end_test_fixture f; - gpr_asprintf(&fullname, "%s/%s", __FUNCTION__, name); - - f = begin_test(config, fullname, NULL, NULL); - body(f); + f = begin_test(config, __FUNCTION__, NULL, NULL); + simple_request_body(f); end_test(&f); config.tear_down_data(&f); - gpr_free(fullname); } static void test_invoke_10_simple_requests(grpc_end2end_test_config config) { @@ -245,9 +211,6 @@ static void test_invoke_10_simple_requests(grpc_end2end_test_config config) { } void grpc_end2end_tests(grpc_end2end_test_config config) { - test_invoke_simple_request(config, "simple_request_body", - simple_request_body); - test_invoke_simple_request(config, "simple_request_body2", - simple_request_body2); + test_invoke_simple_request(config); test_invoke_10_simple_requests(config); } diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj index 8c12b2daf0..c6f2846e31 100644 --- a/vsprojects/vs2013/grpc.vcxproj +++ b/vsprojects/vs2013/grpc.vcxproj @@ -319,6 +319,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\surface\call.c"> </ClCompile> + <ClCompile Include="..\..\src\core\surface\call_details.c"> + </ClCompile> <ClCompile Include="..\..\src\core\surface\channel.c"> </ClCompile> <ClCompile Include="..\..\src\core\surface\channel_create.c"> @@ -333,6 +335,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\surface\lame_client.c"> </ClCompile> + <ClCompile Include="..\..\src\core\surface\metadata_array.c"> + </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_channel_create.c"> </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_server_create.c"> diff --git a/vsprojects/vs2013/grpc.vcxproj.filters b/vsprojects/vs2013/grpc.vcxproj.filters index 62f0b60c85..ce76dd8d2b 100644 --- a/vsprojects/vs2013/grpc.vcxproj.filters +++ b/vsprojects/vs2013/grpc.vcxproj.filters @@ -211,6 +211,9 @@ <ClCompile Include="..\..\src\core\surface\call.c"> <Filter>src\core\surface</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\surface\call_details.c"> + <Filter>src\core\surface</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\surface\channel.c"> <Filter>src\core\surface</Filter> </ClCompile> @@ -232,6 +235,9 @@ <ClCompile Include="..\..\src\core\surface\lame_client.c"> <Filter>src\core\surface</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\surface\metadata_array.c"> + <Filter>src\core\surface</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_channel_create.c"> <Filter>src\core\surface</Filter> </ClCompile> diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj b/vsprojects/vs2013/grpc_unsecure.vcxproj index 8c12b2daf0..c6f2846e31 100644 --- a/vsprojects/vs2013/grpc_unsecure.vcxproj +++ b/vsprojects/vs2013/grpc_unsecure.vcxproj @@ -319,6 +319,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\surface\call.c"> </ClCompile> + <ClCompile Include="..\..\src\core\surface\call_details.c"> + </ClCompile> <ClCompile Include="..\..\src\core\surface\channel.c"> </ClCompile> <ClCompile Include="..\..\src\core\surface\channel_create.c"> @@ -333,6 +335,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\surface\lame_client.c"> </ClCompile> + <ClCompile Include="..\..\src\core\surface\metadata_array.c"> + </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_channel_create.c"> </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_server_create.c"> diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters index 5ed5e9b9b6..0e942219d0 100644 --- a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters @@ -172,6 +172,9 @@ <ClCompile Include="..\..\src\core\surface\call.c"> <Filter>src\core\surface</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\surface\call_details.c"> + <Filter>src\core\surface</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\surface\channel.c"> <Filter>src\core\surface</Filter> </ClCompile> @@ -193,6 +196,9 @@ <ClCompile Include="..\..\src\core\surface\lame_client.c"> <Filter>src\core\surface</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\surface\metadata_array.c"> + <Filter>src\core\surface</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\surface\secure_channel_create.c"> <Filter>src\core\surface</Filter> </ClCompile> |