diff options
Diffstat (limited to 'src/cpp')
-rw-r--r-- | src/cpp/client/channel.cc | 20 | ||||
-rw-r--r-- | src/cpp/client/channel.h | 8 | ||||
-rw-r--r-- | src/cpp/client/credentials.cc | 37 | ||||
-rw-r--r-- | src/cpp/client/internal_stub.cc | 2 | ||||
-rw-r--r-- | src/cpp/client/internal_stub.h | 60 | ||||
-rw-r--r-- | src/cpp/common/rpc_method.cc (renamed from src/cpp/rpc_method.cc) | 2 | ||||
-rw-r--r-- | src/cpp/proto/proto_utils.cc | 6 | ||||
-rw-r--r-- | src/cpp/proto/proto_utils.h | 3 | ||||
-rw-r--r-- | src/cpp/rpc_method.h | 69 | ||||
-rw-r--r-- | src/cpp/server/async_server_context.cc | 3 | ||||
-rw-r--r-- | src/cpp/server/rpc_service_method.h | 214 | ||||
-rw-r--r-- | src/cpp/server/server.cc | 2 | ||||
-rw-r--r-- | src/cpp/server/server_context_impl.cc | 4 | ||||
-rw-r--r-- | src/cpp/server/server_credentials.cc | 1 | ||||
-rw-r--r-- | src/cpp/server/server_rpc_handler.cc | 14 | ||||
-rw-r--r-- | src/cpp/stream/stream_context.cc | 9 | ||||
-rw-r--r-- | src/cpp/stream/stream_context.h | 13 | ||||
-rw-r--r-- | src/cpp/util/status.cc | 1 |
18 files changed, 84 insertions, 384 deletions
diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 7d95518631..ddda8c22d6 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -41,13 +41,13 @@ #include <grpc/support/log.h> #include <grpc/support/slice.h> -#include "src/cpp/rpc_method.h" #include "src/cpp/proto/proto_utils.h" #include "src/cpp/stream/stream_context.h" #include <grpc++/channel_arguments.h> #include <grpc++/client_context.h> #include <grpc++/config.h> #include <grpc++/credentials.h> +#include <grpc++/impl/rpc_method.h> #include <grpc++/status.h> #include <google/protobuf/message.h> @@ -69,8 +69,9 @@ Channel::Channel(const grpc::string& target, : args.GetSslTargetNameOverride()) { grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); + grpc_credentials* c_creds = creds ? creds->GetRawCreds() : nullptr; c_channel_ = grpc_secure_channel_create( - creds->GetRawCreds(), target.c_str(), + c_creds, target.c_str(), channel_args.num_args > 0 ? &channel_args : nullptr); } @@ -118,10 +119,15 @@ Status Channel::StartBlockingRpc(const RpcMethod& method, finished_tag, GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK); ev = grpc_completion_queue_pluck(cq, invoke_tag, gpr_inf_future); + bool success = ev->data.invoke_accepted == GRPC_OP_OK; grpc_event_finish(ev); + if (!success) { + GetFinalStatus(cq, finished_tag, &status); + return status; + } // write request grpc_byte_buffer* write_buffer = nullptr; - bool success = SerializeProto(request, &write_buffer); + success = SerializeProto(request, &write_buffer); if (!success) { grpc_call_cancel(call); status = @@ -166,10 +172,10 @@ Status Channel::StartBlockingRpc(const RpcMethod& method, return status; } -StreamContextInterface* Channel::CreateStream(const RpcMethod& method, - ClientContext* context, - const google::protobuf::Message* request, - google::protobuf::Message* result) { +StreamContextInterface* Channel::CreateStream( + const RpcMethod& method, ClientContext* context, + const google::protobuf::Message* request, + google::protobuf::Message* result) { grpc_call* call = grpc_channel_create_call( c_channel_, method.name(), target_.c_str(), context->RawDeadline()); context->set_call(call); diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index 621e58539b..8de1180ac2 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -58,10 +58,10 @@ class Channel : public ChannelInterface { const google::protobuf::Message& request, google::protobuf::Message* result) override; - StreamContextInterface* CreateStream(const RpcMethod& method, - ClientContext* context, - const google::protobuf::Message* request, - google::protobuf::Message* result) override; + StreamContextInterface* CreateStream( + const RpcMethod& method, ClientContext* context, + const google::protobuf::Message* request, + google::protobuf::Message* result) override; private: const grpc::string target_; diff --git a/src/cpp/client/credentials.cc b/src/cpp/client/credentials.cc index 986008f7bb..d81cf9f4d0 100644 --- a/src/cpp/client/credentials.cc +++ b/src/cpp/client/credentials.cc @@ -31,10 +31,10 @@ * */ - #include <string> #include <grpc/grpc_security.h> +#include <grpc/support/log.h> #include <grpc++/credentials.h> @@ -58,6 +58,9 @@ std::unique_ptr<Credentials> CredentialsFactory::SslCredentials( options.pem_root_certs.empty() ? nullptr : reinterpret_cast<const unsigned char*>( options.pem_root_certs.c_str()); + if (pem_root_certs == nullptr) { + return std::unique_ptr<Credentials>(); + } const unsigned char* pem_private_key = options.pem_private_key.empty() ? nullptr : reinterpret_cast<const unsigned char*>( @@ -71,17 +74,42 @@ std::unique_ptr<Credentials> CredentialsFactory::SslCredentials( pem_root_certs, options.pem_root_certs.size(), pem_private_key, options.pem_private_key.size(), pem_cert_chain, options.pem_cert_chain.size()); - std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds)); + std::unique_ptr<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); return cpp_creds; } // Builds credentials for use when running in GCE std::unique_ptr<Credentials> CredentialsFactory::ComputeEngineCredentials() { grpc_credentials* c_creds = grpc_compute_engine_credentials_create(); - std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds)); + std::unique_ptr<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); return cpp_creds; } +// Builds service account credentials. +std::unique_ptr<Credentials> CredentialsFactory::ServiceAccountCredentials( + const grpc::string& json_key, const grpc::string& scope, + std::chrono::seconds token_lifetime) { + gpr_timespec lifetime = gpr_time_from_seconds( + token_lifetime.count() > 0 ? token_lifetime.count() : 0); + grpc_credentials* c_creds = grpc_service_account_credentials_create( + json_key.c_str(), scope.c_str(), lifetime); + std::unique_ptr<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); + return cpp_creds; +} + +// Builds IAM credentials. +std::unique_ptr<Credentials> CredentialsFactory::IAMCredentials( + const grpc::string& authorization_token, + const grpc::string& authority_selector) { + grpc_credentials* c_creds = grpc_iam_credentials_create( + authorization_token.c_str(), authority_selector.c_str()); + std::unique_ptr<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); + return cpp_creds; +} // Combines two credentials objects into a composite credentials. std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials( @@ -93,7 +121,8 @@ std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials( // refcounts incremented. grpc_credentials* c_creds = grpc_composite_credentials_create( creds1->GetRawCreds(), creds2->GetRawCreds()); - std::unique_ptr<Credentials> cpp_creds(new Credentials(c_creds)); + std::unique_ptr<Credentials> cpp_creds( + c_creds == nullptr ? nullptr : new Credentials(c_creds)); return cpp_creds; } diff --git a/src/cpp/client/internal_stub.cc b/src/cpp/client/internal_stub.cc index ec88ba5e7e..51cb99d1b4 100644 --- a/src/cpp/client/internal_stub.cc +++ b/src/cpp/client/internal_stub.cc @@ -31,6 +31,6 @@ * */ -#include "src/cpp/client/internal_stub.h" +#include <grpc++/impl/internal_stub.h> namespace grpc {} // namespace grpc diff --git a/src/cpp/client/internal_stub.h b/src/cpp/client/internal_stub.h deleted file mode 100644 index 0eaa717d0b..0000000000 --- a/src/cpp/client/internal_stub.h +++ /dev/null @@ -1,60 +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_CLIENT_INTERNAL_STUB_H__ -#define __GRPCPP_INTERNAL_CLIENT_INTERNAL_STUB_H__ - -#include <memory> - -#include <grpc++/channel_interface.h> - -namespace grpc { - -class InternalStub { - public: - InternalStub() {} - virtual ~InternalStub() {} - - void set_channel(const std::shared_ptr<ChannelInterface>& channel) { - channel_ = channel; - } - - ChannelInterface* channel() { return channel_.get(); } - - private: - std::shared_ptr<ChannelInterface> channel_; -}; - -} // namespace grpc - -#endif // __GRPCPP_INTERNAL_CLIENT_INTERNAL_STUB_H__ diff --git a/src/cpp/rpc_method.cc b/src/cpp/common/rpc_method.cc index 8067f42f85..c8b2ccb10e 100644 --- a/src/cpp/rpc_method.cc +++ b/src/cpp/common/rpc_method.cc @@ -31,6 +31,6 @@ * */ -#include "src/cpp/rpc_method.h" +#include <grpc++/impl/rpc_method.h> namespace grpc {} // namespace grpc diff --git a/src/cpp/proto/proto_utils.cc b/src/cpp/proto/proto_utils.cc index 255d1461a9..3b94dc3c07 100644 --- a/src/cpp/proto/proto_utils.cc +++ b/src/cpp/proto/proto_utils.cc @@ -40,7 +40,8 @@ namespace grpc { -bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** bp) { +bool SerializeProto(const google::protobuf::Message& msg, + grpc_byte_buffer** bp) { grpc::string msg_str; bool success = msg.SerializeToString(&msg_str); if (success) { @@ -52,7 +53,8 @@ bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** bp) return success; } -bool DeserializeProto(grpc_byte_buffer* buffer, google::protobuf::Message* msg) { +bool DeserializeProto(grpc_byte_buffer* buffer, + google::protobuf::Message* msg) { grpc::string msg_string; grpc_byte_buffer_reader* reader = grpc_byte_buffer_reader_create(buffer); gpr_slice slice; diff --git a/src/cpp/proto/proto_utils.h b/src/cpp/proto/proto_utils.h index 11471f1acb..ea472f9c51 100644 --- a/src/cpp/proto/proto_utils.h +++ b/src/cpp/proto/proto_utils.h @@ -46,7 +46,8 @@ namespace grpc { // Serialize the msg into a buffer created inside the function. The caller // should destroy the returned buffer when done with it. If serialization fails, // false is returned and buffer is left unchanged. -bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** buffer); +bool SerializeProto(const google::protobuf::Message& msg, + grpc_byte_buffer** buffer); // The caller keeps ownership of buffer and msg. bool DeserializeProto(grpc_byte_buffer* buffer, google::protobuf::Message* msg); diff --git a/src/cpp/rpc_method.h b/src/cpp/rpc_method.h deleted file mode 100644 index 24a34bed89..0000000000 --- a/src/cpp/rpc_method.h +++ /dev/null @@ -1,69 +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_RPC_METHOD_H__ -#define __GRPCPP_INTERNAL_RPC_METHOD_H__ - -namespace google { -namespace protobuf { -class Message; -} -} - -namespace grpc { - -class RpcMethod { - public: - enum RpcType { - NORMAL_RPC = 0, - CLIENT_STREAMING, // request streaming - SERVER_STREAMING, // response streaming - BIDI_STREAMING - }; - - explicit RpcMethod(const char* name) - : name_(name), method_type_(NORMAL_RPC) {} - RpcMethod(const char* name, RpcType type) : name_(name), method_type_(type) {} - - const char *name() const { return name_; } - - RpcType method_type() const { return method_type_; } - - private: - const char *name_; - const RpcType method_type_; -}; - -} // namespace grpc - -#endif // __GRPCPP_INTERNAL_RPC_METHOD_H__ diff --git a/src/cpp/server/async_server_context.cc b/src/cpp/server/async_server_context.cc index f44678b569..298936dec9 100644 --- a/src/cpp/server/async_server_context.cc +++ b/src/cpp/server/async_server_context.cc @@ -48,8 +48,7 @@ AsyncServerContext::AsyncServerContext( host_(host), absolute_deadline_(absolute_deadline), request_(nullptr), - call_(call) { -} + call_(call) {} AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); } diff --git a/src/cpp/server/rpc_service_method.h b/src/cpp/server/rpc_service_method.h deleted file mode 100644 index f4fe01c06b..0000000000 --- a/src/cpp/server/rpc_service_method.h +++ /dev/null @@ -1,214 +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_RPC_SERVICE_METHOD_H__ -#define __GRPCPP_INTERNAL_SERVER_RPC_SERVICE_METHOD_H__ - -#include <functional> -#include <map> -#include <memory> -#include <vector> - -#include "src/cpp/rpc_method.h" -#include <google/protobuf/message.h> -#include <grpc++/status.h> -#include <grpc++/stream.h> - -namespace grpc { -class ServerContext; -class StreamContextInterface; - -// TODO(rocking): we might need to split this file into multiple ones. - -// Base class for running an RPC handler. -class MethodHandler { - public: - virtual ~MethodHandler() {} - struct HandlerParameter { - HandlerParameter(ServerContext* context, const google::protobuf::Message* req, - google::protobuf::Message* resp) - : server_context(context), - request(req), - response(resp), - stream_context(nullptr) {} - HandlerParameter(ServerContext* context, const google::protobuf::Message* req, - google::protobuf::Message* resp, StreamContextInterface* stream) - : server_context(context), - request(req), - response(resp), - stream_context(stream) {} - ServerContext* server_context; - const google::protobuf::Message* request; - google::protobuf::Message* response; - StreamContextInterface* stream_context; - }; - virtual Status RunHandler(const HandlerParameter& param) = 0; -}; - -// A wrapper class of an application provided rpc method handler. -template <class ServiceType, class RequestType, class ResponseType> -class RpcMethodHandler : public MethodHandler { - public: - RpcMethodHandler( - std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ResponseType*)> func, - ServiceType* service) - : func_(func), service_(service) {} - - Status RunHandler(const HandlerParameter& param) final { - // Invoke application function, cast proto messages to their actual types. - return func_(service_, param.server_context, - dynamic_cast<const RequestType*>(param.request), - dynamic_cast<ResponseType*>(param.response)); - } - - private: - // Application provided rpc handler function. - std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ResponseType*)> func_; - // The class the above handler function lives in. - ServiceType* service_; -}; - -// A wrapper class of an application provided client streaming handler. -template <class ServiceType, class RequestType, class ResponseType> -class ClientStreamingHandler : public MethodHandler { - public: - ClientStreamingHandler( - std::function<Status(ServiceType*, ServerContext*, - ServerReader<RequestType>*, ResponseType*)> func, - ServiceType* service) - : func_(func), service_(service) {} - - Status RunHandler(const HandlerParameter& param) final { - ServerReader<RequestType> reader(param.stream_context); - return func_(service_, param.server_context, &reader, - dynamic_cast<ResponseType*>(param.response)); - } - - private: - std::function<Status(ServiceType*, ServerContext*, ServerReader<RequestType>*, - ResponseType*)> func_; - ServiceType* service_; -}; - -// A wrapper class of an application provided server streaming handler. -template <class ServiceType, class RequestType, class ResponseType> -class ServerStreamingHandler : public MethodHandler { - public: - ServerStreamingHandler( - std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ServerWriter<ResponseType>*)> func, - ServiceType* service) - : func_(func), service_(service) {} - - Status RunHandler(const HandlerParameter& param) final { - ServerWriter<ResponseType> writer(param.stream_context); - return func_(service_, param.server_context, - dynamic_cast<const RequestType*>(param.request), &writer); - } - - private: - std::function<Status(ServiceType*, ServerContext*, const RequestType*, - ServerWriter<ResponseType>*)> func_; - ServiceType* service_; -}; - -// A wrapper class of an application provided bidi-streaming handler. -template <class ServiceType, class RequestType, class ResponseType> -class BidiStreamingHandler : public MethodHandler { - public: - BidiStreamingHandler( - std::function<Status(ServiceType*, ServerContext*, - ServerReaderWriter<ResponseType, RequestType>*)> - func, - ServiceType* service) - : func_(func), service_(service) {} - - Status RunHandler(const HandlerParameter& param) final { - ServerReaderWriter<ResponseType, RequestType> stream(param.stream_context); - return func_(service_, param.server_context, &stream); - } - - private: - std::function<Status(ServiceType*, ServerContext*, - ServerReaderWriter<ResponseType, RequestType>*)> func_; - ServiceType* service_; -}; - -// Server side rpc method class -class RpcServiceMethod : public RpcMethod { - public: - // Takes ownership of the handler and two prototype objects. - RpcServiceMethod(const char* name, RpcMethod::RpcType type, - MethodHandler* handler, google::protobuf::Message* request_prototype, - google::protobuf::Message* response_prototype) - : RpcMethod(name, type), - handler_(handler), - request_prototype_(request_prototype), - response_prototype_(response_prototype) {} - - MethodHandler* handler() { return handler_.get(); } - - google::protobuf::Message* AllocateRequestProto() { return request_prototype_->New(); } - google::protobuf::Message* AllocateResponseProto() { - return response_prototype_->New(); - } - - private: - std::unique_ptr<MethodHandler> handler_; - std::unique_ptr<google::protobuf::Message> request_prototype_; - std::unique_ptr<google::protobuf::Message> response_prototype_; -}; - -// This class contains all the method information for an rpc service. It is -// used for registering a service on a grpc server. -class RpcService { - public: - // Takes ownership. - void AddMethod(RpcServiceMethod* method) { - methods_.push_back(std::unique_ptr<RpcServiceMethod>(method)); - } - - RpcServiceMethod* GetMethod(int i) { - return methods_[i].get(); - } - int GetMethodCount() const { return methods_.size(); } - - private: - std::vector<std::unique_ptr<RpcServiceMethod>> methods_; -}; - -} // namespace grpc - -#endif // __GRPCPP_INTERNAL_SERVER_RPC_SERVICE_METHOD_H__ diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index 2130befa7d..d85748eea4 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -37,11 +37,11 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> #include <grpc/support/log.h> -#include "src/cpp/server/rpc_service_method.h" #include "src/cpp/server/server_rpc_handler.h" #include "src/cpp/server/thread_pool.h" #include <grpc++/async_server_context.h> #include <grpc++/completion_queue.h> +#include <grpc++/impl/rpc_service_method.h> #include <grpc++/server_credentials.h> namespace grpc { diff --git a/src/cpp/server/server_context_impl.cc b/src/cpp/server/server_context_impl.cc index 13f2a3ae1a..467cc80e05 100644 --- a/src/cpp/server/server_context_impl.cc +++ b/src/cpp/server/server_context_impl.cc @@ -33,6 +33,4 @@ #include "src/cpp/server/server_context_impl.h" -namespace grpc { - -} // namespace grpc +namespace grpc {} // namespace grpc diff --git a/src/cpp/server/server_credentials.cc b/src/cpp/server/server_credentials.cc index f9ca1622ba..5d899b1cd9 100644 --- a/src/cpp/server/server_credentials.cc +++ b/src/cpp/server/server_credentials.cc @@ -31,7 +31,6 @@ * */ - #include <grpc/grpc_security.h> #include <grpc++/server_credentials.h> diff --git a/src/cpp/server/server_rpc_handler.cc b/src/cpp/server/server_rpc_handler.cc index 3954f04f97..42f8b755b6 100644 --- a/src/cpp/server/server_rpc_handler.cc +++ b/src/cpp/server/server_rpc_handler.cc @@ -34,10 +34,10 @@ #include "src/cpp/server/server_rpc_handler.h" #include <grpc/support/log.h> -#include "src/cpp/server/rpc_service_method.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 { @@ -60,8 +60,10 @@ void ServerRpcHandler::StartRpc() { 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()); + 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()); @@ -86,8 +88,10 @@ void ServerRpcHandler::StartRpc() { } 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()); + 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()); diff --git a/src/cpp/stream/stream_context.cc b/src/cpp/stream/stream_context.cc index 22b7e7d494..7936a30dfd 100644 --- a/src/cpp/stream/stream_context.cc +++ b/src/cpp/stream/stream_context.cc @@ -34,11 +34,11 @@ #include "src/cpp/stream/stream_context.h" #include <grpc/support/log.h> -#include "src/cpp/rpc_method.h" #include "src/cpp/proto/proto_utils.h" #include "src/cpp/util/time.h" #include <grpc++/client_context.h> #include <grpc++/config.h> +#include <grpc++/impl/rpc_method.h> #include <google/protobuf/message.h> namespace grpc { @@ -61,7 +61,8 @@ StreamContext::StreamContext(const RpcMethod& method, ClientContext* context, // Server only ctor StreamContext::StreamContext(const RpcMethod& method, grpc_call* call, grpc_completion_queue* cq, - google::protobuf::Message* request, google::protobuf::Message* result) + google::protobuf::Message* request, + google::protobuf::Message* result) : is_client_(false), method_(&method), call_(call), @@ -85,6 +86,10 @@ void StreamContext::Start(bool buffered) { GPR_ASSERT(GRPC_CALL_OK == error); grpc_event* invoke_ev = grpc_completion_queue_pluck(cq(), invoke_tag(), gpr_inf_future); + if (invoke_ev->data.invoke_accepted != GRPC_OP_OK) { + peer_halfclosed_ = true; + self_halfclosed_ = true; + } grpc_event_finish(invoke_ev); } else { // TODO(yangg) metadata needs to be added before accept diff --git a/src/cpp/stream/stream_context.h b/src/cpp/stream/stream_context.h index 6c31095042..f70fe6daa3 100644 --- a/src/cpp/stream/stream_context.h +++ b/src/cpp/stream/stream_context.h @@ -51,7 +51,8 @@ class RpcMethod; class StreamContext : public StreamContextInterface { public: StreamContext(const RpcMethod& method, ClientContext* context, - const google::protobuf::Message* request, google::protobuf::Message* result); + const google::protobuf::Message* request, + google::protobuf::Message* result); StreamContext(const RpcMethod& method, grpc_call* call, grpc_completion_queue* cq, google::protobuf::Message* request, google::protobuf::Message* result); @@ -81,11 +82,11 @@ class StreamContext : public StreamContextInterface { grpc_completion_queue* cq() { return cq_; } bool is_client_; - const RpcMethod* method_; // not owned - grpc_call* call_; // not owned - grpc_completion_queue* cq_; // not owned - google::protobuf::Message* request_; // first request, not owned - google::protobuf::Message* result_; // last response, not owned + const RpcMethod* method_; // not owned + grpc_call* call_; // not owned + grpc_completion_queue* cq_; // not owned + google::protobuf::Message* request_; // first request, not owned + google::protobuf::Message* result_; // last response, not owned bool peer_halfclosed_; bool self_halfclosed_; diff --git a/src/cpp/util/status.cc b/src/cpp/util/status.cc index 66be26da07..e7ca41b752 100644 --- a/src/cpp/util/status.cc +++ b/src/cpp/util/status.cc @@ -31,7 +31,6 @@ * */ - #include <grpc++/status.h> namespace grpc { |