From 0f350e18091b38509db9e8eaa2416f8e3466a08e Mon Sep 17 00:00:00 2001 From: Dennis Hezel Date: Tue, 10 Dec 2024 17:15:31 +0100 Subject: [PATCH] doc: Shorten example README --- example/README.md | 68 ++----------------- example/async-generator-client.cpp | 6 -- example/async-generator-server.cpp | 4 +- example/file-transfer-client.cpp | 4 +- example/file-transfer-server.cpp | 4 +- example/generic-client.cpp | 8 +-- example/generic-server.cpp | 28 ++------ example/hello-world-server-arena.cpp | 4 +- example/hello-world-server.cpp | 4 +- example/main-io-context-server.cpp | 4 +- example/multi-threaded-alternative-client.cpp | 4 +- example/multi-threaded-alternative-server.cpp | 4 +- example/multi-threaded-client.cpp | 4 +- example/multi-threaded-server.cpp | 4 +- example/share-io-context-client.cpp | 4 +- example/share-io-context-server.cpp | 4 +- example/streaming-client.cpp | 20 +++--- example/streaming-server.cpp | 18 +++-- example/unifex-client.cpp | 12 ++-- example/unifex-server.cpp | 10 ++- 20 files changed, 63 insertions(+), 155 deletions(-) diff --git a/example/README.md b/example/README.md index 68423328..ddc0383f 100644 --- a/example/README.md +++ b/example/README.md @@ -4,14 +4,12 @@ Click on `snippet source` to jump to the code of an individual example. ## Asio client-side -### Streaming RPCs (ClientRPC API) +### Streaming RPCs ```cpp -// --------------------------------------------------- // A simple client-streaming request with coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -19,9 +17,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple server-streaming request with coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -29,23 +25,19 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A bidirectional-streaming request that simply sends the response from the server back to it. -// --------------------------------------------------- ``` -snippet source | anchor +snippet source | anchor ```cpp -// --------------------------------------------------- // 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 +snippet source | anchor ### Multi-threaded @@ -53,9 +45,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Multi-threaded client using multiple GrpcContexts -// --------------------------------------------------- ``` snippet source | anchor @@ -63,9 +53,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Multi-threaded client using single a GrpcContext -// --------------------------------------------------- ``` snippet source | anchor @@ -75,9 +63,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple generic unary with Boost.Coroutine. -// --------------------------------------------------- ``` snippet source | anchor @@ -85,10 +71,8 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A generic bidirectional-streaming request that simply sends the response from the server back to it using Asio's // stackless coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -98,9 +82,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Example showing how to run an io_context and a GrpcContext on the same thread for gRPC clients. -// --------------------------------------------------- ``` snippet source | anchor @@ -110,9 +92,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation. -// --------------------------------------------------- ``` snippet source | anchor @@ -124,9 +104,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Server-side hello world which handles exactly one request from the client before shutting down. -// --------------------------------------------------- ``` snippet source | anchor @@ -134,9 +112,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Server-side hello world with google::protobuf::Arena allocation -// --------------------------------------------------- ``` snippet source | anchor @@ -146,9 +122,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple client-streaming rpc handler using C++20 coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -156,9 +130,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple server-streaming rpc handler using C++20 coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -166,10 +138,8 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A server-streaming rpc handler that sends a message every 30s but completes immediately if the client cancels the // rpc. -// --------------------------------------------------- ``` snippet source | anchor @@ -177,10 +147,8 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // The following bidirectional-streaming example shows how to dispatch requests to a thread_pool and write responses // back to the client. -// --------------------------------------------------- ``` snippet source | anchor @@ -188,9 +156,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // (experimental) Server handling a server-streaming request using co_yield -// --------------------------------------------------- ``` snippet source | anchor @@ -200,9 +166,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Multi-threaded server handling unary requests using callback API and multiple GrpcContexts -// --------------------------------------------------- ``` snippet source | anchor @@ -210,9 +174,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Multi-threaded server handling unary requests using callback API and single GrpcContext -// --------------------------------------------------- ``` snippet source | anchor @@ -222,22 +184,18 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Handle a simple generic unary request with Boost.Coroutine. -// --------------------------------------------------- ``` -snippet source | anchor +snippet source | anchor ```cpp -// --------------------------------------------------- // A bidirectional-streaming example that shows how to dispatch requests to a thread_pool and write responses // back to the client. -// --------------------------------------------------- ``` -snippet source | anchor +snippet source | anchor ### Share io_context @@ -245,11 +203,9 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // 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 @@ -259,9 +215,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // 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 @@ -271,9 +225,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation. -// --------------------------------------------------- ``` snippet source | anchor @@ -285,9 +237,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple unary request with unifex coroutines. -// --------------------------------------------------- ``` snippet source | anchor @@ -295,9 +245,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A server-streaming request with unifex sender/receiver. -// --------------------------------------------------- ``` snippet source | anchor @@ -305,11 +253,9 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // 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 @@ -319,10 +265,8 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // 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 @@ -330,9 +274,7 @@ Click on `snippet source` to jump to the code of an individual example. ```cpp -// --------------------------------------------------- // A simple server-streaming request handler using coroutines. -// --------------------------------------------------- ``` snippet source | anchor diff --git a/example/async-generator-client.cpp b/example/async-generator-client.cpp index 03485fe2..7be0d2e3 100644 --- a/example/async-generator-client.cpp +++ b/example/async-generator-client.cpp @@ -27,12 +27,6 @@ namespace asio = boost::asio; using ExampleStub = example::v1::Example::Stub; using ExampleExtStub = example::v1::ExampleExt::Stub; -// begin-snippet: client-side-server-streaming-async-generator -// --------------------------------------------------- -// (experimental) Client handling a server-streaming request using co_yield -// --------------------------------------------------- -// end-snippet - asio::awaitable make_server_streaming_request(agrpc::GrpcContext& grpc_context, ExampleStub& stub) { using RPC = example::AwaitableClientRPC<&ExampleStub::PrepareAsyncServerStreaming>; diff --git a/example/async-generator-server.cpp b/example/async-generator-server.cpp index 72595048..7d0b73a2 100644 --- a/example/async-generator-server.cpp +++ b/example/async-generator-server.cpp @@ -29,9 +29,9 @@ using ExampleService = example::v1::Example::AsyncService; using ExampleExtService = example::v1::ExampleExt::AsyncService; // begin-snippet: server-side-server-streaming-async-generator -// --------------------------------------------------- + // (experimental) Server handling a server-streaming request using co_yield -// --------------------------------------------------- + // end-snippet template diff --git a/example/file-transfer-client.cpp b/example/file-transfer-client.cpp index 2c65aaf6..3594ff88 100644 --- a/example/file-transfer-client.cpp +++ b/example/file-transfer-client.cpp @@ -37,9 +37,9 @@ namespace asio = boost::asio; inline constexpr asio::use_awaitable_t USE_AWAITABLE{}; // begin-snippet: client-side-file-transfer -// --------------------------------------------------- + // Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation. -// --------------------------------------------------- + // end-snippet // The use of `asio::awaitable` is not required but `agrpc::GrpcExecutor` is slightly smaller diff --git a/example/file-transfer-server.cpp b/example/file-transfer-server.cpp index 55638a5e..8a3668ae 100644 --- a/example/file-transfer-server.cpp +++ b/example/file-transfer-server.cpp @@ -38,9 +38,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-file-transfer -// --------------------------------------------------- + // Example showing how to transfer files over a streaming RPC. Stack buffers are used to customize memory allocation. -// --------------------------------------------------- + // end-snippet using RPC = agrpc::ServerRPC<&example::v1::ExampleExt::AsyncService::RequestSendFile>; diff --git a/example/generic-client.cpp b/example/generic-client.cpp index 398d3ceb..94971176 100644 --- a/example/generic-client.cpp +++ b/example/generic-client.cpp @@ -47,9 +47,9 @@ bool deserialize(grpc::ByteBuffer& buffer, Message& message) } // begin-snippet: client-side-generic-unary-request -// --------------------------------------------------- + // A simple generic unary with Boost.Coroutine. -// --------------------------------------------------- + // end-snippet void make_generic_unary_request(agrpc::GrpcContext& grpc_context, grpc::GenericStub& stub, const asio::yield_context& yield) @@ -84,10 +84,10 @@ void make_generic_unary_request(agrpc::GrpcContext& grpc_context, grpc::GenericS // // begin-snippet: client-side-generic-bidirectional-request -// --------------------------------------------------- + // A generic bidirectional-streaming request that simply sends the response from the server back to it using Asio's // stackless coroutines. -// --------------------------------------------------- + // end-snippet struct BidirectionalStreamingRequest { diff --git a/example/generic-server.cpp b/example/generic-server.cpp index 56ac9dfd..b9203bca 100644 --- a/example/generic-server.cpp +++ b/example/generic-server.cpp @@ -35,12 +35,10 @@ namespace asio = boost::asio; -// Examples showing how to write generic servers for unary and bidirectional streaming RPCs. - // begin-snippet: server-side-generic-unary-request -// --------------------------------------------------- + // Handle a simple generic unary request with Boost.Coroutine. -// --------------------------------------------------- + // end-snippet void process_request(grpc::ByteBuffer& buffer) { @@ -74,10 +72,10 @@ void handle_generic_unary_request(agrpc::GenericServerRPC& rpc, const asio::yiel // // begin-snippet: server-side-generic-bidirectional-request -// --------------------------------------------------- + // A bidirectional-streaming example that shows how to dispatch requests to a thread_pool and write responses // back to the client. -// --------------------------------------------------- + // end-snippet using Channel = asio::experimental::channel; @@ -100,19 +98,6 @@ void reader(agrpc::GenericServerRPC& rpc, Channel& channel, const asio::basic_yi channel.close(); } -// When switching threads in a Boost.Coroutine calls to `std::this_thread::get_id` before and after the switch can -// produce unexpected results. Disabling optimizations seems to correct that. -auto -#if defined(__clang__) - __attribute__((optnone)) -#elif defined(__GNUC__) - __attribute__((optimize("O0"))) -#endif - get_thread_id() -{ - return std::this_thread::get_id(); -} - // The writer will pick up reads from the reader through the channel and switch // to the thread_pool to compute their response. template @@ -128,14 +113,9 @@ bool writer(agrpc::GenericServerRPC& rpc, Channel& channel, asio::thread_pool& t { break; } - auto main_thread = std::this_thread::get_id(); - // In this example we switch to the thread_pool to compute the response. asio::post(asio::bind_executor(thread_pool, yield)); - auto thread_pool_thread = get_thread_id(); - abort_if_not(main_thread != thread_pool_thread); - process_request(buffer); // rpc.write() is thread-safe so we can interact with it from the thread_pool. diff --git a/example/hello-world-server-arena.cpp b/example/hello-world-server-arena.cpp index 7c78aaed..05618e8e 100644 --- a/example/hello-world-server-arena.cpp +++ b/example/hello-world-server-arena.cpp @@ -23,9 +23,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-helloworld-arena -// --------------------------------------------------- + // Server-side hello world with google::protobuf::Arena allocation -// --------------------------------------------------- + // end-snippet class ArenaRequestMessageFactory diff --git a/example/hello-world-server.cpp b/example/hello-world-server.cpp index dab8118a..76c4c91e 100644 --- a/example/hello-world-server.cpp +++ b/example/hello-world-server.cpp @@ -23,9 +23,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-helloworld -// --------------------------------------------------- + // Server-side hello world which handles exactly one request from the client before shutting down. -// --------------------------------------------------- + // end-snippet int main(int argc, const char** argv) { diff --git a/example/main-io-context-server.cpp b/example/main-io-context-server.cpp index b82f207d..ca79ddd1 100644 --- a/example/main-io-context-server.cpp +++ b/example/main-io-context-server.cpp @@ -31,9 +31,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-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. -// --------------------------------------------------- + // end-snippet // A simple tcp request that will be handled by the io_context. diff --git a/example/multi-threaded-alternative-client.cpp b/example/multi-threaded-alternative-client.cpp index 5fe098f5..9781dc39 100644 --- a/example/multi-threaded-alternative-client.cpp +++ b/example/multi-threaded-alternative-client.cpp @@ -31,9 +31,9 @@ namespace asio = boost::asio; // begin-snippet: client-side-multi-threaded-alternative -// --------------------------------------------------- + // Multi-threaded client using single a GrpcContext -// --------------------------------------------------- + // end-snippet asio::awaitable make_request(agrpc::GrpcContext& grpc_context, helloworld::Greeter::Stub& stub) diff --git a/example/multi-threaded-alternative-server.cpp b/example/multi-threaded-alternative-server.cpp index c1f47bab..c1537823 100644 --- a/example/multi-threaded-alternative-server.cpp +++ b/example/multi-threaded-alternative-server.cpp @@ -28,9 +28,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-multi-threaded-alternative -// --------------------------------------------------- + // Multi-threaded server handling unary requests using callback API and single GrpcContext -// --------------------------------------------------- + // end-snippet void register_request_handler(agrpc::GrpcContext& grpc_context, helloworld::Greeter::AsyncService& service, diff --git a/example/multi-threaded-client.cpp b/example/multi-threaded-client.cpp index 92336cb3..b52bca30 100644 --- a/example/multi-threaded-client.cpp +++ b/example/multi-threaded-client.cpp @@ -31,9 +31,9 @@ namespace asio = boost::asio; // begin-snippet: client-side-multi-threaded -// --------------------------------------------------- + // Multi-threaded client using multiple GrpcContexts -// --------------------------------------------------- + // end-snippet // A simple round robin strategy for picking the next GrpcContext to use for an RPC. diff --git a/example/multi-threaded-server.cpp b/example/multi-threaded-server.cpp index 90e3b982..17192c24 100644 --- a/example/multi-threaded-server.cpp +++ b/example/multi-threaded-server.cpp @@ -30,9 +30,9 @@ namespace asio = boost::asio; // begin-snippet: server-side-multi-threaded -// --------------------------------------------------- + // Multi-threaded server handling unary requests using callback API and multiple GrpcContexts -// --------------------------------------------------- + // end-snippet void register_request_handler(agrpc::GrpcContext& grpc_context, helloworld::Greeter::AsyncService& service, diff --git a/example/share-io-context-client.cpp b/example/share-io-context-client.cpp index 3325bbd5..ba7998f5 100644 --- a/example/share-io-context-client.cpp +++ b/example/share-io-context-client.cpp @@ -32,9 +32,9 @@ namespace asio = boost::asio; // begin-snippet: client-side-share-io-context -// --------------------------------------------------- + // Example showing how to run an io_context and a GrpcContext on the same thread for gRPC clients. -// --------------------------------------------------- + // end-snippet // A simple tcp request that will be handled by the io_context diff --git a/example/share-io-context-server.cpp b/example/share-io-context-server.cpp index a5eae223..0b54bf18 100644 --- a/example/share-io-context-server.cpp +++ b/example/share-io-context-server.cpp @@ -32,11 +32,11 @@ namespace asio = boost::asio; // begin-snippet: server-side-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. -// --------------------------------------------------- + // end-snippet // A simple tcp request that will be handled by the io_context. diff --git a/example/streaming-client.cpp b/example/streaming-client.cpp index de6c0733..cc8db645 100644 --- a/example/streaming-client.cpp +++ b/example/streaming-client.cpp @@ -39,9 +39,9 @@ using ExampleExtStub = example::v1::ExampleExt::Stub; // Example showing some of the features of the ClientRPC API of asio-grpc with Boost.Asio. // begin-snippet: client-side-client-rpc-streaming -// --------------------------------------------------- + // A simple client-streaming request with coroutines. -// --------------------------------------------------- + // end-snippet asio::awaitable make_client_streaming_request(agrpc::GrpcContext& grpc_context, ExampleStub& stub) { @@ -73,9 +73,9 @@ asio::awaitable make_client_streaming_request(agrpc::GrpcContext& grpc_con // // begin-snippet: client-rpc-server-streaming -// --------------------------------------------------- + // A simple server-streaming request with coroutines. -// --------------------------------------------------- + // end-snippet asio::awaitable make_server_streaming_request(agrpc::GrpcContext& grpc_context, ExampleStub& stub) { @@ -103,9 +103,7 @@ asio::awaitable make_server_streaming_request(agrpc::GrpcContext& grpc_con // --------------------------------------------------- // -// --------------------------------------------------- // A server-streaming request that is cancelled. -// --------------------------------------------------- asio::awaitable make_server_streaming_notify_when_done_request(agrpc::GrpcContext& grpc_context, ExampleStub& stub) { @@ -133,9 +131,9 @@ asio::awaitable make_server_streaming_notify_when_done_request(agrpc::Grpc // // begin-snippet: client-rpc-bidirectional-streaming -// --------------------------------------------------- + // A bidirectional-streaming request that simply sends the response from the server back to it. -// --------------------------------------------------- + // end-snippet asio::awaitable make_bidirectional_streaming_request(agrpc::GrpcContext& grpc_context, ExampleStub& stub) { @@ -177,11 +175,11 @@ asio::awaitable make_bidirectional_streaming_request(agrpc::GrpcContext& g // // begin-snippet: client-side-run-with-deadline -// --------------------------------------------------- + // 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. -// --------------------------------------------------- + // end-snippet asio::awaitable make_and_cancel_unary_request(agrpc::GrpcContext& grpc_context, ExampleExtStub& stub) { @@ -215,9 +213,7 @@ asio::awaitable make_and_cancel_unary_request(agrpc::GrpcContext& grpc_con // --------------------------------------------------- // -// --------------------------------------------------- // The Shutdown endpoint is used by unit tests. -// --------------------------------------------------- asio::awaitable make_shutdown_request(agrpc::GrpcContext& grpc_context, ExampleExtStub& stub) { using RPC = example::AwaitableClientRPC<&ExampleExtStub::PrepareAsyncShutdown>; diff --git a/example/streaming-server.cpp b/example/streaming-server.cpp index b44f4da7..a7f90b3c 100644 --- a/example/streaming-server.cpp +++ b/example/streaming-server.cpp @@ -40,9 +40,9 @@ using ExampleExtService = example::v1::ExampleExt::AsyncService; // Example showing some of the features of using asio-grpc with Boost.Asio. // begin-snippet: server-side-client-streaming -// --------------------------------------------------- + // A simple client-streaming rpc handler using C++20 coroutines. -// --------------------------------------------------- + // end-snippet using ClientStreamingRPC = example::AwaitableServerRPC<&ExampleService::RequestClientStreaming>; @@ -74,9 +74,9 @@ asio::awaitable handle_client_streaming_request(ClientStreamingRPC& rpc) // // begin-snippet: server-side-server-streaming -// --------------------------------------------------- + // A simple server-streaming rpc handler using C++20 coroutines. -// --------------------------------------------------- + // end-snippet using ServerStreamingRPC = example::AwaitableServerRPC<&ExampleService::RequestServerStreaming>; @@ -94,10 +94,10 @@ asio::awaitable handle_server_streaming_request(ServerStreamingRPC& rpc, e // // begin-snippet: server-side-notify-when-done -// --------------------------------------------------- + // A server-streaming rpc handler that sends a message every 30s but completes immediately if the client cancels the // rpc. -// --------------------------------------------------- + // end-snippet using ServerStreamingNotifyWhenDoneRPC = example::AwaitableNotifyWhenDoneServerRPC<&ExampleService::RequestServerStreaming>; @@ -144,10 +144,10 @@ auto server_streaming_notify_when_done_request_handler(agrpc::GrpcContext& grpc_ // // begin-snippet: server-side-bidirectional-streaming -// --------------------------------------------------- + // The following bidirectional-streaming example shows how to dispatch requests to a thread_pool and write responses // back to the client. -// --------------------------------------------------- + // end-snippet using BidiStreamingRPC = example::AwaitableServerRPC<&ExampleService::RequestBidirectionalStreaming>; @@ -224,10 +224,8 @@ auto bidirectional_streaming_rpc_handler(asio::thread_pool& thread_pool) // --------------------------------------------------- // -// --------------------------------------------------- // The SlowUnary endpoint is used by the client to demonstrate per-RPC step cancellation. See streaming-client.cpp. // It also demonstrates how to use an awaitable with a different executor type. -// --------------------------------------------------- using SlowUnaryRPC = asio::use_awaitable_t::as_default_on_t>; diff --git a/example/unifex-client.cpp b/example/unifex-client.cpp index 2ebc5723..c9890589 100644 --- a/example/unifex-client.cpp +++ b/example/unifex-client.cpp @@ -35,9 +35,9 @@ // Example showing some of the features of using asio-grpc with libunifex. // begin-snippet: client-side-unifex-unary -// --------------------------------------------------- + // A simple unary request with unifex coroutines. -// --------------------------------------------------- + // end-snippet unifex::task make_unary_request(agrpc::GrpcContext& grpc_context, example::v1::Example::Stub& stub) { @@ -57,9 +57,9 @@ unifex::task make_unary_request(agrpc::GrpcContext& grpc_context, example: // // begin-snippet: client-side-unifex-server-streaming -// --------------------------------------------------- + // A server-streaming request with unifex sender/receiver. -// --------------------------------------------------- + // end-snippet using ServerStreamingClientRPC = agrpc::ClientRPC<&example::v1::Example::Stub::PrepareAsyncServerStreaming>; @@ -145,11 +145,11 @@ auto make_server_streaming_request(agrpc::GrpcContext& grpc_context, example::v1 // // begin-snippet: client-side-unifex-with-deadline -// --------------------------------------------------- + // 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. -// --------------------------------------------------- + // end-snippet auto with_deadline(agrpc::GrpcContext& grpc_context, std::chrono::system_clock::time_point deadline) { diff --git a/example/unifex-server.cpp b/example/unifex-server.cpp index 75e62d61..59b63ca2 100644 --- a/example/unifex-server.cpp +++ b/example/unifex-server.cpp @@ -40,10 +40,10 @@ using UnaryRPC = agrpc::ServerRPC<&ExampleService::RequestUnary>; using ServerStreamingRPC = agrpc::ServerRPC<&ExampleService::RequestServerStreaming>; // begin-snippet: server-side-unifex-unary -// --------------------------------------------------- + // Register a request handler to unary requests. A bit of boilerplate code regarding stop_source has been added to make // the example testable. -// --------------------------------------------------- + // end-snippet auto register_unary_request_handler(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service) { @@ -67,9 +67,9 @@ auto register_unary_request_handler(agrpc::GrpcContext& grpc_context, example::v // // begin-snippet: server-side-unifex-server-streaming -// --------------------------------------------------- + // A simple server-streaming request handler using coroutines. -// --------------------------------------------------- + // end-snippet auto handle_server_streaming_request(agrpc::GrpcContext& grpc_context, example::v1::Example::AsyncService& service) { @@ -93,9 +93,7 @@ auto handle_server_streaming_request(agrpc::GrpcContext& grpc_context, example:: // --------------------------------------------------- // -// --------------------------------------------------- // The SlowUnary endpoint is used by the client to demonstrate per-RPC step cancellation. See unifex-client.cpp. -// --------------------------------------------------- auto handle_slow_unary_request(agrpc::GrpcContext& grpc_context, example::v1::ExampleExt::AsyncService& service) { using RPC = agrpc::ServerRPC<&example::v1::ExampleExt::AsyncService::RequestSlowUnary>;