MCPcopy Create free account
hub / github.com/Tradias/asio-grpc / writer

Function writer

example/generic-server.cpp:102–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100// to the thread_pool to compute their response.
101template <class Handler>
102bool writer(agrpc::GenericServerRPC& rpc, Channel& channel, asio::thread_pool& thread_pool,
103 const asio::basic_yield_context<Handler>& yield)
104{
105 bool ok{true};
106 while (ok)
107 {
108 boost::system::error_code ec;
109 auto buffer = channel.async_receive(yield[ec]);
110 if (ec)
111 {
112 break;
113 }
114 // In this example we switch to the thread_pool to compute the response.
115 asio::post(asio::bind_executor(thread_pool, yield));
116
117 process_request(buffer);
118
119 // rpc.write() is thread-safe so we can interact with it from the thread_pool.
120 ok = rpc.write(buffer, yield);
121 // Now we are back on the main thread.
122 }
123 std::cout << "Generic: Server writes completed with: " << std::boolalpha << ok << std::endl;
124 return ok;
125}
126
127void handle_generic_bidistream_request(agrpc::GrpcContext& grpc_context, agrpc::GenericServerRPC& rpc,
128 asio::thread_pool& thread_pool, const asio::yield_context& yield)

Callers 1

Calls 3

postFunction · 0.85
process_requestFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected