class ServerBuilder
Defined at line 88 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
A builder class for the creation and startup of
instances.
Public Methods
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)
Defined at line 243 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
void ServerBuilder ()
void ~ServerBuilder ()
std::unique_ptr<grpc::Server> BuildAndStart ()
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
Will return a nullptr on errors.
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
instance returned
by
Matches requests with any :authority
ServerBuilder & AddListeningPort (const std::string & addr_uri, std::shared_ptr<grpc::ServerCredentials> creds, int * selected_port)
Enlists an endpoint
(port with an optional IP address) to
bind the
object to be created to.
It can be invoked multiple times.
Parameters
std::unique_ptr<grpc::ServerCompletionQueue> AddCompletionQueue (bool is_frequently_polled)
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)) { }
Parameters
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
instance
returned by
Only matches requests with :authority
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 & 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
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 & 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
ServerBuilder & SetMaxReceiveMessageSize (int max_receive_message_size)
Set max receive message size in bytes.
The default is GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH.
Defined at line 189 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
ServerBuilder & SetMaxSendMessageSize (int max_send_message_size)
Set max send message size in bytes.
The default is GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH.
Defined at line 196 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
ServerBuilder & SetMaxMessageSize (int max_message_size)
Defined at line 202 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
ServerBuilder & SetResourceQuota (const grpc::ResourceQuota & resource_quota)
Set the attached buffer pool for this server
ServerBuilder & SetOption (std::unique_ptr<grpc::ServerBuilderOption> option)
ServerBuilder & SetSyncServerOption (SyncServerOption option, int value)
Only useful if this is a Synchronous server.
void InternalAddPluginFactory (std::unique_ptr<grpc::ServerBuilderPlugin> (*)() CreatePlugin)
For internal use only: Register a ServerBuilderPlugin factory function.
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.
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 & 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
experimental_type experimental ()
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.
Defined at line 329 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
Protected Methods
ChannelArguments BuildChannelArgs ()
Experimental API, subject to change.
std::vector<Port> ports ()
Experimental, to be deprecated
Defined at line 350 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
std::vector<NamedService *> services ()
Experimental, to be deprecated
Defined at line 353 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
std::vector<grpc::ServerBuilderOption *> options ()
Experimental, to be deprecated
Defined at line 363 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
void set_fetcher (grpc_server_config_fetcher * server_config_fetcher)
Experimental API, subject to change.
Defined at line 373 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
Enumerations
enum SyncServerOption
| Name | Value |
|---|---|
| NUM_CQS | 0 |
| MIN_POLLERS | 1 |
| MAX_POLLERS | 2 |
| CQ_TIMEOUT_MSEC | 3 |
Options for synchronous servers.
Defined at line 230 of file ../../third_party/grpc-migrating/src/include/grpcpp/server_builder.h
Records
Friends
class ServerBuilderPluginTest