diff options
author | yang-g <yangg@google.com> | 2015-08-13 11:15:53 -0700 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-08-13 11:15:53 -0700 |
commit | 9b7757dd356dae2549433d5b2686ce9a902c7bcc (patch) | |
tree | 73156a3771c071957f0c0cf8fd245ef84ec45061 /include/grpc++ | |
parent | abfa427d654529dec5ad0dad790f5bf7f991ac85 (diff) |
Use a sync service to handle requests to unknown services
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/completion_queue.h | 2 | ||||
-rw-r--r-- | include/grpc++/impl/rpc_service_method.h | 15 | ||||
-rw-r--r-- | include/grpc++/server.h | 2 | ||||
-rw-r--r-- | include/grpc++/server_context.h | 2 |
4 files changed, 21 insertions, 0 deletions
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 ServiceType, class RequestType, class ResponseType> class ServerStreamingHandler; template <class ServiceType, class RequestType, class ResponseType> class BidiStreamingHandler; +class UnknownMethodHandler; class ChannelInterface; class ClientContext; @@ -138,6 +139,7 @@ class CompletionQueue : public GrpcLibrary { friend class ServerStreamingHandler; template <class ServiceType, class RequestType, class ResponseType> friend class BidiStreamingHandler; + friend class UnknownMethodHandler; friend class ::grpc::Server; friend class ::grpc::ServerContext; template <class InputMessage, class OutputMessage> 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<CallOpSendInitialMetadata, CallOpServerSendStatus> 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<SyncRequest>* sync_methods_; + std::unique_ptr<RpcServiceMethod> 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 ServiceType, class RequestType, class ResponseType> class ServerStreamingHandler; template <class ServiceType, class RequestType, class ResponseType> class BidiStreamingHandler; +class UnknownMethodHandler; class Call; class CallOpBuffer; @@ -159,6 +160,7 @@ class ServerContext { friend class ServerStreamingHandler; template <class ServiceType, class RequestType, class ResponseType> friend class BidiStreamingHandler; + friend class UnknownMethodHandler; friend class ::grpc::ClientContext; // Prevent copying. |