Merge pull request #54909 from canhld94/revert-54893-revert-54819-ch_net_interfaces

Resubmit: Avoid excessive calls to getifaddrs in isLocalAddress
This commit is contained in:
Alexey Milovidov 2023-11-25 23:00:18 +01:00 committed by GitHub
commit d29092f8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@
#include <cstring>
#include <optional>
#include <base/types.h>
#include <boost/core/noncopyable.hpp>
#include <Common/Exception.h>
#include <Common/levenshteinDistance.h>
#include <Poco/Net/IPAddress.h>
@ -21,7 +22,7 @@ namespace ErrorCodes
namespace
{
struct NetworkInterfaces
struct NetworkInterfaces : public boost::noncopyable
{
ifaddrs * ifaddr;
NetworkInterfaces()
@ -112,8 +113,8 @@ bool isLocalAddress(const Poco::Net::IPAddress & address)
}
}
NetworkInterfaces interfaces;
return interfaces.hasAddress(address);
static NetworkInterfaces network_interfaces;
return network_interfaces.hasAddress(address);
}