From 53c4fdb746e0b747e959f809792ff2ddeab12ad0 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sun, 14 Apr 2024 12:40:26 +0000 Subject: [PATCH] Add TcpEndpoint to network facade --- include/cserver/engine/network.hpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/cserver/engine/network.hpp b/include/cserver/engine/network.hpp index d597d01..92cc746 100644 --- a/include/cserver/engine/network.hpp +++ b/include/cserver/engine/network.hpp @@ -64,8 +64,36 @@ public: template friend inline constexpr auto AsyncReadUntil(TcpSocket& socket, Buffer buffer, Match match); }; +class TcpEntry; + +class TcpEndpoint { + boost::asio::ip::tcp::endpoint impl; + inline constexpr TcpEndpoint(boost::asio::ip::tcp::endpoint impl) : impl(std::move(impl)) {}; +public: + friend TcpEntry; +}; +class TcpEntry { + boost::asio::ip::tcp::resolver::results_type::value_type impl; +public: + inline constexpr TcpEntry() = default; + inline constexpr TcpEntry(const TcpEndpoint& ep, + std::string_view host, + std::string_view service) : impl(ep.impl, host, service) {}; + inline constexpr auto Endpoint() -> TcpEndpoint { + return {this->impl.endpoint()}; + }; + inline constexpr auto HostName() -> std::string { + return this->impl.host_name(); + }; + inline constexpr auto ServiceName() -> std::string { + return this->impl.service_name(); + }; + inline constexpr operator TcpEndpoint() { + return {this->impl}; + }; +}; class TcpResolver {