Fix GetDependencies for 2 dependencies

This commit is contained in:
sha512sum 2024-03-25 10:58:02 +00:00
parent 08c048c248
commit 3045e1a8e4
4 changed files with 15 additions and 22 deletions

View file

@ -59,12 +59,8 @@ private:
};
template <typename Socket>
inline auto ReadHeaders(Socket&& socket, auto&&...) const -> cserver::Task<server::http::HTTPResponse> {
boost::system::error_code ec;
std::string serverResponse;
co_await boost::asio::async_read_until(socket, boost::asio::dynamic_buffer(serverResponse), "\r\n\r\n", boost::asio::redirect_error(boost::asio::use_awaitable, ec));
if(ec) {
throw BoostErrorWrapper{ec};
};
co_await boost::asio::async_read_until(socket, boost::asio::dynamic_buffer(serverResponse), "\r\n\r\n", boost::asio::use_awaitable);
server::http::HTTPResponse response;
std::istringstream responseStream(std::move(serverResponse));
std::string httpVersion;
@ -80,11 +76,7 @@ private:
inline auto ReadBody(Socket&& socket, std::size_t length, auto&&...) const -> cserver::Task<std::string> {
std::string response;
response.reserve(length);
boost::system::error_code ec;
co_await boost::asio::async_read(socket, boost::asio::dynamic_buffer(response), boost::asio::transfer_at_least(length), boost::asio::redirect_error(boost::asio::use_awaitable, ec));
if(ec) {
throw BoostErrorWrapper{ec};
};
co_await boost::asio::async_read(socket, boost::asio::dynamic_buffer(response), boost::asio::transfer_at_least(length), boost::asio::use_awaitable);
co_return response;
};
template <typename Socket>
@ -96,7 +88,7 @@ private:
break;
};
if(ec) {
throw BoostErrorWrapper{ec};
throw boost::system::error_code{ec};
};
};
co_return response;

View file

@ -1,7 +1,6 @@
#pragma once
#include <cserver/server/http/http_response.hpp>
#include <cserver/engine/coroutine.hpp>
#include <cserver/utils/boost_error_wrapper.hpp>
#include <boost/asio/ssl.hpp>
namespace cserver::clients::http {
@ -19,9 +18,8 @@ public:
co_return false;
};
if(ec) {
throw BoostErrorWrapper{ec};
throw boost::system::error_code(ec);
};
this->body.resize(n);
co_return true;
};

View file

@ -208,7 +208,7 @@ public:
return utempl::Tuple{};
} else {
if constexpr(requires{GetDependencies<I + 1, names...>();}) {
return GetDependencies<I + 1, names..., typename decltype(Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{}))::Type>();
return GetDependencies<I + 1, names..., Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{})>();
} else {
return utempl::Tuple{names..., Magic(loopholes::Getter<DependencyInfoKey<Current, I>{}>{})};
};

View file

@ -33,15 +33,18 @@ struct Server {
return {};
});
};
template <utempl::ConstexprString name, typename T>
inline constexpr Server(utempl::Wrapper<name>, T& context) :
template <
utempl::ConstexprString name,
typename T,
std::size_t... Is>
inline constexpr Server(std::index_sequence<Is...>, utempl::Wrapper<name>, T& context) :
taskProcessor(context.template FindComponent<TPName>()),
handlers{
[&]<auto... Is>(std::index_sequence<Is...>) -> utempl::Tuple<impl::GetTypeFromComponentConfig<Ts>&...> {
return {context.template FindComponent<Get<Is>(kNames)>()...};
}(std::index_sequence_for<Ts...>())
},
handlers{context.template FindComponent<Get<Is>(kNames)>()...},
port(T::kConfig.template Get<name>().template Get<"port">()) {
};
inline constexpr Server(auto name, auto& context) :
Server(std::index_sequence_for<Ts...>{}, name, context) {
};
template<auto I, typename Socket>
auto ProcessHandler(Socket&& socket, http::HTTPRequest request) -> Task<void> {