If you have a temporary_buffer it's not easy to reuse as you get a new one from the network APIs each time. Here's how to keep it alive.
future<>
my_connection::read_loop() {
while (auto buf = co_await _conn.read()) {
auto shard = determine_shard(buf);
co_await _my_service.invoke_on(shard, buf.get());
// buf is held by the coroutine and destroyed here
}
}
You may choose to run some processing in parallel, so details by vary.
If your buffer isn't a temporary_buffer, just keep it in a linked list or some other container.