From 9b7757dd356dae2549433d5b2686ce9a902c7bcc Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 13 Aug 2015 11:15:53 -0700 Subject: Use a sync service to handle requests to unknown services --- include/grpc++/completion_queue.h | 2 ++ include/grpc++/impl/rpc_service_method.h | 15 +++++++++++++++ include/grpc++/server.h | 2 ++ include/grpc++/server_context.h | 2 ++ 4 files changed, 21 insertions(+) (limited to 'include/grpc++') diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h index 0523ab6a0e..2f30211145 100644 --- a/include/grpc++/completion_queue.h +++ b/include/grpc++/completion_queue.h @@ -63,6 +63,7 @@ template class ServerStreamingHandler; template class BidiStreamingHandler; +class UnknownMethodHandler; class ChannelInterface; class ClientContext; @@ -138,6 +139,7 @@ class CompletionQueue : public GrpcLibrary { friend class ServerStreamingHandler; template friend class BidiStreamingHandler; + friend class UnknownMethodHandler; friend class ::grpc::Server; friend class ::grpc::ServerContext; template diff --git a/include/grpc++/impl/rpc_service_method.h b/include/grpc++/impl/rpc_service_method.h index 3cfbef7806..925801e1ce 100644 --- a/include/grpc++/impl/rpc_service_method.h +++ b/include/grpc++/impl/rpc_service_method.h @@ -208,6 +208,21 @@ class BidiStreamingHandler : public MethodHandler { ServiceType* service_; }; +// Handle unknown method by returning UNIMPLEMENTED error. +class UnknownMethodHandler : public MethodHandler { + public: + void RunHandler(const HandlerParameter& param) GRPC_FINAL { + Status status(StatusCode::UNIMPLEMENTED, ""); + CallOpSet ops; + if (!param.server_context->sent_initial_metadata_) { + ops.SendInitialMetadata(param.server_context->initial_metadata_); + } + ops.ServerSendStatus(param.server_context->trailing_metadata_, status); + param.call->PerformOps(&ops); + param.call->cq()->Pluck(&ops); + } +}; + // Server side rpc method class class RpcServiceMethod : public RpcMethod { public: diff --git a/include/grpc++/server.h b/include/grpc++/server.h index 94ee0b6a4a..8755b4b445 100644 --- a/include/grpc++/server.h +++ b/include/grpc++/server.h @@ -228,6 +228,8 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook { grpc::condition_variable callback_cv_; std::list* sync_methods_; + std::unique_ptr unknown_method_; + bool has_generic_service_; // Pointer to the c grpc server. grpc_server* const server_; diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 4f7fc54ef1..8262dee654 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -73,6 +73,7 @@ template class ServerStreamingHandler; template class BidiStreamingHandler; +class UnknownMethodHandler; class Call; class CallOpBuffer; @@ -159,6 +160,7 @@ class ServerContext { friend class ServerStreamingHandler; template friend class BidiStreamingHandler; + friend class UnknownMethodHandler; friend class ::grpc::ClientContext; // Prevent copying. -- cgit v1.2.3