This commit is contained in:
Timur A. Fatkhullin
2024-11-09 03:15:59 +03:00
parent 8d6e1bb59c
commit afd1a917b4
5 changed files with 82 additions and 163 deletions

View File

@@ -50,19 +50,25 @@ public:
if (endpoint.isTCP()) {
asio::ip::tcp::endpoint ept(asio::ip::make_address(endpoint.host()), endpoint.port());
using srv_t = AdcNetServiceASIO<asio::ip::tcp, SessProtoT>;
base_t::template start<Session<srv_t>>("TCP", this, _ioContext, ept);
// base_t::template start<Session<srv_t>>("TCP", this, _ioContext, ept);
base_t::template start<Session<srv_t>>("TCP", {this, _sessionRecvTimeout, _sessionSendTimeout}, _ioContext,
ept);
#ifdef USE_OPENSSL_WITH_ASIO
} else if (endpoint.isTLS()) {
asio::ip::tcp::endpoint ept(asio::ip::make_address(endpoint.host()), endpoint.port());
using srv_t = AdcNetServiceASIOTLS<asio::ip::tcp, SessProtoT>;
base_t::template start<Session<srv_t>>("TLS", this, _ioContext, ept, std::move(tls_context),
tls_verify_mode);
// base_t::template start<Session<srv_t>>("TLS", this, _ioContext, ept, std::move(tls_context),
// tls_verify_mode);
base_t::template start<Session<srv_t>>("TLS", {this, _sessionRecvTimeout, _sessionSendTimeout}, _ioContext,
ept, std::move(tls_context), tls_verify_mode);
#endif
} else if (endpoint.isLocal()) {
if (endpoint.isLocalStream()) {
asio::local::stream_protocol::endpoint ept(endpoint.template path<std::string>());
using srv_t = AdcNetServiceASIO<asio::local::stream_protocol, SessProtoT>;
base_t::template start<Session<srv_t>>("LOCAL STREAM", this, _ioContext, ept);
// base_t::template start<Session<srv_t>>("LOCAL STREAM", this, _ioContext, ept);
base_t::template start<Session<srv_t>>("LOCAL STREAM", {this, _sessionRecvTimeout, _sessionSendTimeout},
_ioContext, ept);
// } else if (endpoint.isLocalDatagram()) {
// asio::local::datagram_protocol::endpoint ept(endpoint.template path<std::string>());
// using srv_t = AdcNetServiceASIO<asio::local::datagram_protocol, SessProtoT>;
@@ -70,7 +76,9 @@ public:
} else if (endpoint.isLocalSeqpacket()) {
asio::local::seq_packet_protocol::endpoint ept(endpoint.template path<std::string>());
using srv_t = AdcNetServiceASIO<asio::local::seq_packet_protocol, SessProtoT>;
base_t::template start<Session<srv_t>>("LOCAL SEQPACK", this, _ioContext, ept);
// base_t::template start<Session<srv_t>>("LOCAL SEQPACK", this, _ioContext, ept);
base_t::template start<Session<srv_t>>(
"LOCAL SEQPACK", {this, _sessionRecvTimeout, _sessionSendTimeout}, _ioContext, ept);
}
} else {
throw std::system_error(std::make_error_code(std::errc::protocol_not_supported));
@@ -104,11 +112,24 @@ public:
});
}
template <traits::adc_time_duration_c RT, traits::adc_time_duration_c ST>
requires(std::convertible_to<RT, std::chrono::milliseconds> &&
std::convertible_to<ST, std::chrono::milliseconds>)
void setSessionTimeouts(const RT& recv_timeout, const ST& send_timeout)
{
_sessionRecvTimeout = recv_timeout;
_sessionSendTimeout = send_timeout;
}
protected:
asio::io_context& _ioContext;
asio::signal_set _stopSignal, _restartSignal;
std::chrono::milliseconds _sessionRecvTimeout = std::chrono::hours(12);
std::chrono::milliseconds _sessionSendTimeout = std::chrono::seconds(5);
// demonizing ASIO-related methods
virtual void daemonizePrepare()
{

View File

@@ -757,6 +757,15 @@ public:
return _shutdownType;
}
template <typename OutputItT, typename FormatT = std::string_view>
static void formatError(std::error_code err,
OutputItT out_iter,
FormatT fmt = "{} (Err category: {}) (Err msg: {})")
{
std::format_to(out_iter, fmt, err.value(), err.category().name(), err.message());
}
protected:
static constexpr netservice_ident_t _ident =
std::derived_from<socket_t, asio::basic_stream_socket<typename socket_t::protocol_type>>