[*] Net: Globalize adapter cache
This commit is contained in:
parent
e0f74d6160
commit
aadca8058e
@ -13,41 +13,40 @@ namespace Aurora::IO::Net
|
|||||||
{
|
{
|
||||||
const AuString &NetSrvInterfaces::GetHostname()
|
const AuString &NetSrvInterfaces::GetHostname()
|
||||||
{
|
{
|
||||||
AU_LOCK_GUARD(this->lock);
|
AU_LOCK_GUARD(NetSrvInterfaces::gLock);
|
||||||
if (this->bShouldUpdateCache)
|
if (NetSrvInterfaces::bShouldUpdateCache)
|
||||||
{
|
{
|
||||||
UpdateCache();
|
UpdateCache();
|
||||||
}
|
}
|
||||||
|
return NetSrvInterfaces::gHostname;
|
||||||
return hostname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetSrvInterfaces::ResetAdapterCache()
|
void NetSrvInterfaces::ResetAdapterCache()
|
||||||
{
|
{
|
||||||
AU_LOCK_GUARD(this->lock);
|
AU_LOCK_GUARD(NetSrvInterfaces::gLock);
|
||||||
this->bShouldUpdateCache = true;
|
NetSrvInterfaces::bShouldUpdateCache = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetSrvInterfaces::UpdateCache()
|
void NetSrvInterfaces::UpdateCache()
|
||||||
{
|
{
|
||||||
this->hostname = NetAdapter::GetHostname();
|
NetSrvInterfaces::gHostname = NetAdapter::GetHostname();
|
||||||
|
|
||||||
auto ipv4s = NetAdapter::GetIPv4s();
|
auto ipv4s = NetAdapter::GetIPv4s();
|
||||||
auto ipv6s = NetAdapter::GetIPv6s();
|
auto ipv6s = NetAdapter::GetIPv6s();
|
||||||
|
|
||||||
this->adapters.clear();
|
NetSrvInterfaces::gAdapters.clear();
|
||||||
this->adapters.insert(this->adapters.end(), ipv4s.begin(), ipv4s.end());
|
NetSrvInterfaces::gAdapters.insert(NetSrvInterfaces::gAdapters.end(), ipv4s.begin(), ipv4s.end());
|
||||||
this->adapters.insert(this->adapters.end(), ipv6s.begin(), ipv6s.end());
|
NetSrvInterfaces::gAdapters.insert(NetSrvInterfaces::gAdapters.end(), ipv6s.begin(), ipv6s.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
AuList<AuSPtr<INetAdapter>> NetSrvInterfaces::GetAdapters()
|
AuList<AuSPtr<INetAdapter>> NetSrvInterfaces::GetAdapters()
|
||||||
{
|
{
|
||||||
AU_LOCK_GUARD(this->lock);
|
AU_LOCK_GUARD(NetSrvInterfaces::gLock);
|
||||||
if (this->bShouldUpdateCache)
|
if (this->bShouldUpdateCache)
|
||||||
{
|
{
|
||||||
UpdateCache();
|
UpdateCache();
|
||||||
}
|
}
|
||||||
return this->adapters;
|
return this->NetSrvInterfaces::gAdapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetSrvInterfaces::IsSupportedOnOS()
|
bool NetSrvInterfaces::IsSupportedOnOS()
|
||||||
|
@ -11,20 +11,18 @@ namespace Aurora::IO::Net
|
|||||||
{
|
{
|
||||||
struct NetSrvInterfaces : INetSrvInterfaces
|
struct NetSrvInterfaces : INetSrvInterfaces
|
||||||
{
|
{
|
||||||
const AuString &GetHostname() override;
|
const AuString & GetHostname() override;
|
||||||
void ResetAdapterCache() override;
|
void ResetAdapterCache() override;
|
||||||
AuList<AuSPtr<INetAdapter>> GetAdapters() override;
|
AuList<AuSPtr<INetAdapter>> GetAdapters() override;
|
||||||
|
|
||||||
bool IsSupportedOnOS();
|
bool IsSupportedOnOS();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void UpdateCache();
|
void UpdateCache();
|
||||||
|
|
||||||
AuThreadPrimitives::SpinLock lock;
|
cstatic AuMutex gLock;
|
||||||
AuString hostname;
|
cstatic AuString gHostname;
|
||||||
bool bShouldUpdateCache { true };
|
cstatic bool bShouldUpdateCache { true };
|
||||||
AuList<AuSPtr<INetAdapter>> adapters;
|
cstatic AuList<AuSPtr<INetAdapter>> gAdapters;
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user