From 8065000697a6225d76ebbcc8b7eca9f01a9be474 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Fri, 23 Feb 2018 14:51:46 -0800 Subject: [PATCH 01/16] Remove "final" keyword and make methods protected. This adds extensibility to the API and makes custom implementation of the server possible. --- .../grpcpp/impl/codegen/completion_queue.h | 10 +- include/grpcpp/server.h | 97 ++++++++++--------- include/grpcpp/server_builder.h | 36 +++---- src/cpp/server/server_cc.cc | 20 ++-- 4 files changed, 86 insertions(+), 77 deletions(-) diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 80c7c41982a..5ba70e2e660 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -165,7 +165,7 @@ class CompletionQueue : private GrpcLibraryCodegen { /// /// \return true if got an event, false if the queue is fully drained and /// shut down. - bool Next(void** tag, bool* ok) { + virtual bool Next(void** tag, bool* ok) { return (AsyncNextInternal(tag, ok, g_core_codegen_interface->gpr_inf_future( GPR_CLOCK_REALTIME)) != SHUTDOWN); @@ -365,9 +365,7 @@ class ServerCompletionQueue : public CompletionQueue { public: bool IsFrequentlyPolled() { return polling_type_ != GRPC_CQ_NON_LISTENING; } - private: - grpc_cq_polling_type polling_type_; - friend class ServerBuilder; + protected: /// \param is_frequently_polled Informs the GRPC library about whether the /// server completion queue would be actively polled (by calling Next() or /// AsyncNext()). By default all server completion queues are assumed to be @@ -376,6 +374,10 @@ class ServerCompletionQueue : public CompletionQueue { : CompletionQueue(grpc_completion_queue_attributes{ GRPC_CQ_CURRENT_VERSION, GRPC_CQ_NEXT, polling_type}), polling_type_(polling_type) {} + + private: + grpc_cq_polling_type polling_type_; + friend class ServerBuilder; }; } // namespace grpc diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index f99a6c26b4c..c75b4927349 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -49,7 +49,7 @@ class ServerInitializer; /// /// Use a \a grpc::ServerBuilder to create, configure, and start /// \a Server instances. -class Server final : public ServerInterface, private GrpcLibraryCodegen { +class Server : public ServerInterface, private GrpcLibraryCodegen { public: ~Server(); @@ -98,24 +98,26 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen { /// Establish a channel for in-process communication std::shared_ptr InProcessChannel(const ChannelArguments& args); - private: - friend class AsyncGenericService; - friend class ServerBuilder; - friend class ServerInitializer; - - class SyncRequest; - class AsyncRequest; - class ShutdownRequest; - - /// SyncRequestThreadManager is an implementation of ThreadManager. This class - /// is responsible for polling for incoming RPCs and calling the RPC handlers. - /// This is only used in case of a Sync server (i.e a server exposing a sync - /// interface) - class SyncRequestThreadManager; +protected: + /// Register a service. This call does not take ownership of the service. + /// The service must exist for the lifetime of the Server instance. + bool RegisterService(const grpc::string* host, Service* service) override; - class UnimplementedAsyncRequestContext; - class UnimplementedAsyncRequest; - class UnimplementedAsyncResponse; + /// Try binding the server to the given \a addr endpoint + /// (port, and optionally including IP address to bind to). + /// + /// It can be invoked multiple times. Should be used before + /// starting the server. + /// + /// \param addr The address to try to bind to the server (eg, localhost:1234, + /// 192.168.1.1:31416, [::1]:27182, etc.). + /// \param creds The credentials associated with the server. + /// + /// \return bound port number on success, 0 on failure. + /// + /// \warning It is an error to call this method on an already started server. + int AddListeningPort(const grpc::string& addr, + ServerCredentials* creds) override; /// Server constructors. To be used by \a ServerBuilder only. /// @@ -143,30 +145,6 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen { sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec); - /// Register a service. This call does not take ownership of the service. - /// The service must exist for the lifetime of the Server instance. - bool RegisterService(const grpc::string* host, Service* service) override; - - /// Register a generic service. This call does not take ownership of the - /// service. The service must exist for the lifetime of the Server instance. - void RegisterAsyncGenericService(AsyncGenericService* service) override; - - /// Try binding the server to the given \a addr endpoint - /// (port, and optionally including IP address to bind to). - /// - /// It can be invoked multiple times. Should be used before - /// starting the server. - /// - /// \param addr The address to try to bind to the server (eg, localhost:1234, - /// 192.168.1.1:31416, [::1]:27182, etc.). - /// \param creds The credentials associated with the server. - /// - /// \return bound port number on success, 0 on failure. - /// - /// \warning It is an error to call this method on an already started server. - int AddListeningPort(const grpc::string& addr, - ServerCredentials* creds) override; - /// Start the server. /// /// \param cqs Completion queues for handling asynchronous services. The @@ -175,6 +153,35 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen { /// \param num_cqs How many completion queues does \a cqs hold. void Start(ServerCompletionQueue** cqs, size_t num_cqs) override; + // Pointer to the wrapped grpc_server. + grpc_server* server_; + + // Server status + bool started_; + + private: + friend class AsyncGenericService; + friend class ServerBuilder; + friend class ServerInitializer; + + class SyncRequest; + class AsyncRequest; + class ShutdownRequest; + + /// SyncRequestThreadManager is an implementation of ThreadManager. This class + /// is responsible for polling for incoming RPCs and calling the RPC handlers. + /// This is only used in case of a Sync server (i.e a server exposing a sync + /// interface) + class SyncRequestThreadManager; + + class UnimplementedAsyncRequestContext; + class UnimplementedAsyncRequest; + class UnimplementedAsyncResponse; + + /// Register a generic service. This call does not take ownership of the + /// service. The service must exist for the lifetime of the Server instance. + void RegisterAsyncGenericService(AsyncGenericService* service) override; + void PerformOpsOnCall(internal::CallOpSetInterface* ops, internal::Call* call) override; @@ -200,9 +207,8 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen { /// the \a sync_server_cqs) std::vector> sync_req_mgrs_; - // Sever status + // Server status std::mutex mu_; - bool started_; bool shutdown_; bool shutdown_notified_; // Was notify called on the shutdown_cv_ @@ -213,9 +219,6 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen { std::vector services_; bool has_generic_service_; - // Pointer to the wrapped grpc_server. - grpc_server* server_; - std::unique_ptr server_initializer_; std::unique_ptr health_check_service_; diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index c35a6cf98a9..8f148bcd06b 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -52,7 +52,7 @@ class ServerBuilderPluginTest; class ServerBuilder { public: ServerBuilder(); - ~ServerBuilder(); + virtual ~ServerBuilder(); ////////////////////////////////////////////////////////////////////////////// // Primary API's @@ -65,7 +65,7 @@ class ServerBuilder { /// traffic (via AddListeningPort) /// 3. [for async api only] completion queues have been added via /// AddCompletionQueue - std::unique_ptr BuildAndStart(); + virtual std::unique_ptr BuildAndStart(); /// Register a service. This call does not take ownership of the service. /// The service must exist for the lifetime of the \a Server instance returned @@ -210,15 +210,29 @@ class ServerBuilder { /// doc/workarounds.md. ServerBuilder& EnableWorkaround(grpc_workaround_list id); - private: - friend class ::grpc::testing::ServerBuilderPluginTest; - + protected: struct Port { grpc::string addr; std::shared_ptr creds; int* selected_port; }; + typedef std::unique_ptr HostString; + struct NamedService { + explicit NamedService(Service* s) : service(s) {} + NamedService(const grpc::string& h, Service* s) + : host(new grpc::string(h)), service(s) {} + HostString host; + Service* service; + }; + + std::vector> options_; + std::vector> services_; + std::vector ports_; + + private: + friend class ::grpc::testing::ServerBuilderPluginTest; + struct SyncServerSettings { SyncServerSettings() : num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {} @@ -238,20 +252,8 @@ class ServerBuilder { int cq_timeout_msec; }; - typedef std::unique_ptr HostString; - struct NamedService { - explicit NamedService(Service* s) : service(s) {} - NamedService(const grpc::string& h, Service* s) - : host(new grpc::string(h)), service(s) {} - HostString host; - Service* service; - }; - int max_receive_message_size_; int max_send_message_size_; - std::vector> options_; - std::vector> services_; - std::vector ports_; SyncServerSettings sync_server_settings_; diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 5638636e67d..067f292b6e1 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -368,13 +368,13 @@ Server::Server( std::shared_ptr>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec) - : max_receive_message_size_(max_receive_message_size), - sync_server_cqs_(sync_server_cqs), + : server_(nullptr), started_(false), + max_receive_message_size_(max_receive_message_size), + sync_server_cqs_(sync_server_cqs), shutdown_(false), shutdown_notified_(false), has_generic_service_(false), - server_(nullptr), server_initializer_(new ServerInitializer(this)), health_check_service_disabled_(false) { g_gli_initializer.summon(); @@ -382,11 +382,13 @@ Server::Server( global_callbacks_ = g_callbacks; global_callbacks_->UpdateArguments(args); - for (auto it = sync_server_cqs_->begin(); it != sync_server_cqs_->end(); - it++) { - sync_req_mgrs_.emplace_back(new SyncRequestThreadManager( - this, (*it).get(), global_callbacks_, min_pollers, max_pollers, - sync_cq_timeout_msec)); + if (sync_server_cqs_ != nullptr) { + for (auto it = sync_server_cqs_->begin(); it != sync_server_cqs_->end(); + it++) { + sync_req_mgrs_.emplace_back(new SyncRequestThreadManager( + this, (*it).get(), global_callbacks_, min_pollers, max_pollers, + sync_cq_timeout_msec)); + } } grpc_channel_args channel_args; @@ -525,7 +527,7 @@ void Server::Start(ServerCompletionQueue** cqs, size_t num_cqs) { // explicit one. if (health_check_service_ == nullptr && !health_check_service_disabled_ && DefaultHealthCheckServiceEnabled()) { - if (sync_server_cqs_->empty()) { + if (sync_server_cqs_ == nullptr || sync_server_cqs_->empty()) { gpr_log(GPR_INFO, "Default health check service disabled at async-only server."); } else { From ae038c1d47025b1ed17beb1802c8543ebf0b38b4 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 26 Feb 2018 14:01:00 -0800 Subject: [PATCH 02/16] Implement newly virtualized "Next" --- test/cpp/codegen/codegen_test_minimal.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/cpp/codegen/codegen_test_minimal.cc b/test/cpp/codegen/codegen_test_minimal.cc index d317ea31164..230ba9d2b41 100644 --- a/test/cpp/codegen/codegen_test_minimal.cc +++ b/test/cpp/codegen/codegen_test_minimal.cc @@ -17,8 +17,15 @@ */ #include +#include namespace grpc { + +// Unused implementation for the virtual "Next" method. +bool CompletionQueue::Next(void** tag, bool* ok) { + return false; +} + namespace { class CodegenTestMinimal : public ::testing::Test {}; From e1a7283dd30d9f44c1c555225d14b92a3c2c8b8f Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 26 Feb 2018 14:55:56 -0800 Subject: [PATCH 03/16] moved Next implementation to CC file. --- include/grpcpp/impl/codegen/completion_queue.h | 6 +----- src/cpp/common/completion_queue_cc.cc | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 5ba70e2e660..86fa634df83 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -165,11 +165,7 @@ class CompletionQueue : private GrpcLibraryCodegen { /// /// \return true if got an event, false if the queue is fully drained and /// shut down. - virtual bool Next(void** tag, bool* ok) { - return (AsyncNextInternal(tag, ok, - g_core_codegen_interface->gpr_inf_future( - GPR_CLOCK_REALTIME)) != SHUTDOWN); - } + virtual bool Next(void** tag, bool* ok); /// Read from the queue, blocking up to \a deadline (or the queue's shutdown). /// Both \a tag and \a ok are updated upon success (if an event is available diff --git a/src/cpp/common/completion_queue_cc.cc b/src/cpp/common/completion_queue_cc.cc index 6893201e2e3..b3af25fbf95 100644 --- a/src/cpp/common/completion_queue_cc.cc +++ b/src/cpp/common/completion_queue_cc.cc @@ -50,6 +50,12 @@ void CompletionQueue::CompleteAvalanching() { } } +bool CompletionQueue::Next(void** tag, bool* ok) { + return (AsyncNextInternal(tag, ok, + g_core_codegen_interface->gpr_inf_future( + GPR_CLOCK_REALTIME)) != SHUTDOWN); +} + CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( void** tag, bool* ok, gpr_timespec deadline) { for (;;) { From 57237443ac86c8f46d9b028a06c27b72318404b2 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 26 Feb 2018 16:03:57 -0800 Subject: [PATCH 04/16] clang-format --- include/grpcpp/server.h | 2 +- test/cpp/codegen/codegen_test_minimal.cc | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index c75b4927349..b09c590a7e6 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -98,7 +98,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { /// Establish a channel for in-process communication std::shared_ptr InProcessChannel(const ChannelArguments& args); -protected: + protected: /// Register a service. This call does not take ownership of the service. /// The service must exist for the lifetime of the Server instance. bool RegisterService(const grpc::string* host, Service* service) override; diff --git a/test/cpp/codegen/codegen_test_minimal.cc b/test/cpp/codegen/codegen_test_minimal.cc index 230ba9d2b41..a614848184f 100644 --- a/test/cpp/codegen/codegen_test_minimal.cc +++ b/test/cpp/codegen/codegen_test_minimal.cc @@ -16,15 +16,13 @@ * */ -#include #include +#include namespace grpc { // Unused implementation for the virtual "Next" method. -bool CompletionQueue::Next(void** tag, bool* ok) { - return false; -} +bool CompletionQueue::Next(void** tag, bool* ok) { return false; } namespace { From 838af3eb6c6c6e7d49931ddc5c7e9c4fd26f2a18 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Fri, 9 Mar 2018 09:39:42 -0800 Subject: [PATCH 05/16] moved member variables from protected to private Per style guide, the member variables are not protected but private and accessed through methods. --- include/grpcpp/server.h | 13 ++++++------- include/grpcpp/server_builder.h | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index b09c590a7e6..77ae7206b47 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -153,11 +153,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { /// \param num_cqs How many completion queues does \a cqs hold. void Start(ServerCompletionQueue** cqs, size_t num_cqs) override; - // Pointer to the wrapped grpc_server. - grpc_server* server_; - - // Server status - bool started_; + grpc_server* server() override { return server_; }; private: friend class AsyncGenericService; @@ -191,8 +187,6 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { return max_receive_message_size_; }; - grpc_server* server() override { return server_; }; - ServerInitializer* initializer(); const int max_receive_message_size_; @@ -209,6 +203,8 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // Server status std::mutex mu_; + // Server status + bool started_; bool shutdown_; bool shutdown_notified_; // Was notify called on the shutdown_cv_ @@ -219,6 +215,9 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { std::vector services_; bool has_generic_service_; + // Pointer to the wrapped grpc_server. + grpc_server* server_; + std::unique_ptr server_initializer_; std::unique_ptr health_check_service_; diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index 8f148bcd06b..5ae0fb161d6 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -226,9 +226,24 @@ class ServerBuilder { Service* service; }; - std::vector> options_; - std::vector> services_; - std::vector ports_; + std::vector ports() { return ports_; } + + std::vector> services() { + std::vector> service_refs; + for (auto &ptr : services_) { + service_refs.push_back(std::ref(*ptr)); + } + return service_refs; + } + + std::vector> options() { + std::vector> option_refs; + for (auto &ptr : options_) { + option_refs.push_back(std::ref(*ptr)); + } + return option_refs; + } + private: friend class ::grpc::testing::ServerBuilderPluginTest; @@ -254,6 +269,9 @@ class ServerBuilder { int max_receive_message_size_; int max_send_message_size_; + std::vector> options_; + std::vector> services_; + std::vector ports_; SyncServerSettings sync_server_settings_; From 9cd0099a5354bbb55ceafa5b675b65a31b6da39c Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Fri, 9 Mar 2018 09:42:22 -0800 Subject: [PATCH 06/16] variable init sequence fix --- src/cpp/server/server_cc.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 067f292b6e1..18b0b182b12 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -368,13 +368,13 @@ Server::Server( std::shared_ptr>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec) - : server_(nullptr), - started_(false), - max_receive_message_size_(max_receive_message_size), + : max_receive_message_size_(max_receive_message_size), sync_server_cqs_(sync_server_cqs), + started_(false), shutdown_(false), shutdown_notified_(false), has_generic_service_(false), + server_(nullptr), server_initializer_(new ServerInitializer(this)), health_check_service_disabled_(false) { g_gli_initializer.summon(); From 757af97ad0fe57f2cc6fcb8c0af4eebaf6bc3e15 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Fri, 9 Mar 2018 10:46:35 -0800 Subject: [PATCH 07/16] added ///Experimental in comment for c_server Please enter the commit message for your changes. Lines starting --- include/grpcpp/server.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index 77ae7206b47..69d7a3f4786 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -87,7 +87,8 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { /// application and is shared among all \a Server objects. static void SetGlobalCallbacks(GlobalCallbacks* callbacks); - // Returns a \em raw pointer to the underlying \a grpc_server instance. + /// Returns a \em raw pointer to the underlying \a grpc_server instance. + /// EXPERIMENTAL: for internal/test use only grpc_server* c_server(); /// Returns the health check service. From c8e523351e472839b076d12c976e86f278ae1f3c Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Fri, 9 Mar 2018 13:47:46 -0800 Subject: [PATCH 08/16] clang-format --- include/grpcpp/server_builder.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index 5ae0fb161d6..0a5348117eb 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -230,7 +230,7 @@ class ServerBuilder { std::vector> services() { std::vector> service_refs; - for (auto &ptr : services_) { + for (auto& ptr : services_) { service_refs.push_back(std::ref(*ptr)); } return service_refs; @@ -238,13 +238,12 @@ class ServerBuilder { std::vector> options() { std::vector> option_refs; - for (auto &ptr : options_) { + for (auto& ptr : options_) { option_refs.push_back(std::ref(*ptr)); } return option_refs; } - private: friend class ::grpc::testing::ServerBuilderPluginTest; From d10a885922387c7237dc5d26ec4db8c1474a70cd Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 12 Mar 2018 10:12:01 -0700 Subject: [PATCH 09/16] removed unnecessary "virtual" Removed unnecessary "virtual" keyword from CompletionQueue::Next. Reverted two files that no longer need to be changed. --- src/cpp/common/completion_queue_cc.cc | 6 ------ test/cpp/codegen/codegen_test_minimal.cc | 5 ----- 2 files changed, 11 deletions(-) diff --git a/src/cpp/common/completion_queue_cc.cc b/src/cpp/common/completion_queue_cc.cc index b3af25fbf95..6893201e2e3 100644 --- a/src/cpp/common/completion_queue_cc.cc +++ b/src/cpp/common/completion_queue_cc.cc @@ -50,12 +50,6 @@ void CompletionQueue::CompleteAvalanching() { } } -bool CompletionQueue::Next(void** tag, bool* ok) { - return (AsyncNextInternal(tag, ok, - g_core_codegen_interface->gpr_inf_future( - GPR_CLOCK_REALTIME)) != SHUTDOWN); -} - CompletionQueue::NextStatus CompletionQueue::AsyncNextInternal( void** tag, bool* ok, gpr_timespec deadline) { for (;;) { diff --git a/test/cpp/codegen/codegen_test_minimal.cc b/test/cpp/codegen/codegen_test_minimal.cc index a614848184f..d317ea31164 100644 --- a/test/cpp/codegen/codegen_test_minimal.cc +++ b/test/cpp/codegen/codegen_test_minimal.cc @@ -16,14 +16,9 @@ * */ -#include #include namespace grpc { - -// Unused implementation for the virtual "Next" method. -bool CompletionQueue::Next(void** tag, bool* ok) { return false; } - namespace { class CodegenTestMinimal : public ::testing::Test {}; From 1d603248f29493d9faca01999d7e793a48a5b1fd Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 12 Mar 2018 10:37:52 -0700 Subject: [PATCH 10/16] forgot to add completion_queue.h doh! --- include/grpcpp/impl/codegen/completion_queue.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 86fa634df83..ea43777bfcc 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -165,7 +165,11 @@ class CompletionQueue : private GrpcLibraryCodegen { /// /// \return true if got an event, false if the queue is fully drained and /// shut down. - virtual bool Next(void** tag, bool* ok); + bool Next(void** tag, bool* ok) { + return (AsyncNextInternal(tag, ok, + g_core_codegen_interface->gpr_inf_future( + GPR_CLOCK_REALTIME)) != SHUTDOWN); + } /// Read from the queue, blocking up to \a deadline (or the queue's shutdown). /// Both \a tag and \a ok are updated upon success (if an event is available From d10c4e1e8e55c6b6cae8c112b19929c125caf731 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 12 Mar 2018 11:07:35 -0700 Subject: [PATCH 11/16] added "Experimental" and returned raw pointers Added experimental in the comment and removed reference_wrapper in favor of the raw pointer. --- include/grpcpp/server_builder.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index 0a5348117eb..54d3cc1d59b 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -226,20 +226,23 @@ class ServerBuilder { Service* service; }; + /// Experimental, to be deprecated std::vector ports() { return ports_; } - std::vector> services() { - std::vector> service_refs; + /// Experimental, to be deprecated + std::vector services() { + std::vector service_refs; for (auto& ptr : services_) { - service_refs.push_back(std::ref(*ptr)); + service_refs.push_back(ptr.get()); } return service_refs; } - std::vector> options() { - std::vector> option_refs; + /// Experimental, to be deprecated + std::vector options() { + std::vector option_refs; for (auto& ptr : options_) { - option_refs.push_back(std::ref(*ptr)); + option_refs.push_back(ptr.get()); } return option_refs; } From 606742d30cb178b3abd06be4ab166a95785190b8 Mon Sep 17 00:00:00 2001 From: makdharma <> Date: Mon, 12 Mar 2018 14:30:51 -0700 Subject: [PATCH 12/16] replaced loop with range expression --- src/cpp/server/server_cc.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 18b0b182b12..760aaa4b4d2 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -383,10 +383,9 @@ Server::Server( global_callbacks_->UpdateArguments(args); if (sync_server_cqs_ != nullptr) { - for (auto it = sync_server_cqs_->begin(); it != sync_server_cqs_->end(); - it++) { + for (const auto& it : *sync_server_cqs_) { sync_req_mgrs_.emplace_back(new SyncRequestThreadManager( - this, (*it).get(), global_callbacks_, min_pollers, max_pollers, + this, it.get(), global_callbacks_, min_pollers, max_pollers, sync_cq_timeout_msec)); } } From dbf4b71a00861013ec69d39782203fd995fdc147 Mon Sep 17 00:00:00 2001 From: makdharma Date: Tue, 13 Mar 2018 09:06:40 -0700 Subject: [PATCH 13/16] added Experimental in comments For "struct Port" and friends, since they are now protected instead of private. --- include/grpcpp/server_builder.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/grpcpp/server_builder.h b/include/grpcpp/server_builder.h index 54d3cc1d59b..4c8dcf49167 100644 --- a/include/grpcpp/server_builder.h +++ b/include/grpcpp/server_builder.h @@ -211,12 +211,14 @@ class ServerBuilder { ServerBuilder& EnableWorkaround(grpc_workaround_list id); protected: + /// Experimental, to be deprecated struct Port { grpc::string addr; std::shared_ptr creds; int* selected_port; }; + /// Experimental, to be deprecated typedef std::unique_ptr HostString; struct NamedService { explicit NamedService(Service* s) : service(s) {} From 626a65e877ef90d4e975c221ad24cad4d9187cce Mon Sep 17 00:00:00 2001 From: makdharma Date: Tue, 13 Mar 2018 09:46:08 -0700 Subject: [PATCH 14/16] Added protected default constructor --- include/grpcpp/impl/codegen/completion_queue.h | 5 ++++- include/grpcpp/server.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index ea43777bfcc..104a6031293 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -366,6 +366,10 @@ class ServerCompletionQueue : public CompletionQueue { bool IsFrequentlyPolled() { return polling_type_ != GRPC_CQ_NON_LISTENING; } protected: + // Default constructor + ServerCompletionQueue() {} + + private: /// \param is_frequently_polled Informs the GRPC library about whether the /// server completion queue would be actively polled (by calling Next() or /// AsyncNext()). By default all server completion queues are assumed to be @@ -375,7 +379,6 @@ class ServerCompletionQueue : public CompletionQueue { GRPC_CQ_CURRENT_VERSION, GRPC_CQ_NEXT, polling_type}), polling_type_(polling_type) {} - private: grpc_cq_polling_type polling_type_; friend class ServerBuilder; }; diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index 69d7a3f4786..6056003fcd7 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -204,7 +204,7 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // Server status std::mutex mu_; - // Server status + bool started_; bool shutdown_; bool shutdown_notified_; // Was notify called on the shutdown_cv_ From 589e2cfe098d6e98d1bfe79c72eb1c4d41a72c01 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 13 Mar 2018 09:52:00 -0700 Subject: [PATCH 15/16] Update completion_queue.h --- include/grpcpp/impl/codegen/completion_queue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpcpp/impl/codegen/completion_queue.h b/include/grpcpp/impl/codegen/completion_queue.h index 104a6031293..9713333cf5b 100644 --- a/include/grpcpp/impl/codegen/completion_queue.h +++ b/include/grpcpp/impl/codegen/completion_queue.h @@ -366,7 +366,7 @@ class ServerCompletionQueue : public CompletionQueue { bool IsFrequentlyPolled() { return polling_type_ != GRPC_CQ_NON_LISTENING; } protected: - // Default constructor + /// Default constructor ServerCompletionQueue() {} private: From 3c3c4c913a9f15e17f89c0c39146314445d5d93d Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 13 Mar 2018 09:53:28 -0700 Subject: [PATCH 16/16] Update server.h --- include/grpcpp/server.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/grpcpp/server.h b/include/grpcpp/server.h index 6056003fcd7..e88e7966dc5 100644 --- a/include/grpcpp/server.h +++ b/include/grpcpp/server.h @@ -204,7 +204,6 @@ class Server : public ServerInterface, private GrpcLibraryCodegen { // Server status std::mutex mu_; - bool started_; bool shutdown_; bool shutdown_notified_; // Was notify called on the shutdown_cv_