SSX3LobbyServer/lib/impl/asio_config.hpp

58 lines
1.7 KiB
C++
Raw Normal View History

#pragma once
#include <base/assert.hpp>
#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>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/deferred.hpp>
#include <boost/asio/detached.hpp>
#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>;
/// 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());
}
}
};
}
} // namespace base