Fix bug in GetStartStreamIndex

This commit is contained in:
sha512sum 2024-10-04 17:23:31 +00:00
parent d9489ea5d3
commit 2e92c59f50

View file

@ -314,9 +314,6 @@ struct ClientCreateVisitor {
}; };
auto GetStartStreamIndex(auto& socket, boost::asio::streambuf& streambuf) -> boost::asio::awaitable<std::size_t> { auto GetStartStreamIndex(auto& socket, boost::asio::streambuf& streambuf) -> boost::asio::awaitable<std::size_t> {
auto buf = streambuf.prepare(4096); // NOLINT
std::size_t n = co_await socket.async_read_some(buf, boost::asio::use_awaitable);
streambuf.commit(n);
auto splited = Splitter{GetEnumerated(streambuf)}; auto splited = Splitter{GetEnumerated(streambuf)};
using It = decltype(splited.begin()); using It = decltype(splited.begin());
// clang-format off // clang-format off
@ -327,9 +324,14 @@ struct ClientCreateVisitor {
.transform([](auto value) -> boost::asio::awaitable<std::size_t> { .transform([](auto value) -> boost::asio::awaitable<std::size_t> {
auto [n, _] = *value; auto [n, _] = *value;
co_return n; co_return n;
}) }) // NOLINTNEXTLINE
.or_else([&] -> std::optional<boost::asio::awaitable<std::size_t>> { .or_else([&] { // NOLINTNEXTLINE
return this->GetStartStreamIndex(socket, streambuf); return std::optional{[](auto self, auto& socket, auto& streambuf) -> boost::asio::awaitable<std::size_t> {
auto buf = streambuf.prepare(4096); // NOLINT
std::size_t n = co_await socket.async_read_some(buf, boost::asio::use_awaitable);
streambuf.commit(n);
co_return co_await self->GetStartStreamIndex(socket, streambuf);
}(this, socket, streambuf)};
}) })
.value(); .value();
// clang-format on // clang-format on