From 7cc2c309f3615a365a0ce0f19d8dac1a42b34c4c Mon Sep 17 00:00:00 2001 From: vjpai Date: Wed, 18 Feb 2015 12:33:37 -0800 Subject: Mac-specific Makefile inclusions and installation instructions Not yet fully building due to some gtest anomalies on Mac. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 485042b5b3..97a00e0a1a 100644 --- a/Makefile +++ b/Makefile @@ -177,7 +177,9 @@ LDFLAGS += -g -fPIC INCLUDES = . include $(GENDIR) ifeq ($(SYSTEM),Darwin) +INCLUDES += /usr/local/ssl/include /opt/local/include LIBS = m z +LDFLAGS += -L/usr/local/ssl/lib -L/opt/local/lib else LIBS = rt m z pthread LDFLAGS += -pthread -- cgit v1.2.3 From 3a5e5495e53868378a0c46e16990671f2fab565d Mon Sep 17 00:00:00 2001 From: Yang Gao Date: Wed, 18 Feb 2015 14:32:38 -0800 Subject: Async client api change. Add a ClientAsyncResponseReader. Make the api similar to streaming and symmetric to server side. --- Makefile | 1 + build.json | 1 + include/grpc++/async_unary_call.h | 144 ++++++++++++++++++++++++++++++++ include/grpc++/client_context.h | 4 + include/grpc++/impl/client_unary_call.h | 7 -- include/grpc++/stream.h | 54 ------------ src/compiler/cpp_generator.cc | 22 +++-- src/cpp/client/client_unary_call.cc | 26 ------ test/cpp/end2end/async_end2end_test.cc | 82 +++++++++++------- 9 files changed, 213 insertions(+), 128 deletions(-) create mode 100644 include/grpc++/async_unary_call.h (limited to 'Makefile') diff --git a/Makefile b/Makefile index 58bbc7a783..3794d943f6 100644 --- a/Makefile +++ b/Makefile @@ -2978,6 +2978,7 @@ LIBGRPC++_SRC = \ src/cpp/util/time.cc \ PUBLIC_HEADERS_CXX += \ + include/grpc++/async_unary_call.h \ include/grpc++/channel_arguments.h \ include/grpc++/channel_interface.h \ include/grpc++/client_context.h \ diff --git a/build.json b/build.json index 07af69126b..a980e94687 100644 --- a/build.json +++ b/build.json @@ -398,6 +398,7 @@ "build": "all", "language": "c++", "public_headers": [ + "include/grpc++/async_unary_call.h", "include/grpc++/channel_arguments.h", "include/grpc++/channel_interface.h", "include/grpc++/client_context.h", diff --git a/include/grpc++/async_unary_call.h b/include/grpc++/async_unary_call.h new file mode 100644 index 0000000000..2c437960cb --- /dev/null +++ b/include/grpc++/async_unary_call.h @@ -0,0 +1,144 @@ +/* + * + * 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 __GRPCPP_ASYNC_UNARY_CALL_H__ +#define __GRPCPP_ASYNC_UNARY_CALL_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace grpc { +template +class ClientAsyncResponseReader final { + public: + ClientAsyncResponseReader(ChannelInterface* channel, CompletionQueue* cq, + const RpcMethod& method, ClientContext* context, + const google::protobuf::Message& request, void* tag) + : context_(context), + call_(channel->CreateCall(method, context, cq)) { + init_buf_.Reset(tag); + init_buf_.AddSendInitialMetadata(&context->send_initial_metadata_); + init_buf_.AddSendMessage(request); + init_buf_.AddClientSendClose(); + call_.PerformOps(&init_buf_); + } + + void ReadInitialMetadata(void* tag) { + GPR_ASSERT(!context_->initial_metadata_received_); + + meta_buf_.Reset(tag); + meta_buf_.AddRecvInitialMetadata(context_); + call_.PerformOps(&meta_buf_); + } + + void Finish(R* msg, Status* status, void* tag) { + finish_buf_.Reset(tag); + if (!context_->initial_metadata_received_) { + finish_buf_.AddRecvInitialMetadata(context_); + } + finish_buf_.AddRecvMessage(msg); + finish_buf_.AddClientRecvStatus(context_, status); + call_.PerformOps(&finish_buf_); + } + + + private: + ClientContext* context_ = nullptr; + Call call_; + CallOpBuffer init_buf_; + CallOpBuffer meta_buf_; + CallOpBuffer finish_buf_; +}; + +template +class ServerAsyncResponseWriter final : public ServerAsyncStreamingInterface { + public: + explicit ServerAsyncResponseWriter(ServerContext* ctx) + : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} + + void SendInitialMetadata(void* tag) { + GPR_ASSERT(!ctx_->sent_initial_metadata_); + + meta_buf_.Reset(tag); + meta_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + call_.PerformOps(&meta_buf_); + } + + void Finish(const W& msg, const Status& status, void* tag) { + finish_buf_.Reset(tag); + if (!ctx_->sent_initial_metadata_) { + finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + } + // The response is dropped if the status is not OK. + if (status.IsOk()) { + finish_buf_.AddSendMessage(msg); + } + bool cancelled = false; + finish_buf_.AddServerRecvClose(&cancelled); + finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); + call_.PerformOps(&finish_buf_); + } + + void FinishWithError(const Status& status, void* tag) { + GPR_ASSERT(!status.IsOk()); + finish_buf_.Reset(tag); + if (!ctx_->sent_initial_metadata_) { + finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); + ctx_->sent_initial_metadata_ = true; + } + bool cancelled = false; + finish_buf_.AddServerRecvClose(&cancelled); + finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); + call_.PerformOps(&finish_buf_); + } + + private: + void BindCall(Call* call) override { call_ = *call; } + + Call call_; + ServerContext* ctx_; + CallOpBuffer meta_buf_; + CallOpBuffer finish_buf_; +}; + +} // namespace grpc + +#endif // __GRPCPP_ASYNC_UNARY_CALL_H__ diff --git a/include/grpc++/client_context.h b/include/grpc++/client_context.h index 8345a6f5af..29aef7ae5d 100644 --- a/include/grpc++/client_context.h +++ b/include/grpc++/client_context.h @@ -72,6 +72,8 @@ template class ClientAsyncWriter; template class ClientAsyncReaderWriter; +template +class ClientAsyncResponseReader; class ClientContext { public: @@ -119,6 +121,8 @@ class ClientContext { friend class ::grpc::ClientAsyncWriter; template friend class ::grpc::ClientAsyncReaderWriter; + template + friend class ::grpc::ClientAsyncResponseReader; grpc_call *call() { return call_; } void set_call(grpc_call *call) { diff --git a/include/grpc++/impl/client_unary_call.h b/include/grpc++/impl/client_unary_call.h index 22a8a04c82..f94538560e 100644 --- a/include/grpc++/impl/client_unary_call.h +++ b/include/grpc++/impl/client_unary_call.h @@ -48,13 +48,6 @@ class CompletionQueue; class RpcMethod; class Status; -// Wrapper that begins an asynchronous unary call -void AsyncUnaryCall(ChannelInterface *channel, const RpcMethod &method, - ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result, Status *status, - CompletionQueue *cq, void *tag); - // Wrapper that performs a blocking unary call Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, ClientContext *context, diff --git a/include/grpc++/stream.h b/include/grpc++/stream.h index 20ba3fb790..740189fcd0 100644 --- a/include/grpc++/stream.h +++ b/include/grpc++/stream.h @@ -550,60 +550,6 @@ class ClientAsyncReaderWriter final : public ClientAsyncStreamingInterface, CallOpBuffer finish_buf_; }; -// TODO(yangg) Move out of stream.h -template -class ServerAsyncResponseWriter final : public ServerAsyncStreamingInterface { - public: - explicit ServerAsyncResponseWriter(ServerContext* ctx) - : call_(nullptr, nullptr, nullptr), ctx_(ctx) {} - - void SendInitialMetadata(void* tag) { - GPR_ASSERT(!ctx_->sent_initial_metadata_); - - meta_buf_.Reset(tag); - meta_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); - ctx_->sent_initial_metadata_ = true; - call_.PerformOps(&meta_buf_); - } - - void Finish(const W& msg, const Status& status, void* tag) { - finish_buf_.Reset(tag); - if (!ctx_->sent_initial_metadata_) { - finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); - ctx_->sent_initial_metadata_ = true; - } - // The response is dropped if the status is not OK. - if (status.IsOk()) { - finish_buf_.AddSendMessage(msg); - } - bool cancelled = false; - finish_buf_.AddServerRecvClose(&cancelled); - finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_buf_); - } - - void FinishWithError(const Status& status, void* tag) { - GPR_ASSERT(!status.IsOk()); - finish_buf_.Reset(tag); - if (!ctx_->sent_initial_metadata_) { - finish_buf_.AddSendInitialMetadata(&ctx_->initial_metadata_); - ctx_->sent_initial_metadata_ = true; - } - bool cancelled = false; - finish_buf_.AddServerRecvClose(&cancelled); - finish_buf_.AddServerSendStatus(&ctx_->trailing_metadata_, status); - call_.PerformOps(&finish_buf_); - } - - private: - void BindCall(Call* call) override { call_ = *call; } - - Call call_; - ServerContext* ctx_; - CallOpBuffer meta_buf_; - CallOpBuffer finish_buf_; -}; - template class ServerAsyncReader : public ServerAsyncStreamingInterface, public AsyncReaderInterface { diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 60dc02d7af..6229170c2a 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -126,6 +126,8 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) { "class RpcService;\n" "class ServerContext;\n"; if (HasUnaryCalls(file)) { + temp.append( + "template class ClientAsyncResponseReader;\n"); temp.append( "template class ServerAsyncResponseWriter;\n"); } @@ -160,7 +162,8 @@ std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) { } std::string GetSourceIncludes() { - return "#include \n" + return "#include \n" + "#include \n" "#include \n" "#include \n" "#include \n" @@ -181,9 +184,9 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer *printer, "::grpc::Status $Method$(::grpc::ClientContext* context, " "const $Request$& request, $Response$* response);\n"); printer->Print(*vars, - "void $Method$(::grpc::ClientContext* context, " - "const $Request$& request, $Response$* response, " - "::grpc::Status* status, " + "::grpc::ClientAsyncResponseReader< $Response$>* " + "$Method$(::grpc::ClientContext* context, " + "const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag);\n"); } else if (ClientOnlyStreaming(method)) { printer->Print(*vars, @@ -378,14 +381,15 @@ void PrintSourceClientMethod(google::protobuf::io::Printer *printer, "context, request, response);\n" "}\n\n"); printer->Print(*vars, - "void $Service$::Stub::$Method$(" - "::grpc::ClientContext* context, " - "const $Request$& request, $Response$* response, ::grpc::Status* status, " + "::grpc::ClientAsyncResponseReader< $Response$>* " + "$Service$::Stub::$Method$(::grpc::ClientContext* context, " + "const $Request$& request, " "::grpc::CompletionQueue* cq, void* tag) {\n"); printer->Print(*vars, - " ::grpc::AsyncUnaryCall(channel()," + " return new ClientAsyncResponseReader< $Response$>(" + "channel(), cq, " "::grpc::RpcMethod($Service$_method_names[$Idx$]), " - "context, request, response, status, cq, tag);\n" + "context, request, tag);\n" "}\n\n"); } else if (ClientOnlyStreaming(method)) { printer->Print( diff --git a/src/cpp/client/client_unary_call.cc b/src/cpp/client/client_unary_call.cc index 03a0326128..1bc1db5fb0 100644 --- a/src/cpp/client/client_unary_call.cc +++ b/src/cpp/client/client_unary_call.cc @@ -60,30 +60,4 @@ Status BlockingUnaryCall(ChannelInterface *channel, const RpcMethod &method, GPR_ASSERT((cq.Pluck(&buf) && buf.got_message) || !status.IsOk()); return status; } - -class ClientAsyncRequest final : public CallOpBuffer { - public: - void FinalizeResult(void **tag, bool *status) override { - CallOpBuffer::FinalizeResult(tag, status); - delete this; - } -}; - -void AsyncUnaryCall(ChannelInterface *channel, const RpcMethod &method, - ClientContext *context, - const google::protobuf::Message &request, - google::protobuf::Message *result, Status *status, - CompletionQueue *cq, void *tag) { - ClientAsyncRequest *buf = new ClientAsyncRequest; - buf->Reset(tag); - Call call(channel->CreateCall(method, context, cq)); - buf->AddSendInitialMetadata(context); - buf->AddSendMessage(request); - buf->AddRecvInitialMetadata(context); - buf->AddRecvMessage(result); - buf->AddClientSendClose(); - buf->AddClientRecvStatus(context, status); - call.PerformOps(buf); -} - } // namespace grpc diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 7e827cb0e5..2848ffce1f 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -38,6 +38,7 @@ #include "test/cpp/util/echo_duplicate.pb.h" #include "test/cpp/util/echo.pb.h" #include "src/cpp/util/time.h" +#include #include #include #include @@ -124,21 +125,23 @@ class AsyncEnd2endTest : public ::testing::Test { grpc::ServerAsyncResponseWriter response_writer(&srv_ctx); send_request.set_message("Hello"); - stub_->Echo( - &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); + std::unique_ptr > + response_reader(stub_->Echo( + &cli_ctx, send_request, &cli_cq_, tag(1))); service_.RequestEcho( &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); server_ok(2); EXPECT_EQ(send_request.message(), recv_request.message()); + client_ok(1); send_response.set_message(recv_request.message()); response_writer.Finish(send_response, Status::OK, tag(3)); - server_ok(3); - client_ok(1); + response_reader->Finish(&recv_response, &recv_status, tag(4)); + client_ok(4); EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); @@ -341,8 +344,8 @@ TEST_F(AsyncEnd2endTest, ClientInitialMetadataRpc) { cli_ctx.AddMetadata(meta1.first, meta1.second); cli_ctx.AddMetadata(meta2.first, meta2.second); - stub_->Echo( - &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); + std::unique_ptr > response_reader( + stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1))); service_.RequestEcho( &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); @@ -352,13 +355,15 @@ TEST_F(AsyncEnd2endTest, ClientInitialMetadataRpc) { EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second); EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second); EXPECT_EQ(2, client_initial_metadata.size()); + client_ok(1); send_response.set_message(recv_request.message()); response_writer.Finish(send_response, Status::OK, tag(3)); server_ok(3); - client_ok(1); + response_reader->Finish(&recv_response, &recv_status, tag(4)); + client_ok(4); EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); @@ -381,8 +386,8 @@ TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) { std::pair meta1("key1", "val1"); std::pair meta2("key2", "val2"); - stub_->Echo( - &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); + std::unique_ptr > response_reader( + stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1))); service_.RequestEcho( &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); @@ -390,22 +395,26 @@ TEST_F(AsyncEnd2endTest, ServerInitialMetadataRpc) { EXPECT_EQ(send_request.message(), recv_request.message()); srv_ctx.AddInitialMetadata(meta1.first, meta1.second); srv_ctx.AddInitialMetadata(meta2.first, meta2.second); + client_ok(1); response_writer.SendInitialMetadata(tag(3)); server_ok(3); - send_response.set_message(recv_request.message()); - response_writer.Finish(send_response, Status::OK, tag(4)); + response_reader->ReadInitialMetadata(tag(4)); + client_ok(4); + auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); + EXPECT_EQ(meta1.second, server_initial_metadata.find(meta1.first)->second); + EXPECT_EQ(meta2.second, server_initial_metadata.find(meta2.first)->second); + EXPECT_EQ(2, server_initial_metadata.size()); - server_ok(4); + send_response.set_message(recv_request.message()); + response_writer.Finish(send_response, Status::OK, tag(5)); + server_ok(5); - client_ok(1); + response_reader->Finish(&recv_response, &recv_status, tag(6)); + client_ok(6); EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); - auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); - EXPECT_EQ(meta1.second, server_initial_metadata.find(meta1.first)->second); - EXPECT_EQ(meta2.second, server_initial_metadata.find(meta2.first)->second); - EXPECT_EQ(2, server_initial_metadata.size()); } TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { @@ -425,8 +434,8 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { std::pair meta1("key1", "val1"); std::pair meta2("key2", "val2"); - stub_->Echo( - &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); + std::unique_ptr > response_reader( + stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1))); service_.RequestEcho( &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); @@ -434,6 +443,7 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { EXPECT_EQ(send_request.message(), recv_request.message()); response_writer.SendInitialMetadata(tag(3)); server_ok(3); + client_ok(1); send_response.set_message(recv_request.message()); srv_ctx.AddTrailingMetadata(meta1.first, meta1.second); @@ -442,8 +452,9 @@ TEST_F(AsyncEnd2endTest, ServerTrailingMetadataRpc) { server_ok(4); - client_ok(1); + response_reader->Finish(&recv_response, &recv_status, tag(5)); + client_ok(5); EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); @@ -467,17 +478,20 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) { send_request.set_message("Hello"); std::pair meta1("key1", "val1"); - std::pair meta2("key2-bin", {"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13}); + std::pair meta2( + "key2-bin", {"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", 13}); std::pair meta3("key3", "val3"); - std::pair meta6("key4-bin", {"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", 14}); + std::pair meta6("key4-bin", + {"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", 14}); std::pair meta5("key5", "val5"); - std::pair meta4("key6-bin", {"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15}); + std::pair meta4("key6-bin", + {"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", 15}); cli_ctx.AddMetadata(meta1.first, meta1.second); cli_ctx.AddMetadata(meta2.first, meta2.second); - stub_->Echo( - &cli_ctx, send_request, &recv_response, &recv_status, &cli_cq_, tag(1)); + std::unique_ptr > response_reader( + stub_->Echo(&cli_ctx, send_request, &cli_cq_, tag(1))); service_.RequestEcho( &srv_ctx, &recv_request, &response_writer, &srv_cq_, tag(2)); @@ -487,27 +501,31 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) { EXPECT_EQ(meta1.second, client_initial_metadata.find(meta1.first)->second); EXPECT_EQ(meta2.second, client_initial_metadata.find(meta2.first)->second); EXPECT_EQ(2, client_initial_metadata.size()); + client_ok(1); srv_ctx.AddInitialMetadata(meta3.first, meta3.second); srv_ctx.AddInitialMetadata(meta4.first, meta4.second); response_writer.SendInitialMetadata(tag(3)); server_ok(3); + response_reader->ReadInitialMetadata(tag(4)); + client_ok(4); + auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); + EXPECT_EQ(meta3.second, server_initial_metadata.find(meta3.first)->second); + EXPECT_EQ(meta4.second, server_initial_metadata.find(meta4.first)->second); + EXPECT_EQ(2, server_initial_metadata.size()); send_response.set_message(recv_request.message()); srv_ctx.AddTrailingMetadata(meta5.first, meta5.second); srv_ctx.AddTrailingMetadata(meta6.first, meta6.second); - response_writer.Finish(send_response, Status::OK, tag(4)); + response_writer.Finish(send_response, Status::OK, tag(5)); - server_ok(4); + server_ok(5); - client_ok(1); + response_reader->Finish(&recv_response, &recv_status, tag(6)); + client_ok(6); EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.IsOk()); - auto server_initial_metadata = cli_ctx.GetServerInitialMetadata(); - EXPECT_EQ(meta3.second, server_initial_metadata.find(meta3.first)->second); - EXPECT_EQ(meta4.second, server_initial_metadata.find(meta4.first)->second); - EXPECT_EQ(2, server_initial_metadata.size()); auto server_trailing_metadata = cli_ctx.GetServerTrailingMetadata(); EXPECT_EQ(meta5.second, server_trailing_metadata.find(meta5.first)->second); EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second); -- cgit v1.2.3 From 2ec0b3ea59ea0869d07153c8f54894aea5192693 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 18 Feb 2015 15:03:12 -0800 Subject: make grpc_csharp_ext compile and install independently from the grpc and gpr libraries --- Makefile | 52 ++++++++++++++++++++++++++++----------------- build.json | 2 +- templates/Makefile.template | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 20 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e1991da5ec..f1fa9dba12 100644 --- a/Makefile +++ b/Makefile @@ -892,16 +892,19 @@ $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure static: static_c static_cxx -static_c: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a +static_c: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a static_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.a shared: shared_c shared_cxx -shared_c: $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) +shared_c: $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) shared_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT) +shared_csharp: shared_c $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) +grpc_csharp_ext: shared_csharp + privatelibs: privatelibs_c privatelibs_cxx privatelibs_c: $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fake_security.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_fullstack_uds.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_simple_ssl_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_simple_ssl_with_oauth2_fullstack.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_socket_pair.a $(LIBDIR)/$(CONFIG)/libend2end_fixture_chttp2_socket_pair_one_byte_at_a_time.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept_and_writes_closed.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_invoke.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_before_invoke.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_in_a_vacuum.a $(LIBDIR)/$(CONFIG)/libend2end_test_census_simple_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_disappearing_server.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_inflight_calls.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_tags.a $(LIBDIR)/$(CONFIG)/libend2end_test_empty_batch.a $(LIBDIR)/$(CONFIG)/libend2end_test_graceful_server_shutdown.a $(LIBDIR)/$(CONFIG)/libend2end_test_invoke_large_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_max_concurrent_streams.a $(LIBDIR)/$(CONFIG)/libend2end_test_no_op.a $(LIBDIR)/$(CONFIG)/libend2end_test_ping_pong_streaming.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_binary_metadata_and_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_metadata_and_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_large_metadata.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_payload.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_delayed_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_request.a $(LIBDIR)/$(CONFIG)/libend2end_test_thread_stress.a $(LIBDIR)/$(CONFIG)/libend2end_test_writes_done_hangs_with_pending_read.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_accept_and_writes_closed_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_after_invoke_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_before_invoke_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_cancel_in_a_vacuum_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_census_simple_request_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_disappearing_server_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_inflight_calls_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_early_server_shutdown_finishes_tags_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_graceful_server_shutdown_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_invoke_large_request_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_max_concurrent_streams_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_no_op_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_ping_pong_streaming_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_binary_metadata_and_payload_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_metadata_and_payload_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_payload_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_response_with_trailing_metadata_and_payload_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_large_metadata_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_request_with_payload_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_delayed_request_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_simple_request_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_thread_stress_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_test_writes_done_hangs_with_pending_read_legacy.a $(LIBDIR)/$(CONFIG)/libend2end_certs.a @@ -1765,8 +1768,6 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[STRIP] Stripping libgrpc.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc.a - $(E) "[STRIP] Stripping libgrpc_csharp_ext.a" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a $(E) "[STRIP] Stripping libgrpc_unsecure.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a endif @@ -1783,8 +1784,6 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgpr.$(SHARED_EXT) $(E) "[STRIP] Stripping libgrpc.so" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT) - $(E) "[STRIP] Stripping libgrpc_csharp_ext.so" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(E) "[STRIP] Stripping libgrpc_unsecure.so" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) endif @@ -1795,6 +1794,12 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT) endif +strip-shared_csharp: shared_csharp +ifeq ($(CONFIG),opt) + $(E) "[STRIP] Stripping libgrpc_csharp_ext.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) +endif + ifeq ($(NO_PROTOC),true) $(GENDIR)/examples/pubsub/empty.pb.cc: protoc_dep_error else @@ -1913,6 +1918,10 @@ install_c: install-headers_c install-static_c install-shared_c install_cxx: install-headers_cxx install-static_cxx install-shared_cxx +install_csharp: install-shared_csharp install_c + +install_grpc_csharp_ext: install_csharp + install-headers: install-headers_c install-headers_cxx install-headers_c: @@ -1930,8 +1939,6 @@ install-static_c: static_c strip-static_c $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgpr.a $(prefix)/lib/libgpr.a $(E) "[INSTALL] Installing libgrpc.a" $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc.a $(prefix)/lib/libgrpc.a - $(E) "[INSTALL] Installing libgrpc_csharp_ext.a" - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a $(prefix)/lib/libgrpc_csharp_ext.a $(E) "[INSTALL] Installing libgrpc_unsecure.a" $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a $(prefix)/lib/libgrpc_unsecure.a @@ -1962,17 +1969,6 @@ ifneq ($(SYSTEM),Darwin) $(Q) ln -sf libgrpc.$(SHARED_EXT) $(prefix)/lib/libgrpc.so endif endif -ifeq ($(SYSTEM),MINGW32) - $(E) "[INSTALL] Installing grpc_csharp_ext.$(SHARED_EXT)" - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/grpc_csharp_ext.$(SHARED_EXT) - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a $(prefix)/lib/libgrpc_csharp_ext-imp.a -else - $(E) "[INSTALL] Installing libgrpc_csharp_ext.$(SHARED_EXT)" - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.$(SHARED_EXT) -ifneq ($(SYSTEM),Darwin) - $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.so -endif -endif ifeq ($(SYSTEM),MINGW32) $(E) "[INSTALL] Installing grpc_unsecure.$(SHARED_EXT)" $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc_unsecure.$(SHARED_EXT) $(prefix)/lib/grpc_unsecure.$(SHARED_EXT) @@ -2008,6 +2004,24 @@ ifneq ($(SYSTEM),Darwin) endif endif +install-shared_csharp: shared_csharp strip-shared_csharp +ifeq ($(SYSTEM),MINGW32) + $(E) "[INSTALL] Installing grpc_csharp_ext.$(SHARED_EXT)" + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/grpc_csharp_ext.$(SHARED_EXT) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a $(prefix)/lib/libgrpc_csharp_ext-imp.a +else + $(E) "[INSTALL] Installing libgrpc_csharp_ext.$(SHARED_EXT)" + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.$(SHARED_EXT) +ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.so +endif +endif +ifneq ($(SYSTEM),MINGW32) +ifneq ($(SYSTEM),Darwin) + $(Q) ldconfig +endif +endif + clean: $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) diff --git a/build.json b/build.json index a09296479a..c552228496 100644 --- a/build.json +++ b/build.json @@ -345,7 +345,7 @@ { "name": "grpc_csharp_ext", "build": "all", - "language": "c", + "language": "csharp", "src": [ "src/csharp/ext/grpc_csharp_ext.c" ], diff --git a/templates/Makefile.template b/templates/Makefile.template index d107801e08..178ace6bcf 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -529,6 +529,15 @@ shared_cxx: \ % endfor +shared_csharp: shared_c \ +% for lib in libs: +% if lib.build == 'all' and lib.language == 'csharp': + $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT)\ +% endif +% endfor + +grpc_csharp_ext: shared_csharp + privatelibs: privatelibs_c privatelibs_cxx privatelibs_c: \ @@ -662,6 +671,18 @@ ifeq ($(CONFIG),opt) % endfor endif +strip-shared_csharp: shared_csharp +ifeq ($(CONFIG),opt) +% for lib in libs: +% if lib.language == "csharp": +% if lib.build == "all": + $(E) "[STRIP] Stripping lib${lib.name}.so" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) +% endif +% endif +% endfor +endif + % for p in protos: ifeq ($(NO_PROTOC),true) $(GENDIR)/${p}.pb.cc: protoc_dep_error @@ -701,6 +722,10 @@ install_c: install-headers_c install-static_c install-shared_c install_cxx: install-headers_cxx install-static_cxx install-shared_cxx +install_csharp: install-shared_csharp install_c + +install_grpc_csharp_ext: install_csharp + install-headers: install-headers_c install-headers_cxx install-headers_c: @@ -781,6 +806,30 @@ ifneq ($(SYSTEM),Darwin) endif endif +install-shared_csharp: shared_csharp strip-shared_csharp +% for lib in libs: +% if lib.language == "csharp": +% if lib.build == "all": +ifeq ($(SYSTEM),MINGW32) + $(E) "[INSTALL] Installing ${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/${lib.name}.$(SHARED_EXT) $(prefix)/lib/${lib.name}.$(SHARED_EXT) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a +else + $(E) "[INSTALL] Installing lib${lib.name}.$(SHARED_EXT)" + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.$(SHARED_EXT) +ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) $(prefix)/lib/lib${lib.name}.so +endif +endif +% endif +% endif +% endfor +ifneq ($(SYSTEM),MINGW32) +ifneq ($(SYSTEM),Darwin) + $(Q) ldconfig +endif +endif + clean: $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) -- cgit v1.2.3