diff options
author | Craig Tiller <ctiller@google.com> | 2015-02-09 16:12:00 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-02-09 16:12:00 -0800 |
commit | b470169252c36a64749f6b7c60da36845c7fee1d (patch) | |
tree | cb8af32c27f1a1904d8a8fe0635d6bbf9015df13 | |
parent | 40fcdaff0ae9db85953c4c2e32bd2a6534bdb72e (diff) |
Remove more unnecessary files
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | build.json | 2 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 5 | ||||
-rw-r--r-- | src/cpp/client/channel.cc | 1 | ||||
-rw-r--r-- | src/cpp/common/completion_queue.cc | 1 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 18 | ||||
-rw-r--r-- | src/cpp/server/server_rpc_handler.cc | 140 | ||||
-rw-r--r-- | src/cpp/server/server_rpc_handler.h | 67 |
8 files changed, 14 insertions, 223 deletions
@@ -2622,7 +2622,6 @@ LIBGRPC++_SRC = \ src/cpp/server/server_builder.cc \ src/cpp/server/server_context_impl.cc \ src/cpp/server/server_credentials.cc \ - src/cpp/server/server_rpc_handler.cc \ src/cpp/server/thread_pool.cc \ src/cpp/util/status.cc \ src/cpp/util/time.cc \ @@ -2677,7 +2676,6 @@ src/cpp/server/server.cc: $(OPENSSL_DEP) src/cpp/server/server_builder.cc: $(OPENSSL_DEP) src/cpp/server/server_context_impl.cc: $(OPENSSL_DEP) src/cpp/server/server_credentials.cc: $(OPENSSL_DEP) -src/cpp/server/server_rpc_handler.cc: $(OPENSSL_DEP) src/cpp/server/thread_pool.cc: $(OPENSSL_DEP) src/cpp/util/status.cc: $(OPENSSL_DEP) src/cpp/util/time.cc: $(OPENSSL_DEP) @@ -2735,7 +2733,6 @@ objs/$(CONFIG)/src/cpp/server/server.o: objs/$(CONFIG)/src/cpp/server/server_builder.o: objs/$(CONFIG)/src/cpp/server/server_context_impl.o: objs/$(CONFIG)/src/cpp/server/server_credentials.o: -objs/$(CONFIG)/src/cpp/server/server_rpc_handler.o: objs/$(CONFIG)/src/cpp/server/thread_pool.o: objs/$(CONFIG)/src/cpp/util/status.o: objs/$(CONFIG)/src/cpp/util/time.o: diff --git a/build.json b/build.json index 3bedddfcd1..bd4fcb9fd1 100644 --- a/build.json +++ b/build.json @@ -399,7 +399,6 @@ "headers": [ "src/cpp/client/channel.h", "src/cpp/proto/proto_utils.h", - "src/cpp/server/server_rpc_handler.h", "src/cpp/server/thread_pool.h", "src/cpp/util/time.h" ], @@ -418,7 +417,6 @@ "src/cpp/server/server_builder.cc", "src/cpp/server/server_context_impl.cc", "src/cpp/server/server_credentials.cc", - "src/cpp/server/server_rpc_handler.cc", "src/cpp/server/thread_pool.cc", "src/cpp/util/status.cc", "src/cpp/util/time.cc" diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 9fd3ab1689..4af9fd6aaa 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -35,6 +35,9 @@ #define __GRPCPP_SERVER_CONTEXT_H_ #include <chrono> +#include <vector> + +#include "config.h" namespace grpc { @@ -43,7 +46,7 @@ class ServerContext { public: virtual ~ServerContext() {} - virtual std::chrono::system_clock::time_point absolute_deadline() const = 0; + std::chrono::system_clock::time_point absolute_deadline(); private: std::vector<std::pair<grpc::string, grpc::string> > metadata_; diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index b513212903..24bd7adaad 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -42,7 +42,6 @@ #include <grpc/support/slice.h> #include "src/cpp/proto/proto_utils.h" -#include "src/cpp/stream/stream_context.h" #include <grpc++/call.h> #include <grpc++/channel_arguments.h> #include <grpc++/client_context.h> diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc index 31c1fb9286..d7d616407e 100644 --- a/src/cpp/common/completion_queue.cc +++ b/src/cpp/common/completion_queue.cc @@ -38,7 +38,6 @@ #include <grpc/support/log.h> #include <grpc/support/time.h> #include "src/cpp/util/time.h" -#include <grpc++/async_server_context.h> namespace grpc { diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 1f48e83b88..5d44ab2ba4 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -37,10 +37,9 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpc/support/log.h> -#include "src/cpp/server/server_rpc_handler.h" -#include <grpc++/async_server_context.h> #include <grpc++/completion_queue.h> #include <grpc++/impl/rpc_service_method.h> +#include <grpc++/server_context.h> #include <grpc++/server_credentials.h> #include <grpc++/thread_pool_interface.h> @@ -148,12 +147,12 @@ void Server::RunRpc() { void *tag = nullptr; GPR_ASSERT(started_); grpc_call *c_call = NULL; - grpc_call_details details; - grpc_call_details_init(&details); + grpc_call_details call_details; + grpc_call_details_init(&call_details); grpc_metadata_array initial_metadata; grpc_metadata_array_init(&initial_metadata); CompletionQueue cq; - grpc_call_error err = grpc_server_request_call(server_, &call, &details, &initial_metadata, cq.cq(), nullptr); + grpc_call_error err = grpc_server_request_call(server_, &c_call, &call_details, &initial_metadata, cq.cq(), nullptr); GPR_ASSERT(err == GRPC_CALL_OK); bool ok = false; GPR_ASSERT(cq_.Next(&tag, &ok)); @@ -166,10 +165,13 @@ void Server::RunRpc() { if (iter != method_map_.end()) { method = iter->second; } - ServerRpcHandler rpc_handler(&call, context, method); - rpc_handler.StartRpc(); + // TODO(ctiller): allocate only if necessary + std::unique_ptr<google::protobuf::Message> request(method->AllocateRequestProto()); + std::unique_ptr<google::protobuf::Message> response(method->AllocateResponseProto()); + method->handler()->RunHandler(MethodHandler::HandlerParameter( + &call, &context, request.get(), response.get())); } - grpc_call_details_destroy(&details); + grpc_call_details_destroy(&call_details); grpc_metadata_array_destroy(&initial_metadata); { diff --git a/src/cpp/server/server_rpc_handler.cc b/src/cpp/server/server_rpc_handler.cc deleted file mode 100644 index bf02de8b80..0000000000 --- a/src/cpp/server/server_rpc_handler.cc +++ /dev/null @@ -1,140 +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. - * - */ - -#include "src/cpp/server/server_rpc_handler.h" - -#include <grpc/support/log.h> -#include "src/cpp/server/server_context_impl.h" -#include "src/cpp/stream/stream_context.h" -#include <grpc++/async_server_context.h> -#include <grpc++/impl/rpc_service_method.h> - -namespace grpc { - -ServerRpcHandler::ServerRpcHandler(AsyncServerContext *async_server_context, - RpcServiceMethod *method) - : async_server_context_(async_server_context), method_(method) {} - -void ServerRpcHandler::StartRpc() { - if (method_ == nullptr) { - // Method not supported, finish the rpc with error. - // TODO(rocking): do we need to call read to consume the request? - FinishRpc(Status(StatusCode::UNIMPLEMENTED, "No such method.")); - return; - } - - ServerContextImpl user_context(async_server_context_->absolute_deadline()); - - if (method_->method_type() == RpcMethod::NORMAL_RPC) { - // Start the rpc on this dedicated completion queue. - async_server_context_->Accept(cq_.cq()); - - // Allocate request and response. - std::unique_ptr<google::protobuf::Message> request( - method_->AllocateRequestProto()); - std::unique_ptr<google::protobuf::Message> response( - method_->AllocateResponseProto()); - - // Read request - async_server_context_->StartRead(request.get()); - auto type = WaitForNextEvent(); - GPR_ASSERT(type == CompletionQueue::SERVER_READ_OK); - - // Run the application's rpc handler - MethodHandler *handler = method_->handler(); - Status status = handler->RunHandler(MethodHandler::HandlerParameter( - &user_context, request.get(), response.get())); - - if (status.IsOk()) { - // Send the response if we get an ok status. - async_server_context_->StartWrite(*response, GRPC_WRITE_BUFFER_HINT); - type = WaitForNextEvent(); - if (type != CompletionQueue::SERVER_WRITE_OK) { - status = Status(StatusCode::INTERNAL, "Error writing response."); - } - } - - FinishRpc(status); - } else { - // Allocate request and response. - // TODO(yangg) maybe not allocate both when not needed? - std::unique_ptr<google::protobuf::Message> request( - method_->AllocateRequestProto()); - std::unique_ptr<google::protobuf::Message> response( - method_->AllocateResponseProto()); - - StreamContext stream_context(*method_, async_server_context_->call(), - cq_.cq(), request.get(), response.get()); - - // Run the application's rpc handler - MethodHandler *handler = method_->handler(); - Status status = handler->RunHandler(MethodHandler::HandlerParameter( - &user_context, request.get(), response.get(), &stream_context)); - if (status.IsOk() && - method_->method_type() == RpcMethod::CLIENT_STREAMING) { - stream_context.Write(response.get(), false); - } - // TODO(yangg) Do we need to consider the status in stream_context? - FinishRpc(status); - } -} - -CompletionQueue::CompletionType ServerRpcHandler::WaitForNextEvent() { - void *tag = nullptr; - CompletionQueue::CompletionType type = cq_.Next(&tag); - if (type != CompletionQueue::QUEUE_CLOSED && - type != CompletionQueue::RPC_END) { - GPR_ASSERT(static_cast<AsyncServerContext *>(tag) == - async_server_context_.get()); - } - return type; -} - -void ServerRpcHandler::FinishRpc(const Status &status) { - async_server_context_->StartWriteStatus(status); - CompletionQueue::CompletionType type; - - // HALFCLOSE_OK and RPC_END events come in either order. - type = WaitForNextEvent(); - GPR_ASSERT(type == CompletionQueue::HALFCLOSE_OK || - type == CompletionQueue::RPC_END); - type = WaitForNextEvent(); - GPR_ASSERT(type == CompletionQueue::HALFCLOSE_OK || - type == CompletionQueue::RPC_END); - - cq_.Shutdown(); - type = WaitForNextEvent(); - GPR_ASSERT(type == CompletionQueue::QUEUE_CLOSED); -} - -} // namespace grpc diff --git a/src/cpp/server/server_rpc_handler.h b/src/cpp/server/server_rpc_handler.h deleted file mode 100644 index 15efd1892d..0000000000 --- a/src/cpp/server/server_rpc_handler.h +++ /dev/null @@ -1,67 +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 __GRPCPP_INTERNAL_SERVER_SERVER_RPC_HANDLER_H__ -#define __GRPCPP_INTERNAL_SERVER_SERVER_RPC_HANDLER_H__ - -#include <memory> - -#include <grpc++/completion_queue.h> -#include <grpc++/status.h> - -namespace grpc { - -class -class ServerContext; -class RpcServiceMethod; - -class ServerRpcHandler { - public: - ServerRpcHandler(Call *call, - ServerContext *server_context, - RpcServiceMethod *method); - - void StartRpc(); - - private: - void FinishRpc(const Status &status); - - Call *call_; - ServerContext* server_context_; - RpcServiceMethod *method_; - CompletionQueue cq_; -}; - -} // namespace grpc - -#endif // __GRPCPP_INTERNAL_SERVER_SERVER_RPC_HANDLER_H__ |