2024-02-05 06:24:48 -05:00
|
|
|
#pragma once
|
|
|
|
|
2024-03-10 05:55:40 -04:00
|
|
|
#include <base/assert.hpp>
|
2024-02-05 06:24:48 -05:00
|
|
|
#include <boost/asio/any_io_executor.hpp>
|
|
|
|
#include <boost/asio/as_tuple.hpp>
|
|
|
|
#include <boost/asio/awaitable.hpp>
|
|
|
|
#include <boost/asio/basic_waitable_timer.hpp>
|
2024-03-10 05:55:40 -04:00
|
|
|
#include <boost/asio/co_spawn.hpp>
|
|
|
|
#include <boost/asio/deferred.hpp>
|
|
|
|
#include <boost/asio/detached.hpp>
|
2024-02-05 06:24:48 -05:00
|
|
|
#include <boost/asio/generic/stream_protocol.hpp>
|
|
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
|
|
#include <boost/asio/local/stream_protocol.hpp>
|
|
|
|
#include <boost/asio/strand.hpp>
|
|
|
|
#include <boost/asio/use_awaitable.hpp>
|
|
|
|
#include <boost/beast/core/basic_stream.hpp>
|
|
|
|
#include <boost/beast/core/error.hpp>
|
|
|
|
|
|
|
|
namespace asio = boost::asio;
|
|
|
|
namespace beast = boost::beast;
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
|
|
|
|
// if we need strands this is here just in case :)
|
|
|
|
using BaseExecutorType = asio::any_io_executor;
|
|
|
|
using ExecutorType = BaseExecutorType;
|
|
|
|
|
|
|
|
/// Awaitable type (configured for the current executor)
|
|
|
|
template <class T>
|
|
|
|
using Awaitable = asio::awaitable<T, ExecutorType>;
|
|
|
|
|
|
|
|
template <typename Protocol>
|
|
|
|
using Acceptor = asio::basic_socket_acceptor<Protocol, ExecutorType>;
|
|
|
|
|
|
|
|
template <typename Protocol>
|
|
|
|
using Socket = asio::basic_stream_socket<Protocol, ExecutorType>;
|
|
|
|
|
|
|
|
using SteadyTimer = asio::basic_waitable_timer<std::chrono::steady_clock, asio::wait_traits<std::chrono::steady_clock>, ExecutorType>;
|
|
|
|
|
|
|
|
template <typename Protocol>
|
|
|
|
using BeastStream = beast::basic_stream<Protocol, ExecutorType>;
|
|
|
|
|
2024-03-10 05:55:40 -04:00
|
|
|
/// Exception boilerplate
|
|
|
|
inline auto DefCoroCompletion(std::string_view name) {
|
|
|
|
// N.B: name is expected to be a literal
|
|
|
|
return [name](auto ep) {
|
|
|
|
if(ep) {
|
|
|
|
try {
|
|
|
|
std::rethrow_exception(ep);
|
|
|
|
} catch(std::exception& e) {
|
|
|
|
BASE_CHECK(false, "Unhandled exception in task \"{}\": {}", name, e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-02-05 06:24:48 -05:00
|
|
|
} // namespace base
|