From 2e6deffdd27463949a05175714f281ee4e5a5073 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Wed, 9 Oct 2024 18:59:54 +0300 Subject: [PATCH] ... --- net/asio/adc_netservice_asio.h | 82 +++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/net/asio/adc_netservice_asio.h b/net/asio/adc_netservice_asio.h index d12b646..f1b01c6 100644 --- a/net/asio/adc_netservice_asio.h +++ b/net/asio/adc_netservice_asio.h @@ -166,6 +166,9 @@ public: } } + + virtual ~acceptor_t() = default; + typedef AdcNetServiceASIOBase netservice_t; typedef std::shared_ptr sptr_netservice_t; @@ -244,7 +247,7 @@ public: return accept(endpoint, timeout); } - private: + protected: asio::io_context& _ioContext; AdcNetServiceASIOBase::endpoint_t _endpoint; AdcNetServiceASIOBase::socket_t _socket; @@ -670,6 +673,83 @@ protected: }; + +#ifdef USE_OPENSSL_WITH_ASIO + +template SESSION_PROTOT, + traits::adc_output_char_range RMSGT = + std::vector> // used only for inner storing of message byte sequence +class AdcNetServiceASIOTLS : public AdcNetServiceASIOBase +{ + typedef AdcNetServiceASIOBase base_t; + +public: + using typename base_t::socket_t; + + using base_t::connect; + using base_t::getShutdownType; + using base_t::receive; + using base_t::send; + using base_t::setShutdownType; + + + // reimplement acceptor class + class acceptor_t : public base_t::acceptor_t + { + public: + typedef AdcNetServiceASIOTLS netservice_t; + typedef std::shared_ptr sptr_netservice_t; + + using base_t::acceptor_t::acceptor_t; + + typedef std::function async_accept_callback_t; + + template TokenT, + traits::adc_time_duration_c DT = decltype(base_t::acceptor_t::DEFAULT_ACCEPT_TIMEOUT)> + auto asyncAccept(TokenT&& token, const DT& timeout = base_t::acceptor_t::DEFAULT_ACCEPT_TIMEOUT) + { + enum { starting, handshaking, finishing }; + + this->_socket = base_t::socket_t(this->_ioContext); + auto timer = getDeadlineTimer(this->_acceptor, timeout); + } + + + template TokenT, + traits::adc_time_duration_c DT = decltype(base_t::acceptor_t::DEFAULT_ACCEPT_TIMEOUT)> + auto asyncAccept(const base_t::endpoint_t& endpoint, + TokenT&& token, + const DT& timeout = base_t::acceptor_t::DEFAULT_ACCEPT_TIMEOUT) + { + this->_endpoint = endpoint; + return asyncAccept(std::forward(token), timeout); + } + }; + + + std::error_code close() + { + std::error_code ec; + + _tlsStream.shutdown(ec); // shutdown OpenSSL stream + if (!ec) { + _tlsStream.lowest_layer().shutdown(this->_shutdownType, ec); + if (!ec) { + _tlsStream.lowest_layer().close(ec); + } + } + + return ec; + } + +protected: + asio::ssl::stream _tlsStream; +}; + +#endif + + static_assert(adc::interfaces::adc_netservice_c>>, "");