Remove more unnecessary files

pull/501/head
Craig Tiller 10 years ago
parent 40fcdaff0a
commit b470169252
  1. 3
      Makefile
  2. 2
      build.json
  3. 5
      include/grpc++/server_context.h
  4. 1
      src/cpp/client/channel.cc
  5. 1
      src/cpp/common/completion_queue.cc
  6. 18
      src/cpp/server/server.cc
  7. 140
      src/cpp/server/server_rpc_handler.cc
  8. 67
      src/cpp/server/server_rpc_handler.h

@ -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:

@ -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"

@ -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_;

@ -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>

@ -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 {

@ -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);
{

@ -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

@ -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__
Loading…
Cancel
Save