#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; template AdcGenericNetSessionASIO(const R& id, netservice_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_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; std::shared_ptr _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