diff options
author | Yash Tibrewal <yashkt@google.com> | 2017-11-30 10:54:42 -0800 |
---|---|---|
committer | Yash Tibrewal <yashkt@google.com> | 2017-11-30 10:54:42 -0800 |
commit | 10f2790f7fedb7b54889c9ba8297a9e127edb143 (patch) | |
tree | 899151af9bc4ab60aac48ab67de4e84c1cd8062a /include/grpc++ | |
parent | c354269ba7bd1f6dfe9c86ba18f38fc8e346dcfc (diff) | |
parent | 5f662537deb01539a204273977c7e32394fc3454 (diff) |
Merge branch 'master' into execctx
Diffstat (limited to 'include/grpc++')
-rw-r--r-- | include/grpc++/impl/codegen/call.h | 5 | ||||
-rw-r--r-- | include/grpc++/server_builder.h | 146 |
2 files changed, 83 insertions, 68 deletions
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 41e95866cf..af2c2b510c 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -313,11 +313,6 @@ class CallOpSendMessage { WriteOptions write_options_; }; -namespace internal { -template <class T> -T Example(); -} // namespace internal - template <class M> Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { write_options_ = options; diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index 0888bef0d9..e2bae4b41f 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -55,13 +55,18 @@ class ServerBuilder { ServerBuilder(); ~ServerBuilder(); - /// Options for synchronous servers. - enum SyncServerOption { - NUM_CQS, ///< Number of completion queues. - MIN_POLLERS, ///< Minimum number of polling threads. - MAX_POLLERS, ///< Maximum number of polling threads. - CQ_TIMEOUT_MSEC ///< Completion queue timeout in milliseconds. - }; + ////////////////////////////////////////////////////////////////////////////// + // Primary API's + + /// Return a running server which is ready for processing calls. + /// Before calling, one typically needs to ensure that: + /// 1. a service is registered - so that the server knows what to serve + /// (via RegisterService, or RegisterAsyncGenericService) + /// 2. a listening port has been added - so the server knows where to receive + /// traffic (via AddListeningPort) + /// 3. [for async api only] completion queues have been added via + /// AddCompletionQueue + std::unique_ptr<Server> 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 @@ -69,9 +74,60 @@ class ServerBuilder { /// Matches requests with any :authority ServerBuilder& RegisterService(Service* service); - /// Register a generic service. - /// Matches requests with any :authority - ServerBuilder& RegisterAsyncGenericService(AsyncGenericService* service); + /// Enlists an endpoint \a addr (port with an optional IP address) to + /// bind the \a grpc::Server object to be created to. + /// + /// It can be invoked multiple times. + /// + /// \param addr_uri The address to try to bind to the server in URI form. If + /// the scheme name is omitted, "dns:///" is assumed. To bind to any address, + /// please use IPv6 any, i.e., [::]:<port>, which also accepts IPv4 + /// connections. Valid values include dns:///localhost:1234, / + /// 192.168.1.1:31416, dns:///[::1]:27182, etc.). + /// \param creds The credentials associated with the server. + /// \param selected_port[out] If not `nullptr`, gets populated with the port + /// number bound to the \a grpc::Server for the corresponding endpoint after + /// it is successfully bound, 0 otherwise. + /// + ServerBuilder& AddListeningPort(const grpc::string& addr_uri, + std::shared_ptr<ServerCredentials> creds, + int* selected_port = nullptr); + + /// Add a completion queue for handling asynchronous services. + /// + /// Best performance is typically obtained by using one thread per polling + /// completion queue. + /// + /// Caller is required to shutdown the server prior to shutting down the + /// returned completion queue. Caller is also required to drain the + /// completion queue after shutting it down. A typical usage scenario: + /// + /// // While building the server: + /// ServerBuilder builder; + /// ... + /// cq_ = builder.AddCompletionQueue(); + /// server_ = builder.BuildAndStart(); + /// + /// // While shutting down the server; + /// server_->Shutdown(); + /// cq_->Shutdown(); // Always *after* the associated server's Shutdown()! + /// // Drain the cq_ that was created + /// void* ignored_tag; + /// bool ignored_ok; + /// while (cq_->Next(&ignored_tag, &ignored_ok)) { } + /// + /// \param is_frequently_polled This is an optional parameter to inform gRPC + /// library about whether this completion queue would be frequently polled + /// (i.e. by calling \a Next() or \a AsyncNext()). The default value is + /// 'true' and is the recommended setting. Setting this to 'false' (i.e. + /// not polling the completion queue frequently) will have a significantly + /// negative performance impact and hence should not be used in production + /// use cases. + std::unique_ptr<ServerCompletionQueue> AddCompletionQueue( + bool is_frequently_polled = true); + + ////////////////////////////////////////////////////////////////////////////// + // Less commonly used RegisterService variants /// 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 @@ -79,6 +135,15 @@ class ServerBuilder { /// Only matches requests with :authority \a host ServerBuilder& RegisterService(const grpc::string& host, Service* service); + /// Register a generic service. + /// Matches requests with any :authority + /// This is mostly useful for writing generic gRPC Proxies where the exact + /// serialization format is unknown + ServerBuilder& RegisterAsyncGenericService(AsyncGenericService* service); + + ////////////////////////////////////////////////////////////////////////////// + // Fine control knobs + /// Set max receive message size in bytes. ServerBuilder& SetMaxReceiveMessageSize(int max_receive_message_size) { max_receive_message_size_ = max_receive_message_size; @@ -119,6 +184,14 @@ class ServerBuilder { ServerBuilder& SetOption(std::unique_ptr<ServerBuilderOption> option); + /// Options for synchronous servers. + enum SyncServerOption { + NUM_CQS, ///< Number of completion queues. + MIN_POLLERS, ///< Minimum number of polling threads. + MAX_POLLERS, ///< Maximum number of polling threads. + CQ_TIMEOUT_MSEC ///< Completion queue timeout in milliseconds. + }; + /// Only useful if this is a Synchronous server. ServerBuilder& SetSyncServerOption(SyncServerOption option, int value); @@ -129,59 +202,6 @@ class ServerBuilder { return SetOption(MakeChannelArgumentOption(arg, value)); } - /// Enlists an endpoint \a addr (port with an optional IP address) to - /// bind the \a grpc::Server object to be created to. - /// - /// It can be invoked multiple times. - /// - /// \param addr_uri The address to try to bind to the server in URI form. If - /// the scheme name is omitted, "dns:///" is assumed. To bind to any address, - /// please use IPv6 any, i.e., [::]:<port>, which also accepts IPv4 - /// connections. Valid values include dns:///localhost:1234, / - /// 192.168.1.1:31416, dns:///[::1]:27182, etc.). - /// \param creds The credentials associated with the server. - /// \param selected_port[out] If not `nullptr`, gets populated with the port - /// number bound to the \a grpc::Server for the corresponding endpoint after - /// it is successfully bound, 0 otherwise. - /// - // TODO(dgq): the "port" part seems to be a misnomer. - ServerBuilder& AddListeningPort(const grpc::string& addr_uri, - std::shared_ptr<ServerCredentials> creds, - int* selected_port = nullptr); - - /// Add a completion queue for handling asynchronous services. - /// - /// Caller is required to shutdown the server prior to shutting down the - /// returned completion queue. Caller is also required to drain the - /// completion queue after shutting it down. A typical usage scenario: - /// - /// // While building the server: - /// ServerBuilder builder; - /// ... - /// cq_ = builder.AddCompletionQueue(); - /// server_ = builder.BuildAndStart(); - /// - /// // While shutting down the server; - /// server_->Shutdown(); - /// cq_->Shutdown(); // Always *after* the associated server's Shutdown()! - /// // Drain the cq_ that was created - /// void* ignored_tag; - /// bool ignored_ok; - /// while (cq_->Next(&ignored_tag, &ignored_ok)) { } - /// - /// \param is_frequently_polled This is an optional parameter to inform gRPC - /// library about whether this completion queue would be frequently polled - /// (i.e. by calling \a Next() or \a AsyncNext()). The default value is - /// 'true' and is the recommended setting. Setting this to 'false' (i.e. - /// not polling the completion queue frequently) will have a significantly - /// negative performance impact and hence should not be used in production - /// use cases. - std::unique_ptr<ServerCompletionQueue> AddCompletionQueue( - bool is_frequently_polled = true); - - /// Return a running server which is ready for processing calls. - std::unique_ptr<Server> BuildAndStart(); - /// For internal use only: Register a ServerBuilderPlugin factory function. static void InternalAddPluginFactory( std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()); |