Skip to content

Latest commit

 

History

History
280 lines (233 loc) · 12.9 KB

README.md

File metadata and controls

280 lines (233 loc) · 12.9 KB

Examples

Click on snippet source to jump to the code of an individual example.

Asio client-side

Streaming RPCs

// A simple client-streaming request with coroutines.

snippet source | anchor

// A simple server-streaming request with coroutines.

snippet source | anchor

// A bidirectional-streaming request that simply sends the response from the server back to it.

snippet source | anchor

// A unary request with a per-RPC step timeout. Using a unary RPC for demonstration purposes, the same mechanism can be
// applied to streaming RPCs, where it is arguably more useful.
// For unary RPCs, `grpc::ClientContext::set_deadline` should be preferred.

snippet source | anchor

Multi-threaded

// Multi-threaded client using multiple GrpcContexts

snippet source | anchor

// Multi-threaded client using single a GrpcContext

snippet source | anchor

Generic

// A simple generic unary with Boost.Coroutine.

snippet source | anchor

// A generic bidirectional-streaming request that simply sends the response from the server back to it using Asio's
// stackless coroutines.

snippet source | anchor

Share io_context

// Example showing how to run an io_context and a GrpcContext on the same thread for gRPC clients.

snippet source | anchor

io_uring file transfer

// Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation.

snippet source | anchor

Asio server-side

Helloworld

// Server-side hello world which handles exactly one request from the client before shutting down.

snippet source | anchor

// Server-side hello world with google::protobuf::Arena allocation

snippet source | anchor

Streaming RPCs

// A simple client-streaming rpc handler using C++20 coroutines.

snippet source | anchor

// A simple server-streaming rpc handler using C++20 coroutines.

snippet source | anchor

// A server-streaming rpc handler that sends a message every 30s but completes immediately if the client cancels the
// rpc.

snippet source | anchor

// The following bidirectional-streaming example shows how to dispatch requests to a thread_pool and write responses
// back to the client.

snippet source | anchor

// (experimental) Server handling a server-streaming request using co_yield

snippet source | anchor

Multi-threaded

// Multi-threaded server handling unary requests using callback API and multiple GrpcContexts

snippet source | anchor

// Multi-threaded server handling unary requests using callback API and single GrpcContext

snippet source | anchor

Generic

// Handle a simple generic unary request with Boost.Coroutine.

snippet source | anchor

// A bidirectional-streaming example that shows how to dispatch requests to a thread_pool and write responses
// back to the client.

snippet source | anchor

Share io_context

// Example showing how to run an io_context and a GrpcContext on the same thread for gRPC servers.
// This can i.e. be useful when writing an HTTP server that occasionally reaches out to a gRPC server. In that case
// creating a separate thread for the GrpcContext might be undesirable due to added synchronization complexity.

snippet source | anchor

Main io_context

// Example showing how to use an io_context as the main context and a GrpcContext on a separate thread for gRPC servers.

snippet source | anchor

io_uring file transfer

// Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation.

snippet source | anchor

Libunifex

Client-side

// A simple unary request with unifex coroutines.

snippet source | anchor

// A server-streaming request with unifex sender/receiver.

snippet source | anchor

// A unifex, unary request with a per-RPC step timeout. Using a unary RPC for demonstration purposes, the same mechanism
// can be applied to streaming RPCs, where it is arguably more useful. For unary RPCs,
// `grpc::ClientContext::set_deadline` is the preferred way of specifying a timeout.

snippet source | anchor

Server-side

// Register a request handler to unary requests. A bit of boilerplate code regarding stop_source has been added to make
// the example testable.

snippet source | anchor

// A simple server-streaming request handler using coroutines.

snippet source | anchor