This commit is contained in:
2024-10-28 18:01:42 +03:00
parent 7685f4c014
commit 1047b57013
6 changed files with 147 additions and 28 deletions

View File

@@ -377,12 +377,16 @@ public:
// _devices.try_emplace(dev_ptr, dev_ptr, std::forward<IdSerialT>(id_ser_func),
// std::forward<AttrIdDeserialT>(attr_id_deser_func),
// std::forward<CmdIdDeserialT>(cmd_id_deser_func));
return *this;
}
template <interfaces::adc_device_c DeviceT>
AdcDeviceNetServer& delDevice(DeviceT* dev_ptr)
{
_devices.erase(dev_ptr);
return *this;
}
};

View File

@@ -40,6 +40,8 @@ namespace adc
class AdcEndpointParser
{
typedef std::span<char> host_part_t;
public:
static constexpr std::string_view protoHostDelim = "://";
static constexpr std::string_view hostPortDelim = ":";
@@ -115,16 +117,19 @@ public:
_proto = validProtoMarks[idx];
_host = std::string_view{found.end(), _endpoint.end()};
// _host = std::string_view{found.end(), _endpoint.end()};
_host = host_part_t{found.end(), _endpoint.end()};
auto f1 = std::ranges::search(_host, portPathDelim);
std::string_view port_sv;
if (f1.empty() && isLocal()) { // no path, but it is mandatory for 'local'!
return _isValid;
} else {
_host = std::string_view(_host.begin(), f1.begin());
// _host = std::string_view(_host.begin(), f1.begin());
_host = host_part_t{found.end(), _endpoint.end()};
_path = std::string_view(f1.end(), &*_endpoint.end());
// _path = std::string_view(f1.end(), &*_endpoint.end());
_path = std::string_view(&*f1.end(), &*_endpoint.end());
f1 = std::ranges::search(_host, hostPortDelim);
if (f1.empty() && !isLocal()) { // no port, but it is mandatory for non-local!
@@ -133,7 +138,8 @@ public:
port_sv = std::string_view(f1.end(), _host.end());
if (port_sv.size()) {
_host = std::string_view(_host.begin(), f1.begin());
// _host = std::string_view(_host.begin(), f1.begin());
_host = host_part_t{found.end(), _endpoint.end()};
if (!isLocal()) {
// convert port string to int
@@ -159,7 +165,7 @@ public:
}
return ok;
})) {
_host = validLocalProtoTypes[idx];
// _host = validLocalProtoTypes[idx];
} else {
return _isValid;
}
@@ -223,17 +229,20 @@ public:
bool isLocalStream() const
{
return host() == localProtoTypeStream;
// return host() == localProtoTypeStream;
return utils::AdcCharRangeCompare(host(), localProtoTypeStream, true);
}
bool isLocalDatagram() const
{
return host() == localProtoTypeDatagram;
// return host() == localProtoTypeDatagram;
return utils::AdcCharRangeCompare(host(), localProtoTypeDatagram, true);
}
bool isLocalSeqpacket() const
{
return host() == localProtoTypeSeqpacket;
// return host() == localProtoTypeSeqpacket;
return utils::AdcCharRangeCompare(host(), localProtoTypeSeqpacket, true);
}
@@ -264,7 +273,9 @@ public:
protected:
std::string _endpoint;
std::string_view _proto, _host, _path;
// std::string_view _proto, _host, _path;
std::string_view _proto, _path;
host_part_t _host;
int _port;
bool _isValid;
@@ -298,28 +309,54 @@ protected:
// return res;
// }
auto part = _proto;
// auto part = _proto;
// switch (what) {
// case PROTO_PART:
// part = _proto;
// break;
// case HOST_PART:
// part = _host;
// break;
// case PATH_PART:
// part = _path;
// break;
// default:
// break;
// }
// if constexpr (std::ranges::view<R>) {
// return R(part.begin(), part.end());
// } else {
// std::ranges::copy(part, std::back_inserter(res));
// }
switch (what) {
case PROTO_PART:
part = _proto;
if constexpr (std::ranges::view<R>) {
res = R(_proto.begin(), _proto.size());
} else {
std::ranges::copy(_proto, std::back_inserter(res));
}
break;
case HOST_PART:
part = _host;
if constexpr (std::ranges::view<R>) {
res = R(_host.begin(), _host.end());
} else {
std::ranges::copy(_host, std::back_inserter(res));
}
break;
case PATH_PART:
part = _path;
if constexpr (std::ranges::view<R>) {
res = R(_path.begin(), _path.end());
} else {
std::ranges::copy(_path, std::back_inserter(res));
}
break;
default:
break;
}
if constexpr (std::ranges::view<R>) {
return {part.begin(), part.end()};
} else {
std::ranges::copy(part, res);
}
return res;
}
};

View File

@@ -18,7 +18,8 @@ class AdcDeviceNetServerASIO : public AdcDeviceNetServer
{
public:
template <traits::adc_input_char_range R>
AdcDeviceNetServerASIO(const R& id, asio::io_context& io_context) : AdcDeviceNetServer(id), _ioContext(io_context)
AdcDeviceNetServerASIO(const R& id, asio::io_context& io_context)
: AdcDeviceNetServer(id), _ioContext(io_context), _stopSignal(io_context), _restartSignal(io_context)
{
}
@@ -53,10 +54,10 @@ public:
asio::local::stream_protocol::endpoint ept(endpoint.template path<std::string>());
using srv_t = AdcNetServiceASIO<asio::local::stream_protocol, SessProtoT>;
AdcDeviceNetServer::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);
// } 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);
} 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>;
@@ -70,7 +71,7 @@ public:
// some default endpoint?!!
void start() {}
template <std::ranges::range RST, std::ranges::range RRT>
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})
requires(std::convertible_to<std::ranges::range_value_t<RST>, int> &&

View File

@@ -116,8 +116,8 @@ class AdcBaseNetServiceASIO : public SESSION_PROTOT
{
public:
#ifdef USE_OPENSSL_WITH_ASIO
static_assert(!(USE_TLS && adc_asio_tls_transport_proto_c<TRANSPORT_PROTOT>),
"INVALID 'TRANSPORT_PROTOT' TEMPLATE ARGUMENT!");
// static_assert(!(USE_TLS && adc_asio_tls_transport_proto_c<TRANSPORT_PROTOT>),
// "INVALID 'TRANSPORT_PROTOT' TEMPLATE ARGUMENT!");
static constexpr bool isTLS = USE_TLS;
#else // ignore USE_TLS
@@ -250,7 +250,8 @@ public:
template <traits::adc_time_duration_c DT = decltype(DEFAULT_ACCEPT_TIMEOUT)>
auto accept(const endpoint_t& endpoint, const DT& timeout = DEFAULT_ACCEPT_TIMEOUT)
{
return accept(endpoint, timeout);
_acceptor = srv_acceptor_t(_ioContext, endpoint);
return accept(timeout);
}
private: