Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
grpc::Server Class Reference

#include <server.h>

Inheritance diagram for grpc::Server:
Inheritance graph
[legend]

Classes

class  AllocatingRequestMatcherBase
 
class  AllocatingRequestMatcherBatch
 
class  AllocatingRequestMatcherRegistered
 
class  CallbackRequest
 
class  experimental_type
 
class  GlobalCallbacks
 
class  RealRequestMatcher
 
struct  RegisteredMethod
 
struct  RequestedCall
 
class  RequestMatcherInterface
 
class  SyncRequest
 
class  SyncRequestThreadManager
 
class  UnimplementedAsyncRequest
 
class  UnimplementedAsyncResponse
 

Public Member Functions

def add_generic_rpc_handlers (self, generic_rpc_handlers)
 
def add_insecure_port (self, address)
 
def add_secure_port (self, address, server_credentials)
 
grpc_serverc_server ()
 
experimental_type experimental ()
 
HealthCheckServiceInterfaceGetHealthCheckService () const
 Returns the health check service. More...
 
std::shared_ptr< ChannelInProcessChannel (const ChannelArguments &args)
 Establish a channel for in-process communication. More...
 
def start (self)
 
def stop (self, grace)
 
void Wait () ABSL_LOCKS_EXCLUDED(mu_) override
 
def wait_for_termination (self, timeout=None)
 
 ~Server () ABSL_LOCKS_EXCLUDED(mu_) override
 
- Public Member Functions inherited from grpc::ServerInterface
void Shutdown ()
 
template<class T >
void Shutdown (const T &deadline)
 
 ~ServerInterface () override
 
- Public Member Functions inherited from grpc::internal::CallHook
virtual ~CallHook ()
 

Static Public Member Functions

static void SetGlobalCallbacks (GlobalCallbacks *callbacks)
 

Protected Member Functions

int AddListeningPort (const std::string &addr, ServerCredentials *creds) override
 
ContextAllocatorcontext_allocator ()
 
bool health_check_service_disabled () const
 NOTE: This method is not part of the public API for this class. More...
 
bool RegisterService (const std::string *addr, Service *service) override
 
grpc_serverserver () override
 
 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 >>())
 
void set_health_check_service (std::unique_ptr< HealthCheckServiceInterface > service)
 NOTE: This method is not part of the public API for this class. More...
 
void Start (ServerCompletionQueue **cqs, size_t num_cqs) override
 
- Protected Member Functions inherited from grpc::ServerInterface
void RequestAsyncCall (internal::RpcServiceMethod *method, grpc::ServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
 
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 RequestAsyncGenericCall (GenericServerContext *context, internal::ServerAsyncStreamingInterface *stream, grpc::CompletionQueue *call_cq, grpc::ServerCompletionQueue *notification_cq, void *tag)
 

Private Member Functions

bool shutdown_ ABSL_GUARDED_BY (mu_)
 
bool shutdown_notified_ ABSL_GUARDED_BY (mu_)
 
bool shutdown_done_ ABSL_GUARDED_BY (mu_)
 
CompletionQueueCallbackCQ () ABSL_LOCKS_EXCLUDED(mu_) override
 
ServerInitializerinitializer ()
 
std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface > > * interceptor_creators () override
 
int max_receive_message_size () const override
 
void PerformOpsOnCall (internal::CallOpSetInterface *ops, internal::Call *call) override
 
void Ref ()
 
void RegisterAsyncGenericService (AsyncGenericService *service) override
 
void RegisterCallbackGenericService (CallbackGenericService *service) override
 
void RegisterContextAllocator (std::unique_ptr< ContextAllocator > context_allocator)
 
void ShutdownInternal (gpr_timespec deadline) ABSL_LOCKS_EXCLUDED(mu_) override
 
void UnrefAndWaitLocked () ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
 
void UnrefWithPossibleNotify () ABSL_LOCKS_EXCLUDED(mu_)
 
- Private Member Functions inherited from grpc::GrpcLibraryCodegen
 GrpcLibraryCodegen (bool call_grpc_init=true)
 
virtual ~GrpcLibraryCodegen ()
 

Private Attributes

std::vector< std::shared_ptr< internal::ExternalConnectionAcceptorImpl > > acceptors_
 
std::atomic< CompletionQueue * > callback_cq_ {nullptr}
 
std::unique_ptr< ContextAllocatorcontext_allocator_
 
std::vector< CompletionQueue * > cq_list_
 
std::unique_ptr< internal::MethodHandlergeneric_handler_
 
std::shared_ptr< GlobalCallbacksglobal_callbacks_
 
bool has_async_generic_service_ = false
 
bool has_callback_generic_service_ = false
 
bool has_callback_methods_ = false
 
std::unique_ptr< HealthCheckServiceInterfacehealth_check_service_
 
bool health_check_service_disabled_
 
std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface > > interceptor_creators_
 
int max_receive_message_size_
 
internal::Mutex mu_
 
std::unique_ptr< internal::MethodHandlerresource_exhausted_handler_
 
grpc_serverserver_
 
std::unique_ptr< ServerInitializerserver_initializer_
 
std::vector< std::string > services_
 
internal::CondVar shutdown_cv_
 
internal::CondVar shutdown_done_cv_
 
std::atomic_int shutdown_refs_outstanding_ {1}
 
bool started_
 
std::vector< std::unique_ptr< SyncRequestThreadManager > > sync_req_mgrs_
 
std::shared_ptr< std::vector< std::unique_ptr< ServerCompletionQueue > > > sync_server_cqs_
 
std::unique_ptr< CallbackGenericServiceunimplemented_service_
 

Friends

class AsyncGenericService
 
class ServerBuilder
 
class ServerInitializer
 

Detailed Description

Represents a gRPC server.

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

Services RPCs.

Definition at line 59 of file include/grpcpp/server.h.

Constructor & Destructor Documentation

◆ ~Server()

grpc::Server::~Server ( )
override

Definition at line 952 of file server_cc.cc.

◆ 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 >>() 
)
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

◆ ABSL_GUARDED_BY() [1/3]

bool shutdown_ grpc::Server::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [2/3]

bool shutdown_notified_ grpc::Server::ABSL_GUARDED_BY ( mu_  )
private

◆ ABSL_GUARDED_BY() [3/3]

bool shutdown_done_ grpc::Server::ABSL_GUARDED_BY ( mu_  )
private

◆ add_generic_rpc_handlers()

def grpc.Server.add_generic_rpc_handlers (   self,
  generic_rpc_handlers 
)
Registers GenericRpcHandlers with this Server.

This method is only safe to call before the server is started.

Args:
  generic_rpc_handlers: An iterable of GenericRpcHandlers that will be
  used to service RPCs.

Reimplemented in grpc._server._Server.

Definition at line 1402 of file src/python/grpcio/grpc/__init__.py.

◆ add_insecure_port()

def grpc.Server.add_insecure_port (   self,
  address 
)
Opens an insecure port for accepting RPCs.

This method may only be called before starting the server.

Args:
  address: The address for which to open a port. If the port is 0,
    or not specified in the address, then gRPC runtime will choose a port.

Returns:
  An integer port on which server will accept RPC requests.

Reimplemented in grpc._server._Server.

Definition at line 1414 of file src/python/grpcio/grpc/__init__.py.

◆ add_secure_port()

def grpc.Server.add_secure_port (   self,
  address,
  server_credentials 
)
Opens a secure port for accepting RPCs.

This method may only be called before starting the server.

Args:
  address: The address for which to open a port.
    if the port is 0, or not specified in the address, then gRPC
    runtime will choose a port.
  server_credentials: A ServerCredentials object.

Returns:
  An integer port on which server will accept RPC requests.

Reimplemented in grpc._server._Server.

Definition at line 1429 of file src/python/grpcio/grpc/__init__.py.

◆ AddListeningPort()

int grpc::Server::AddListeningPort ( const std::string &  addr,
grpc::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.

Definition at line 1110 of file server_cc.cc.

◆ c_server()

grpc_server * grpc::Server::c_server ( )

Returns a raw pointer to the underlying grpc_server instance. EXPERIMENTAL: for internal/test use only

Definition at line 989 of file server_cc.cc.

◆ CallbackCQ()

grpc::CompletionQueue * grpc::Server::CallbackCQ ( )
overrideprivatevirtual

Reimplemented from grpc::ServerInterface.

Definition at line 1366 of file server_cc.cc.

◆ context_allocator()

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

Definition at line 206 of file include/grpcpp/server.h.

◆ 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.

Definition at line 131 of file include/grpcpp/server.h.

◆ GetHealthCheckService()

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

Returns the health check service.

Definition at line 102 of file include/grpcpp/server.h.

◆ 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.

Definition at line 209 of file include/grpcpp/server.h.

◆ initializer()

grpc::ServerInitializer * grpc::Server::initializer ( )
private

Definition at line 1362 of file server_cc.cc.

◆ InProcessChannel()

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

Establish a channel for in-process communication.

Definition at line 991 of file server_cc.cc.

◆ interceptor_creators()

std::vector<std::unique_ptr<experimental::ServerInterceptorFactoryInterface> >* grpc::Server::interceptor_creators ( )
inlineoverrideprivatevirtual

Reimplemented from grpc::ServerInterface.

Definition at line 215 of file include/grpcpp/server.h.

◆ max_receive_message_size()

int grpc::Server::max_receive_message_size ( ) const
inlineoverrideprivatevirtual

Implements grpc::ServerInterface.

Definition at line 256 of file include/grpcpp/server.h.

◆ PerformOpsOnCall()

void grpc::Server::PerformOpsOnCall ( internal::CallOpSetInterface ops,
internal::Call call 
)
overrideprivatevirtual

Implements grpc::ServerInterface.

Definition at line 1330 of file server_cc.cc.

◆ Ref()

void grpc::Server::Ref ( )
private

Definition at line 1118 of file server_cc.cc.

◆ RegisterAsyncGenericService()

void grpc::Server::RegisterAsyncGenericService ( grpc::AsyncGenericService service)
overrideprivatevirtual

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

Implements grpc::ServerInterface.

Definition at line 1085 of file server_cc.cc.

◆ RegisterCallbackGenericService()

void grpc::Server::RegisterCallbackGenericService ( grpc::CallbackGenericService service)
overrideprivatevirtual

Register a callback-based generic service. This call does not take ownership of theservice. The service must exist for the lifetime of the Server instance.

Reimplemented from grpc::ServerInterface.

Definition at line 1092 of file server_cc.cc.

◆ RegisterContextAllocator()

void grpc::Server::RegisterContextAllocator ( std::unique_ptr< ContextAllocator context_allocator)
inlineprivate

Definition at line 245 of file include/grpcpp/server.h.

◆ RegisterService()

bool grpc::Server::RegisterService ( const std::string *  addr,
grpc::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.

Definition at line 1026 of file server_cc.cc.

◆ server()

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

Implements grpc::ServerInterface.

Definition at line 197 of file include/grpcpp/server.h.

◆ 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.

Definition at line 201 of file include/grpcpp/server.h.

◆ SetGlobalCallbacks()

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.

Definition at line 983 of file server_cc.cc.

◆ ShutdownInternal()

void grpc::Server::ShutdownInternal ( gpr_timespec  deadline)
overrideprivatevirtual

The completion queue to use for server shutdown completion notification

Implements grpc::ServerInterface.

Definition at line 1245 of file server_cc.cc.

◆ start()

def grpc.Server.start (   self)
Starts this Server.

This method may only be called once. (i.e. it is not idempotent).

Reimplemented in grpc._server._Server.

Definition at line 1446 of file src/python/grpcio/grpc/__init__.py.

◆ Start()

void grpc::Server::Start ( grpc::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.

Definition at line 1145 of file server_cc.cc.

◆ stop()

def grpc.Server.stop (   self,
  grace 
)
Stops this Server.

This method immediately stop service of new RPCs in all cases.

If a grace period is specified, this method returns immediately
and all RPCs active at the end of the grace period are aborted.
If a grace period is not specified (by passing None for `grace`),
all existing RPCs are aborted immediately and this method
blocks until the last RPC handler terminates.

This method is idempotent and may be called at any time.
Passing a smaller grace value in a subsequent call will have
the effect of stopping the Server sooner (passing None will
have the effect of stopping the server immediately). Passing
a larger grace value in a subsequent call *will not* have the
effect of stopping the server later (i.e. the most restrictive
grace value is used).

Args:
  grace: A duration of time in seconds or None.

Returns:
  A threading.Event that will be set when this Server has completely
  stopped, i.e. when running RPCs either complete or are aborted and
  all handlers have terminated.

Reimplemented in grpc._server._Server.

Definition at line 1454 of file src/python/grpcio/grpc/__init__.py.

◆ UnrefAndWaitLocked()

void grpc::Server::UnrefAndWaitLocked ( )
private

Definition at line 1134 of file server_cc.cc.

◆ UnrefWithPossibleNotify()

void grpc::Server::UnrefWithPossibleNotify ( )
private

Definition at line 1122 of file server_cc.cc.

◆ 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.

Definition at line 1323 of file server_cc.cc.

◆ wait_for_termination()

def grpc.Server.wait_for_termination (   self,
  timeout = None 
)
Block current thread until the server stops.

This is an EXPERIMENTAL API.

The wait will not consume computational resources during blocking, and
it will block until one of the two following conditions are met:

1) The server is stopped or terminated;
2) A timeout occurs if timeout is not `None`.

The timeout argument works in the same way as `threading.Event.wait()`.
https://docs.python.org/3/library/threading.html#threading.Event.wait

Args:
  timeout: A floating point number specifying a timeout for the
    operation in seconds.

Returns:
  A bool indicates if the operation times out.

Reimplemented in grpc._server._Server.

Definition at line 1483 of file src/python/grpcio/grpc/__init__.py.

Friends And Related Function Documentation

◆ AsyncGenericService

friend class AsyncGenericService
friend

Definition at line 219 of file include/grpcpp/server.h.

◆ ServerBuilder

friend class ServerBuilder
friend

Definition at line 220 of file include/grpcpp/server.h.

◆ ServerInitializer

friend class ServerInitializer
friend

Definition at line 221 of file include/grpcpp/server.h.

Member Data Documentation

◆ acceptors_

std::vector<std::shared_ptr<internal::ExternalConnectionAcceptorImpl> > grpc::Server::acceptors_
private

Definition at line 272 of file include/grpcpp/server.h.

◆ callback_cq_

std::atomic<CompletionQueue*> grpc::Server::callback_cq_ {nullptr}
private

Definition at line 337 of file include/grpcpp/server.h.

◆ context_allocator_

std::unique_ptr<ContextAllocator> grpc::Server::context_allocator_
private

Definition at line 318 of file include/grpcpp/server.h.

◆ cq_list_

std::vector<CompletionQueue*> grpc::Server::cq_list_
private

Definition at line 342 of file include/grpcpp/server.h.

◆ generic_handler_

std::unique_ptr<internal::MethodHandler> grpc::Server::generic_handler_
private

Definition at line 331 of file include/grpcpp/server.h.

◆ global_callbacks_

std::shared_ptr<GlobalCallbacks> grpc::Server::global_callbacks_
private

Definition at line 306 of file include/grpcpp/server.h.

◆ has_async_generic_service_

bool grpc::Server::has_async_generic_service_ = false
private

Definition at line 309 of file include/grpcpp/server.h.

◆ has_callback_generic_service_

bool grpc::Server::has_callback_generic_service_ = false
private

Definition at line 310 of file include/grpcpp/server.h.

◆ has_callback_methods_

bool grpc::Server::has_callback_methods_ = false
private

Definition at line 311 of file include/grpcpp/server.h.

◆ health_check_service_

std::unique_ptr<HealthCheckServiceInterface> grpc::Server::health_check_service_
private

Definition at line 320 of file include/grpcpp/server.h.

◆ health_check_service_disabled_

bool grpc::Server::health_check_service_disabled_
private

Definition at line 321 of file include/grpcpp/server.h.

◆ interceptor_creators_

std::vector<std::unique_ptr<experimental::ServerInterceptorFactoryInterface> > grpc::Server::interceptor_creators_
private

Definition at line 280 of file include/grpcpp/server.h.

◆ max_receive_message_size_

int grpc::Server::max_receive_message_size_
private

Definition at line 282 of file include/grpcpp/server.h.

◆ mu_

internal::Mutex grpc::Server::mu_
private

Definition at line 295 of file include/grpcpp/server.h.

◆ resource_exhausted_handler_

std::unique_ptr<internal::MethodHandler> grpc::Server::resource_exhausted_handler_
private

Definition at line 328 of file include/grpcpp/server.h.

◆ server_

grpc_server* grpc::Server::server_
private

Definition at line 314 of file include/grpcpp/server.h.

◆ server_initializer_

std::unique_ptr<ServerInitializer> grpc::Server::server_initializer_
private

Definition at line 316 of file include/grpcpp/server.h.

◆ services_

std::vector<std::string> grpc::Server::services_
private

Definition at line 308 of file include/grpcpp/server.h.

◆ shutdown_cv_

internal::CondVar grpc::Server::shutdown_cv_
private

Definition at line 304 of file include/grpcpp/server.h.

◆ shutdown_done_cv_

internal::CondVar grpc::Server::shutdown_done_cv_
private

Definition at line 300 of file include/grpcpp/server.h.

◆ shutdown_refs_outstanding_

std::atomic_int grpc::Server::shutdown_refs_outstanding_ {1}
private

Definition at line 302 of file include/grpcpp/server.h.

◆ started_

bool grpc::Server::started_
private

Definition at line 296 of file include/grpcpp/server.h.

◆ sync_req_mgrs_

std::vector<std::unique_ptr<SyncRequestThreadManager> > grpc::Server::sync_req_mgrs_
private

List of ThreadManager instances (one for each cq in the sync_server_cqs)

Definition at line 292 of file include/grpcpp/server.h.

◆ sync_server_cqs_

std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue> > > grpc::Server::sync_server_cqs_
private

The following completion queues are ONLY used in case of Sync API i.e. if the server has any services with sync methods. The server uses these completion queues to poll for new RPCs

Definition at line 288 of file include/grpcpp/server.h.

◆ unimplemented_service_

std::unique_ptr<CallbackGenericService> grpc::Server::unimplemented_service_
private

Definition at line 325 of file include/grpcpp/server.h.


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


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:31