| 202 | } |
| 203 | |
| 204 | auto bidirectional_streaming_rpc_handler(asio::thread_pool& thread_pool) |
| 205 | { |
| 206 | return [&](BidiStreamingRPC& rpc) -> asio::awaitable<void> |
| 207 | { |
| 208 | // Maximum number of requests that are buffered by the channel to enable backpressure. |
| 209 | static constexpr auto MAX_BUFFER_SIZE = 2; |
| 210 | |
| 211 | Channel channel{co_await asio::this_coro::executor, MAX_BUFFER_SIZE}; |
| 212 | |
| 213 | using namespace asio::experimental::awaitable_operators; |
| 214 | const auto ok = co_await (reader(rpc, channel) && writer(rpc, channel, thread_pool)); |
| 215 | |
| 216 | if (!ok) |
| 217 | { |
| 218 | // Client has disconnected or server is shutting down. |
| 219 | co_return; |
| 220 | } |
| 221 | |
| 222 | co_await rpc.finish(grpc::Status::OK); |
| 223 | }; |
| 224 | } |
| 225 | // --------------------------------------------------- |
| 226 | // |
| 227 | |