From ecca565f3f3430c4605bf734b175b10ee3a7ad9a Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 24 Nov 2024 00:00:22 +0300 Subject: [PATCH] ... --- CMakeLists.txt | 1 - net/adc_device_netclient.h | 7 +- net/asio/adc_netservice_asio.h | 19 +++- net/asio/adc_netsession_asio.h | 198 --------------------------------- 4 files changed, 21 insertions(+), 204 deletions(-) delete mode 100644 net/asio/adc_netsession_asio.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1644d69..adf41fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,6 @@ if (ASIO_LIBRARY) set(ADC_NETWORK_HEADERS ${ADC_NETWORK_HEADERS} net/asio/adc_netservice_asio.h - net/asio/adc_netsession_asio.h net/asio/adc_device_netserver_asio.h ) diff --git a/net/adc_device_netclient.h b/net/adc_device_netclient.h index 0efa20e..db24521 100644 --- a/net/adc_device_netclient.h +++ b/net/adc_device_netclient.h @@ -112,7 +112,6 @@ public: typedef std::vector message_t; - // Session(const netsession_ident_t& id, netservice_t srv, AdcDeviceNetServer* srv_ptr) Session(const netsession_ident_t& id, netservice_t srv, netsession_ctx_t ctx) : _ident(id), _netService(std::move(srv)), @@ -189,7 +188,7 @@ public: } else { try { ServerResponseType type; - auto attrs = checkserverCall(key, rmsg, type); + auto attrs = checkServerCall(key, rmsg, type); std::forward(std::get<0>(wrapper))(type, attrs); @@ -372,7 +371,7 @@ public: // helper methods template - R checkserverCall(std::string_view key, const auto& bytes, ServerResponseType& type) const + R checkServerCall(std::string_view key, const auto& bytes, ServerResponseType& type) const { AdcDeviceProtoMessage dev_msg(bytes); @@ -396,7 +395,7 @@ public: { auto rbytes = sendRecv(bytes); - return checkserverCall(key, rbytes, type); + return checkServerCall(key, rbytes, type); } diff --git a/net/asio/adc_netservice_asio.h b/net/asio/adc_netservice_asio.h index 388cd51..9140bf8 100644 --- a/net/asio/adc_netservice_asio.h +++ b/net/asio/adc_netservice_asio.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,10 @@ public: static constexpr bool isTLS = false; #endif + typedef TRANSPORT_PROTOT transport_proto_t; + typedef SESSION_PROTOT session_proto_t; + typedef RMSGT receive_msg_t; + // typedefs to satisfy 'adc_netservice_c' concept typedef std::string_view netservice_ident_t; @@ -793,6 +798,17 @@ public: return s; } + + template ST, + typename EptRangeT, + asio::completion_token_for CallbackT> + friend auto async_connect(ST& service, const EptRangeT& ept_range, CallbackT&& token) + requires std::ranges::range && + std::same_as, AdcBaseNetServiceASIO::endpoint_t> + { + return asio::async_connect(service._socket, ept_range, token); + }; + protected: static constexpr netservice_ident_t _ident = std::derived_from> @@ -931,7 +947,8 @@ protected: -/* */ +/* PARTIAL AdcBaseNetServiceASIO-CLASS SPECIALIZATIONS */ + template < adc_asio_transport_proto_c TRANSPORT_PROTOT, // transport-level proto (e.g. asio::ip::tcp) interfaces::adc_netsession_proto_c SESSION_PROTOT, // session-level proto (see ../adc_netproto.h) diff --git a/net/asio/adc_netsession_asio.h b/net/asio/adc_netsession_asio.h deleted file mode 100644 index 6e24b7d..0000000 --- a/net/asio/adc_netsession_asio.h +++ /dev/null @@ -1,198 +0,0 @@ -#pragma once - -#include "adc_netservice_asio.h" - -namespace adc::impl -{ - -template SESSION_PROTOT, - traits::adc_output_char_range RMSGT = std::vector> -class AdcGenericNetSessionASIO : public std::enable_shared_from_this< - AdcGenericNetSessionASIO> -{ -public: - typedef std::string netsession_ident_t; - - typedef SessionContextT netsession_ctx_t; - - typedef AdcNetServiceASIOBase netservice_t; - typedef std::shared_ptr netservice_sptr_t; - - template - AdcGenericNetSessionASIO(const R& id, netservice_sptr_t netservice, netsession_ctx_t&& context) - : _ident(), _netservice(std::move(netservice)), _sessionContext(std::forward(context)) - { - if constexpr (std::is_array_v) { - _ident = id; - } else { - _ident = std::string(id.begin(), id.end()); - } - } - - AdcGenericNetSessionASIO(netservice_sptr_t netservice, netsession_ctx_t&& context) - : AdcGenericNetSessionASIO( - std::derived_from ? "ASIO TCP SESSION" - : std::derived_from ? "ASIO UDP SESSION" - : std::derived_from ? "ASIO UNIX SEQPACKET SESSION" - : std::derived_from ? "ASIO UNIX STREAM SESSION" - : std::derived_from ? "ASIO UNIX DATAGRAM SESSION" - : "ASIO UNKNOWN", - std::move(netservice), - std::forward(context)) - { - } - - - virtual ~AdcGenericNetSessionASIO() - { - stop(); - } - - - netsession_ident_t ident() const - { - return _ident; - } - - - virtual void start() = 0; - - virtual void stop() - { - _netservice->close(); - } - - - template - AdcGenericNetSessionASIO& setDefaultTimeouts(const TimeoutT& send_timeout, const TimeoutT& recv_timeout) - { - _sendTimeout = send_timeout; - _recvTimeout = recv_timeout; - - return *this; - } - -protected: - netsession_ident_t _ident; - - netservice_sptr_t _netservice; - - netsession_ctx_t _sessionContext; - - std::chrono::duration _recvTimeout = - std::chrono::seconds::max(); - - std::chrono::duration _sendTimeout = - std::chrono::seconds(5); -}; - -/* -class AdcGenericNetSessionASIO -{ -public: - typedef std::string netsession_ident_t; - - template SESSION_PROTOT, - traits::adc_output_char_range RMSGT = std::vector, - traits::adc_is_callable RECV_MSG_TOKENT> - AdcGenericNetSessionASIO(const R& id, - std::shared_ptr> netservice, - RECV_MSG_TOKENT&& recv_msg_token) - : _ident(id.begin(), id.end()) - { - // check receive message completion token signature and deduce message type - if constexpr (!adc_asio_special_comp_token_c) { - static_assert(traits::adc_func_traits::arity == 2, "INVALID COMPLETION TOKEN SIGNATURE!"); - static_assert( - std::is_same_v>, std::error_code>, - "INVALID COMPLETION TOKEN SIGNATURE!"); - static_assert(traits::adc_output_char_range< - std::tuple_element_t<1, typename traits::adc_func_traits::args_t>>, - "INVALID COMPLETION TOKEN SIGNATURE!"); - } - - using msg_t = std::conditional_t< - adc_asio_special_comp_token_c, RMSGT, - std::remove_cvref_t::args_t>>>; - - - _startFunc = [netservice, wrapper = traits::adc_pf_wrapper(std::forward(recv_msg_token)), - this]() { - // - netservice->asyncReceive(std::get<0>(wrapper), _recvTimeout); - }; - - _stopFunc = [netservice]() { - // stop - netservice->close(); - }; - } - - template SESSION_PROTOT, - traits::adc_output_char_range RMSGT = std::vector, - traits::adc_is_callable RECV_MSG_TOKENT> - AdcGenericNetSessionASIO(std::shared_ptr> netservice, - RECV_MSG_TOKENT&& recv_msg_token) - : AdcGenericNetSessionASIO(std::derived_from ? "TCP SESSION" - : std::derived_from ? "UDP SESSION" - : std::derived_from - ? "UNIX SEQPACKET SESSION" - : std::derived_from ? "UNIX STREAM -SESSION" : "UNKNOWN", std::move(netservice), std::forward(recv_msg_token)) - { - } - - - virtual ~AdcGenericNetSessionASIO() - { - stop(); - } - - - netsession_ident_t ident() const - { - return _ident; - } - - - void start() - { - _startFunc(); - } - - void stop() - { - _stopFunc(); - } - - - template - AdcGenericNetSessionASIO& setDefaultTimeouts(const TimeoutT& send_timeout, const TimeoutT& recv_timeout) - { - _sendTimeout = send_timeout; - _recvTimeout = recv_timeout; - - return *this; - } - -protected: - netsession_ident_t _ident; - - std::function _startFunc; - std::function _stopFunc; - - std::chrono::duration _recvTimeout = - std::chrono::seconds::max(); - - std::chrono::duration _sendTimeout = - std::chrono::seconds(5); -}; - -*/ - -} // namespace adc::impl