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

View file

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

View file

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

View file

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