GRPC C++  1.66.0
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
grpc::Server Class Reference

Represents a gRPC server. More...

#include <server.h>

Data Structures

class  experimental_type
 NOTE: class experimental_type is not part of the public API of this class. More...
 
class  GlobalCallbacks
 Global callbacks are a set of hooks that are called when server events occur. More...
 

Public Member Functions

 ~Server () ABSL_LOCKS_EXCLUDED(mu_) override
 
void Wait () ABSL_LOCKS_EXCLUDED(mu_) override
 Block until the server shuts down. More...
 
grpc_serverc_server ()
 Returns a raw pointer to the underlying grpc_server instance. More...
 
HealthCheckServiceInterfaceGetHealthCheckService () const
 Returns the health check service. More...
 
std::shared_ptr< ChannelInProcessChannel (const ChannelArguments &args)
 Establish a channel for in-process communication. More...
 
experimental_type experimental ()
 NOTE: The function experimental() is not stable public API. More...
 
- Public Member Functions inherited from grpc::ServerInterface
 ~ServerInterface () override
 
template<class T >
void Shutdown (const T &deadline)
 Shutdown does the following things: More...
 
void Shutdown ()
 Shutdown the server without a deadline and forced cancellation. More...
 
- Public Member Functions inherited from grpc::internal::CallHook
virtual ~CallHook ()
 

Static Public Member Functions

static void SetGlobalCallbacks (GlobalCallbacks *callbacks)
 Set the global callback object. More...
 

Protected Member Functions

bool RegisterService (const std::string *addr, Service *service) override
 Register a service. More...
 
int AddListeningPort (const std::string &addr, ServerCredentials *creds) override
 Try binding the server to the given addr endpoint (port, and optionally including IP address to bind to). More...
 
 Server (ChannelArguments *args, std::shared_ptr< std::vector< std::unique_ptr< ServerCompletionQueue >>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec, std::vector< std::shared_ptr< internal::ExternalConnectionAcceptorImpl >> acceptors, grpc_server_config_fetcher *server_config_fetcher=nullptr, grpc_resource_quota *server_rq=nullptr, std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >> interceptor_creators=std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >>(), experimental::ServerMetricRecorder *server_metric_recorder=nullptr)
 NOTE: This is NOT a public API. More...
 
void Start (ServerCompletionQueue **cqs, size_t num_cqs) override
 Start the server. More...
 
grpc_serverserver () override
 
void set_health_check_service (std::unique_ptr< HealthCheckServiceInterface > service)
 NOTE: This method is not part of the public API for this class. More...
 
ContextAllocatorcontext_allocator ()
 
bool health_check_service_disabled () const
 NOTE: This method is not part of the public API for this class. More...
 
- Protected Member Functions inherited from grpc::ServerInterface
template<class Message >
void RequestAsyncCall (internal::RpcServiceMethod *method, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag, Message *message)
 
void RequestAsyncCall (internal::RpcServiceMethod *method, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
 
void RequestAsyncGenericCall (GenericServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
 

Friends

class AsyncGenericService
 
class ServerBuilder
 
class ServerInitializer
 

Detailed Description

Represents a gRPC server.

Use a grpc::ServerBuilder to create, configure, and start Server instances.

Constructor & Destructor Documentation

◆ ~Server()

grpc::Server::~Server ( )
override

◆ Server()

grpc::Server::Server ( ChannelArguments args,
std::shared_ptr< std::vector< std::unique_ptr< ServerCompletionQueue >>>  sync_server_cqs,
int  min_pollers,
int  max_pollers,
int  sync_cq_timeout_msec,
std::vector< std::shared_ptr< internal::ExternalConnectionAcceptorImpl >>  acceptors,
grpc_server_config_fetcher server_config_fetcher = nullptr,
grpc_resource_quota server_rq = nullptr,
std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >>  interceptor_creators = std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >>(),
experimental::ServerMetricRecorder server_metric_recorder = nullptr 
)
protected

NOTE: This is NOT a public API.

The server constructors are supposed to be used by ServerBuilder class only. The constructor will be made 'private' very soon.

Server constructors. To be used by ServerBuilder only.

Parameters
argsThe channel args
sync_server_cqsThe completion queues to use if the server is a synchronous server (or a hybrid server). The server polls for new RPCs on these queues
min_pollersThe minimum number of polling threads per server completion queue (in param sync_server_cqs) to use for listening to incoming requests (used only in case of sync server)
max_pollersThe maximum number of polling threads per server completion queue (in param sync_server_cqs) to use for listening to incoming requests (used only in case of sync server)
sync_cq_timeout_msecThe timeout to use when calling AsyncNext() on server completion queues passed via sync_server_cqs param.

Member Function Documentation

◆ AddListeningPort()

int grpc::Server::AddListeningPort ( const std::string &  addr,
ServerCredentials creds 
)
overrideprotectedvirtual

Try binding the server to the given addr endpoint (port, and optionally including IP address to bind to).

It can be invoked multiple times. Should be used before starting the server.

Parameters
addrThe address to try to bind to the server (eg, localhost:1234, 192.168.1.1:31416, [::1]:27182, etc.).
credsThe credentials associated with the server.
Returns
bound port number on success, 0 on failure.
Warning
It is an error to call this method on an already started server.

Implements grpc::ServerInterface.

◆ c_server()

grpc_server* grpc::Server::c_server ( )

Returns a raw pointer to the underlying grpc_server instance.

EXPERIMENTAL: for internal/test use only

◆ context_allocator()

ContextAllocator* grpc::Server::context_allocator ( )
inlineprotected

◆ experimental()

experimental_type grpc::Server::experimental ( )
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.

◆ GetHealthCheckService()

HealthCheckServiceInterface* grpc::Server::GetHealthCheckService ( ) const
inline

Returns the health check service.

◆ health_check_service_disabled()

bool grpc::Server::health_check_service_disabled ( ) const
inlineprotected

NOTE: This method is not part of the public API for this class.

◆ InProcessChannel()

std::shared_ptr<Channel> grpc::Server::InProcessChannel ( const ChannelArguments args)

Establish a channel for in-process communication.

◆ RegisterService()

bool grpc::Server::RegisterService ( const std::string *  addr,
Service service 
)
overrideprotectedvirtual

Register a service.

This call does not take ownership of the service. The service must exist for the lifetime of the Server instance.

Implements grpc::ServerInterface.

◆ server()

grpc_server* grpc::Server::server ( )
inlineoverrideprotectedvirtual

Implements grpc::ServerInterface.

◆ set_health_check_service()

void grpc::Server::set_health_check_service ( std::unique_ptr< HealthCheckServiceInterface service)
inlineprotected

NOTE: This method is not part of the public API for this class.

◆ SetGlobalCallbacks()

static void grpc::Server::SetGlobalCallbacks ( GlobalCallbacks callbacks)
static

Set the global callback object.

Can only be called once per application. Does not take ownership of callbacks, and expects the pointed to object to be alive until all server objects in the process have been destroyed. The same GlobalCallbacks object will be used throughout the application and is shared among all Server objects.

◆ Start()

void grpc::Server::Start ( ServerCompletionQueue **  cqs,
size_t  num_cqs 
)
overrideprotectedvirtual

Start the server.

Parameters
cqsCompletion queues for handling asynchronous services. The caller is required to keep all completion queues live until the server is destroyed.
num_cqsHow many completion queues does cqs hold.

Implements grpc::ServerInterface.

◆ Wait()

void grpc::Server::Wait ( )
overridevirtual

Block until the server shuts down.

Warning
The server must be either shutting down or some other thread must call Shutdown for this function to ever return.

Implements grpc::ServerInterface.

Friends And Related Function Documentation

◆ AsyncGenericService

friend class AsyncGenericService
friend

◆ ServerBuilder

friend class ServerBuilder
friend

◆ ServerInitializer

friend class ServerInitializer
friend

The documentation for this class was generated from the following file: