|
GRPC C++
1.80.0
|
A builder class for the creation and startup of grpc::Server instances. More...
#include <server_builder.h>
Data Structures | |
| class | experimental_type |
| NOTE: class experimental_type is not part of the public API of this class. More... | |
| struct | NamedService |
| struct | Port |
| Experimental, to be deprecated. More... | |
Public Types | |
| enum | SyncServerOption { NUM_CQS, MIN_POLLERS, MAX_POLLERS, CQ_TIMEOUT_MSEC } |
| Options for synchronous servers. More... | |
Public Member Functions | |
| ServerBuilder () | |
| virtual | ~ServerBuilder () |
| virtual std::unique_ptr< grpc::Server > | BuildAndStart () |
| Return a running server which is ready for processing calls. More... | |
| ServerBuilder & | RegisterService (grpc::Service *service) |
| Register a service. More... | |
| ServerBuilder & | AddListeningPort (const std::string &addr_uri, std::shared_ptr< grpc::ServerCredentials > creds, int *selected_port=nullptr) |
| Enlists an endpoint addr (port with an optional IP address) to bind the grpc::Server object to be created to. More... | |
| std::unique_ptr< grpc::ServerCompletionQueue > | AddCompletionQueue (bool is_frequently_polled=true) |
| Add a completion queue for handling asynchronous services. More... | |
| ServerBuilder & | RegisterService (const std::string &host, grpc::Service *service) |
| Register a service. More... | |
| ServerBuilder & | RegisterAsyncGenericService (grpc::AsyncGenericService *service) |
| Register a generic service. More... | |
| ServerBuilder & | SetMaxReceiveMessageSize (int max_receive_message_size) |
| Set max receive message size in bytes. More... | |
| ServerBuilder & | SetMaxSendMessageSize (int max_send_message_size) |
| Set max send message size in bytes. More... | |
| ServerBuilder & | SetMaxMessageSize (int max_message_size) |
| ServerBuilder & | SetCompressionAlgorithmSupportStatus (grpc_compression_algorithm algorithm, bool enabled) |
| Set the support status for compression algorithms. More... | |
| ServerBuilder & | SetDefaultCompressionLevel (grpc_compression_level level) |
| The default compression level to use for all channel calls in the absence of a call-specific level. More... | |
| ServerBuilder & | SetDefaultCompressionAlgorithm (grpc_compression_algorithm algorithm) |
| The default compression algorithm to use for all channel calls in the absence of a call-specific level. More... | |
| ServerBuilder & | SetResourceQuota (const grpc::ResourceQuota &resource_quota) |
| Set the attached buffer pool for this server. More... | |
| ServerBuilder & | SetEventEngine (std::shared_ptr< grpc_event_engine::experimental::EventEngine > event_engine) |
| ServerBuilder & | SetOption (std::unique_ptr< grpc::ServerBuilderOption > option) |
| ServerBuilder & | SetSyncServerOption (SyncServerOption option, int value) |
| Only useful if this is a Synchronous server. More... | |
| template<class T > | |
| ServerBuilder & | AddChannelArgument (const std::string &arg, const T &value) |
| Add a channel argument (an escape hatch to tuning core library parameters directly) More... | |
| ServerBuilder & | EnableWorkaround (grpc_workaround_list id) |
| Enable a server workaround. More... | |
| ServerBuilder & | SetContextAllocator (std::unique_ptr< grpc::ContextAllocator > context_allocator) |
| Set the allocator for creating and releasing callback server context. More... | |
| ServerBuilder & | RegisterCallbackGenericService (grpc::CallbackGenericService *service) |
| Register a generic service that uses the callback API. More... | |
| experimental_type | experimental () |
| NOTE: The function experimental() is not stable public API. More... | |
Static Public Member Functions | |
| static void | InternalAddPluginFactory (std::unique_ptr< grpc::ServerBuilderPlugin >(*CreatePlugin)()) |
| For internal use only: Register a ServerBuilderPlugin factory function. More... | |
Protected Types | |
| typedef std::unique_ptr< std::string > | HostString |
| Experimental, to be deprecated. More... | |
Protected Member Functions | |
| std::vector< Port > | ports () |
| Experimental, to be deprecated. More... | |
| std::vector< NamedService * > | services () |
| Experimental, to be deprecated. More... | |
| std::vector< grpc::ServerBuilderOption * > | options () |
| Experimental, to be deprecated. More... | |
| void | set_fetcher (grpc_server_config_fetcher *server_config_fetcher) |
| Experimental API, subject to change. More... | |
| virtual ChannelArguments | BuildChannelArgs () |
| Experimental API, subject to change. More... | |
Friends | |
| class | grpc::testing::ServerBuilderPluginTest |
A builder class for the creation and startup of grpc::Server instances.
|
protected |
Experimental, to be deprecated.
| grpc::ServerBuilder::ServerBuilder | ( | ) |
|
virtual |
|
inline |
Add a channel argument (an escape hatch to tuning core library parameters directly)
| std::unique_ptr<grpc::ServerCompletionQueue> grpc::ServerBuilder::AddCompletionQueue | ( | bool | is_frequently_polled = true | ) |
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)) { }
| 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 Next() or 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. |
| ServerBuilder& grpc::ServerBuilder::AddListeningPort | ( | const std::string & | addr_uri, |
| std::shared_ptr< grpc::ServerCredentials > | creds, | ||
| int * | selected_port = nullptr |
||
| ) |
Enlists an endpoint addr (port with an optional IP address) to bind the grpc::Server object to be created to.
It can be invoked multiple times.
| 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. | |
| creds | The credentials associated with the server. | |
| [out] | selected_port | If not nullptr, gets populated with the port number bound to the grpc::Server for the corresponding endpoint after it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort does not modify this pointer. |
|
virtual |
Return a running server which is ready for processing calls.
Before calling, one typically needs to ensure that:
Will return a nullptr on errors.
|
protectedvirtual |
Experimental API, subject to change.
| ServerBuilder& grpc::ServerBuilder::EnableWorkaround | ( | grpc_workaround_list | id | ) |
Enable a server workaround.
Do not use unless you know what the workaround does. For explanation and detailed descriptions of workarounds, see doc/workarounds.md.
|
inline |
NOTE: The function experimental() is not stable public API.
It is a view to the experimental components of this class. It may be changed or removed at any time.
|
static |
For internal use only: Register a ServerBuilderPlugin factory function.
|
inlineprotected |
Experimental, to be deprecated.
|
inlineprotected |
Experimental, to be deprecated.
| ServerBuilder& grpc::ServerBuilder::RegisterAsyncGenericService | ( | grpc::AsyncGenericService * | 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& grpc::ServerBuilder::RegisterCallbackGenericService | ( | grpc::CallbackGenericService * | service | ) |
Register a generic service that uses the callback API.
Matches requests with any :authority This is mostly useful for writing generic gRPC Proxies where the exact serialization format is unknown
| ServerBuilder& grpc::ServerBuilder::RegisterService | ( | const std::string & | host, |
| grpc::Service * | service | ||
| ) |
Register a service.
This call does not take ownership of the service. The service must exist for the lifetime of the Server instance returned by BuildAndStart(). Only matches requests with :authority host
| ServerBuilder& grpc::ServerBuilder::RegisterService | ( | grpc::Service * | service | ) |
Register a service.
This call does not take ownership of the service. The service must exist for the lifetime of the Server instance returned by BuildAndStart(). Matches requests with any :authority
|
inlineprotected |
Experimental, to be deprecated.
|
inlineprotected |
Experimental API, subject to change.
| ServerBuilder& grpc::ServerBuilder::SetCompressionAlgorithmSupportStatus | ( | grpc_compression_algorithm | algorithm, |
| bool | enabled | ||
| ) |
Set the support status for compression algorithms.
All algorithms are enabled by default.
Incoming calls compressed with an unsupported algorithm will fail with GRPC_STATUS_UNIMPLEMENTED.
| ServerBuilder& grpc::ServerBuilder::SetContextAllocator | ( | std::unique_ptr< grpc::ContextAllocator > | context_allocator | ) |
Set the allocator for creating and releasing callback server context.
Takes the owndership of the allocator.
| ServerBuilder& grpc::ServerBuilder::SetDefaultCompressionAlgorithm | ( | grpc_compression_algorithm | algorithm | ) |
The default compression algorithm to use for all channel calls in the absence of a call-specific level.
Note that it overrides any compression level set by SetDefaultCompressionLevel.
| ServerBuilder& grpc::ServerBuilder::SetDefaultCompressionLevel | ( | grpc_compression_level | level | ) |
The default compression level to use for all channel calls in the absence of a call-specific level.
| ServerBuilder& grpc::ServerBuilder::SetEventEngine | ( | std::shared_ptr< grpc_event_engine::experimental::EventEngine > | event_engine | ) |
|
inline |
|
inline |
Set max receive message size in bytes.
The default is GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH.
|
inline |
Set max send message size in bytes.
The default is GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH.
| ServerBuilder& grpc::ServerBuilder::SetOption | ( | std::unique_ptr< grpc::ServerBuilderOption > | option | ) |
| ServerBuilder& grpc::ServerBuilder::SetResourceQuota | ( | const grpc::ResourceQuota & | resource_quota | ) |
Set the attached buffer pool for this server.
| ServerBuilder& grpc::ServerBuilder::SetSyncServerOption | ( | SyncServerOption | option, |
| int | value | ||
| ) |
Only useful if this is a Synchronous server.
|
friend |
| grpc_compression_algorithm grpc::ServerBuilder::algorithm |
| bool grpc::ServerBuilder::is_set |
| grpc_compression_level grpc::ServerBuilder::level |
1.8.17