AdcGenericNetServer, AdcDeviceNetServer, AdcDeviceNetServer::Session and
AdcDeviceNetServerASIO classes now have template parameter 'IdentT' (type of identificator)
This commit is contained in:
@@ -14,12 +14,20 @@
|
||||
namespace adc::impl
|
||||
{
|
||||
|
||||
class AdcDeviceNetServerASIO : public AdcDeviceNetServer
|
||||
template <typename IdentT = std::string>
|
||||
class AdcDeviceNetServerASIO : public AdcDeviceNetServer<IdentT>
|
||||
{
|
||||
typedef AdcDeviceNetServer<IdentT> base_t;
|
||||
|
||||
public:
|
||||
template <traits::adc_input_char_range R>
|
||||
AdcDeviceNetServerASIO(const R& id, asio::io_context& io_context)
|
||||
: AdcDeviceNetServer(id), _ioContext(io_context), _stopSignal(io_context), _restartSignal(io_context)
|
||||
using typename base_t::server_ident_t;
|
||||
typedef std::string session_ident_t;
|
||||
|
||||
template <typename ServiceT>
|
||||
using Session = typename base_t::template Session<ServiceT, session_ident_t>;
|
||||
|
||||
AdcDeviceNetServerASIO(const server_ident_t& id, asio::io_context& io_context)
|
||||
: base_t(id), _ioContext(io_context), _stopSignal(io_context), _restartSignal(io_context)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -39,37 +47,30 @@ public:
|
||||
|
||||
|
||||
// may throw here!
|
||||
#ifdef USE_OPENSSL_WITH_ASIO
|
||||
if (endpoint.isTCP() || endpoint.isTLS()) {
|
||||
asio::ip::tcp::endpoint ept(asio::ip::make_address(endpoint.host()), endpoint.port());
|
||||
if (endpoint.isTCP()) {
|
||||
using srv_t = AdcNetServiceASIO<asio::ip::tcp, SessProtoT>;
|
||||
AdcGenericNetServer::start<Session<srv_t>>("TCP", this, _ioContext, ept);
|
||||
|
||||
} else {
|
||||
using srv_t = AdcNetServiceASIOTLS<asio::ip::tcp, SessProtoT>;
|
||||
AdcGenericNetServer::start<Session<srv_t>>("TLS", this, _ioContext, ept, std::move(tls_context),
|
||||
tls_verify_mode);
|
||||
}
|
||||
#else
|
||||
if (endpoint.isTCP()) {
|
||||
asio::ip::tcp::endpoint ept(asio::ip::make_address(endpoint.host()), endpoint.port());
|
||||
using srv_t = AdcNetServiceASIO<asio::ip::tcp, AdcStopSeqSessionProto<>>;
|
||||
AdcDeviceNetServer::start<Session<srv_t>>("TCP", this, _ioContext, ept);
|
||||
using srv_t = AdcNetServiceASIO<asio::ip::tcp, SessProtoT>;
|
||||
base_t::template start<Session<srv_t>>("TCP", this, _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);
|
||||
#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>;
|
||||
AdcGenericNetServer::start<Session<srv_t>>("LOCAL STREAM", this, _ioContext, ept);
|
||||
base_t::template start<Session<srv_t>>("LOCAL STREAM", this, _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>;
|
||||
// AdcDeviceNetServer::start<Session<srv_t>>("LOCAL DGRAM", this, _ioContext, ept);
|
||||
// base_t::template start<Session<srv_t>>("LOCAL DGRAM", this, _ioContext, ept);
|
||||
} 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>;
|
||||
AdcGenericNetServer::start<Session<srv_t>>("LOCAL SEQPACK", this, _ioContext, ept);
|
||||
base_t::template start<Session<srv_t>>("LOCAL SEQPACK", this, _ioContext, ept);
|
||||
}
|
||||
} else {
|
||||
throw std::system_error(std::make_error_code(std::errc::protocol_not_supported));
|
||||
@@ -80,8 +81,7 @@ public:
|
||||
void start() {}
|
||||
|
||||
template <std::ranges::range RST = std::vector<int>, std::ranges::range RRT = std::vector<int>>
|
||||
void setupSignals(const RST& stop_sig_num = std::vector<int>{SIGINT, SIGTERM},
|
||||
const RRT& restart_sig_num = std::vector<int>{SIGUSR1})
|
||||
void setupSignals(const RST& stop_sig_num = {SIGINT, SIGTERM}, const RRT& restart_sig_num = {SIGUSR1})
|
||||
requires(std::convertible_to<std::ranges::range_value_t<RST>, int> &&
|
||||
std::convertible_to<std::ranges::range_value_t<RRT>, int>)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
|
||||
_restartSignal.async_wait([this](std::error_code ec, int signo) {
|
||||
signalReceived(ec, signo);
|
||||
// ?!!!!!!!
|
||||
restart();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -124,6 +124,16 @@ protected:
|
||||
{
|
||||
std::cout << "SIGNAL: " << signo << "\n";
|
||||
};
|
||||
|
||||
virtual void restart()
|
||||
{
|
||||
this->stopAllSessions();
|
||||
|
||||
_restartSignal.async_wait([this](std::error_code ec, int signo) {
|
||||
signalReceived(ec, signo);
|
||||
restart();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adc::impl
|
||||
|
||||
Reference in New Issue
Block a user