From 3e8a113c3a1dab3bb766faf45d374a5a0ce84d96 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 16 Jun 2024 00:11:20 +0300 Subject: [PATCH] ... --- CMakeLists.txt | 1 - net/adc_netmsg.h | 2 +- net/adc_netserver.h | 1 + net/adc_netservice_asio.h | 87 ++++++++++++++++++++++++++------------- 4 files changed, 60 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf3ce9b..021e3f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ if (ASIO_LIBRARY) net/adc_netservice_asio.h ) - add_compile_options(ASIO::ASIO) add_compile_definitions(PUBLIC USE_ASIO_LIBRARY) option(OPENSSL_LIBRARY "Use openssl library for related ASIO-based implementation" ON) diff --git a/net/adc_netmsg.h b/net/adc_netmsg.h index 1e661ae..1ce2b58 100644 --- a/net/adc_netmsg.h +++ b/net/adc_netmsg.h @@ -542,7 +542,7 @@ template concept adc_netmessage_c = requires { typename T::byte_storage_t; typename T::byte_view_t; - std::derived_from>; + requires std::derived_from>; }; // template // concept adc_netmessage_c = requires(const T t) { // const methods diff --git a/net/adc_netserver.h b/net/adc_netserver.h index 42c7ce5..5f78e5f 100644 --- a/net/adc_netserver.h +++ b/net/adc_netserver.h @@ -9,6 +9,7 @@ ABSTRACT DEVICE COMPONENTS LIBRARY #include #include #include + #if __has_include() // POSIX #define FORK_EXISTS 1 #include diff --git a/net/adc_netservice_asio.h b/net/adc_netservice_asio.h index 461d662..88eac7b 100644 --- a/net/adc_netservice_asio.h +++ b/net/adc_netservice_asio.h @@ -8,49 +8,82 @@ */ +#ifdef USE_ASIO_LIBRARY #include #include "adc_netservice.h" -#ifdef USE_ASIO_LIBRARY -// #include #include #include #include #include -// #include #include +#include +#include +#include #include -#include -#include #include #include #include #include +#ifdef USE_OPENSSL_WITH_ASIO + +#include +#include + +#endif + + #include #include "adc_netmsg.h" + +namespace adc::traits +{ + +// still only TCP, UDP and UNIX +template +concept adc_asio_inet_proto_c = requires { + requires std::derived_from || std::derived_from || + std::derived_from || + std::derived_from; +}; + +} // namespace adc::traits + namespace adc::impl { -template +template class AdcNetServiceASIO : public InetProtoT { public: using socket_t = typename InetProtoT::socket; using endpoint_t = typename InetProtoT::endpoint; + using high_level_socket_t = HighLevelSocketT; + +#ifdef USE_OPENSSL_WITH_ASIO + + static_assert(std::is_same_v + ? true + : std::is_same_v>, + "ONLY BASIC SOCKETS AND SSL::STREAM ARE SUPPORTED!!!"); + + static constexpr bool IsBasicSocket = std::is_same_v; +#else + static_assert(std::is_same_v, + "HighLevelSocketT AND InetProtoT::socket TYPES MUST BE THE SAME!!!"); +#endif + + using streambuff_iter_t = asio::buffers_iterator; - template - AdcNetServiceASIO(socket_t& sock, CtorArgTs&&... ctor_args) - : InetProtoT(std::forward(ctor_args)...), _socket(sock) - { - } + AdcNetServiceASIO(high_level_socket_t& sock) : _socket(sock) {} virtual ~AdcNetServiceASIO() = default; @@ -70,11 +103,10 @@ public: switch (state) { case starting: state = cancel_timer; - if constexpr (std::derived_from>) { - return _socket.lowest_layer().async_connect(endpoint, std::move(self)); - } else { + if constexpr (AdcNetServiceASIO::IsBasicSocket) { return _socket.async_connect(endpoint, std::move(self)); + } else { + return _socket.lowest_layer().async_connect(endpoint, std::move(self)); } break; case cancel_timer: @@ -235,7 +267,12 @@ public: { std::error_code ec; - if constexpr (std::derived_from>) { + if constexpr (AdcNetServiceASIO::IsBasicSocket) { + _socket.shutdown(stype, ec); + if (!ec) { + _socket.close(ec); + } + } else { _socket.shutdown(ec); // shutdown OpenSSL stream if (!ec) { _socket.lowest_layer().shutdown(stype, ec); @@ -243,18 +280,13 @@ public: _socket.lowest_layer().close(ec); } } - } else { - _socket.shutdown(stype, ec); - if (!ec) { - _socket.close(ec); - } } return ec; } protected: - socket_t& _socket; + high_level_socket_t& _socket; asio::streambuf _streamBuffer; @@ -278,14 +310,11 @@ protected: }; +typedef AdcNetService> AdcNetServiceAsioTcp; +typedef AdcNetService> AdcNetServiceAsioLocalSeqPack; +typedef AdcNetService> AdcNetServiceAsioLocalStream; + } // namespace adc::impl -namespace adc -{ - -typedef AdcNetService> AdcNetServiceAsioTcp; - -} // namespace adc - #endif