...
This commit is contained in:
parent
5b50d714f7
commit
2e6deffdd2
@ -166,6 +166,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virtual ~acceptor_t() = default;
|
||||||
|
|
||||||
typedef AdcNetServiceASIOBase netservice_t;
|
typedef AdcNetServiceASIOBase netservice_t;
|
||||||
typedef std::shared_ptr<netservice_t> sptr_netservice_t;
|
typedef std::shared_ptr<netservice_t> sptr_netservice_t;
|
||||||
|
|
||||||
@ -244,7 +247,7 @@ public:
|
|||||||
return accept(endpoint, timeout);
|
return accept(endpoint, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
asio::io_context& _ioContext;
|
asio::io_context& _ioContext;
|
||||||
AdcNetServiceASIOBase::endpoint_t _endpoint;
|
AdcNetServiceASIOBase::endpoint_t _endpoint;
|
||||||
AdcNetServiceASIOBase::socket_t _socket;
|
AdcNetServiceASIOBase::socket_t _socket;
|
||||||
@ -670,6 +673,83 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef USE_OPENSSL_WITH_ASIO
|
||||||
|
|
||||||
|
template <adc_asio_stream_transport_proto_c TRANSPORT_PROTOT,
|
||||||
|
interfaces::adc_netsession_proto_c<std::string_view> SESSION_PROTOT,
|
||||||
|
traits::adc_output_char_range RMSGT =
|
||||||
|
std::vector<char>> // used only for inner storing of message byte sequence
|
||||||
|
class AdcNetServiceASIOTLS : public AdcNetServiceASIOBase<TRANSPORT_PROTOT, SESSION_PROTOT, RMSGT>
|
||||||
|
{
|
||||||
|
typedef AdcNetServiceASIOBase<TRANSPORT_PROTOT, SESSION_PROTOT, RMSGT> 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<netservice_t> sptr_netservice_t;
|
||||||
|
|
||||||
|
using base_t::acceptor_t::acceptor_t;
|
||||||
|
|
||||||
|
typedef std::function<void(std::error_code, sptr_netservice_t)> async_accept_callback_t;
|
||||||
|
|
||||||
|
template <asio::completion_token_for<void(std::error_code, sptr_netservice_t)> 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 <asio::completion_token_for<void(std::error_code, sptr_netservice_t)> 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<TokenT>(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<socket_t> _tlsStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static_assert(adc::interfaces::adc_netservice_c<AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>>,
|
static_assert(adc::interfaces::adc_netservice_c<AdcNetServiceASIOBase<asio::ip::tcp, adc::AdcStopSeqSessionProto<>>>,
|
||||||
"");
|
"");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user