fix 100% load of CPU after client disconnection

(AdcBaseNetServiceASIO.asyncReceive)
add resolving domain name (AdcDeviceNetServerASIO)
This commit is contained in:
Timur A. Fatkhullin
2024-11-17 23:50:15 +03:00
parent 221f595bcb
commit 45b8d4a3c7
4 changed files with 108 additions and 38 deletions

View File

@@ -143,7 +143,7 @@ public:
_host = std::string_view{found.end(), _endpoint.end()};
auto f1 = std::ranges::search(_host, portPathDelim);
std::string_view port_sv;
// std::string_view port_sv;
if (f1.empty() && isLocal()) { // no path, but it is mandatory for 'local'!
return _isValid;
} else {
@@ -156,15 +156,15 @@ public:
return _isValid;
}
port_sv = std::string_view(f1.end(), _host.end());
if (port_sv.size()) {
_portView = std::string_view(f1.end(), _host.end());
if (_portView.size()) {
_host = std::string_view(_host.begin(), f1.begin());
if (!isLocal()) {
// convert port string to int
auto end_ptr = port_sv.data() + port_sv.size();
auto end_ptr = _portView.data() + _portView.size();
auto [ptr, ec] = std::from_chars(port_sv.data(), end_ptr, _port);
auto [ptr, ec] = std::from_chars(_portView.data(), end_ptr, _port);
if (ec != std::errc() || ptr != end_ptr) {
return _isValid;
}
@@ -235,6 +235,17 @@ public:
return _port;
}
template <traits::adc_view_or_output_char_range R>
R portView() const
{
return part<R>(PORT_PART);
}
std::string_view portView() const
{
return portView<std::string_view>();
}
template <traits::adc_view_or_output_char_range R>
R path() const
{
@@ -295,7 +306,7 @@ public:
protected:
std::string _endpoint;
std::string_view _proto, _host, _path;
std::string_view _proto, _host, _path, _portView;
int _port;
bool _isValid;
@@ -318,7 +329,7 @@ protected:
return found ? idx : -1;
}
enum EndpointPart { PROTO_PART, HOST_PART, PATH_PART };
enum EndpointPart { PROTO_PART, HOST_PART, PATH_PART, PORT_PART };
template <traits::adc_view_or_output_char_range R>
R part(EndpointPart what) const
@@ -341,6 +352,9 @@ protected:
case PATH_PART:
part = _path;
break;
case PORT_PART:
part = _portView;
break;
default:
break;
}