AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::rest::GrpcServer Class Reference

#include <grpcServer.hpp>

Collaboration diagram for anch::rest::GrpcServer:

Public Member Functions

 GrpcServer ()
 GrpcServer (const GrpcServer &)=delete
virtual ~GrpcServer ()
GrpcServer & addService (const anch::rest::RpcService &service)
GrpcServer & listen (const std::string &address, std::shared_ptr< grpc::ServerCredentials > credentials=grpc::InsecureServerCredentials())
grpc::ServerBuilder & builder () noexcept
int start ()
void wait ()
void shutdown ()
GrpcServer & operator= (const GrpcServer &)=delete
int getPort () const noexcept

Detailed Description

gRPC server (HTTP/2) for RpcService : the same services can be installed in an anch-rest API ( installRpc , Connect and gRPC-Web) and in a gRPC server, for native gRPC clients (stubs generated by grpc_cpp_plugin ).

anch::rest::GrpcServer server; // anch-rest-grpc
server.addService(service).listen("0.0.0.0:50051");
server.start();
// ...
server.shutdown();

Methods are unary: the first request message is processed. RpcError is sent with its code and message ( UNIMPLEMENTED for unknown methods), request metadata are given in RpcContext , response metadata are sent as initial metadata. Services have to outlive the server.

Author
Vincent Lachenal
Since
0.2

Constructor & Destructor Documentation

◆ GrpcServer() [1/2]

anch::rest::GrpcServer::GrpcServer ( )

GrpcServer constructor

◆ GrpcServer() [2/2]

anch::rest::GrpcServer::GrpcServer ( const GrpcServer & )
delete

Prohibit GrpcServer copy

Here is the call graph for this function:

◆ ~GrpcServer()

virtual anch::rest::GrpcServer::~GrpcServer ( )
virtual

GrpcServer destructor: server is shut down

Member Function Documentation

◆ addService()

GrpcServer & anch::rest::GrpcServer::addService ( const anch::rest::RpcService & service)

Add RPC service (before start )

Parameters
servicethe service
Returns
this
Exceptions
std::invalid_argumentwhen a service with the same name already exists
Here is the call graph for this function:

◆ builder()

grpc::ServerBuilder & anch::rest::GrpcServer::builder ( )
noexcept

Get gRPC server builder, to set other options (before start )

Returns
the builder

◆ getPort()

int anch::rest::GrpcServer::getPort ( ) const
noexcept

Get the port of the first listening address

Returns
the port, 0 before start
Here is the call graph for this function:

◆ listen()

GrpcServer & anch::rest::GrpcServer::listen ( const std::string & address,
std::shared_ptr< grpc::ServerCredentials > credentials = grpc::InsecureServerCredentials() )

Add listening address (before start )

Parameters
addressthe address ( 0.0.0.0:50051 , 127.0.0.1:0 for a free port)
credentialsthe credentials (insecure by default)
Returns
this
Here is the call graph for this function:

◆ operator=()

GrpcServer & anch::rest::GrpcServer::operator= ( const GrpcServer & )
delete

Prohibit GrpcServer copy

Here is the call graph for this function:

◆ shutdown()

void anch::rest::GrpcServer::shutdown ( )

Shut down server: running calls are completed

Here is the call graph for this function:

◆ start()

int anch::rest::GrpcServer::start ( )

Start server

Returns
the port of the first listening address
Exceptions
std::runtime_errorwhen server can not be started
Here is the call graph for this function:

◆ wait()

void anch::rest::GrpcServer::wait ( )

Wait for server shutdown

Here is the call graph for this function:

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