[+] Added INetworkInterface overloads
[+] INetInterface::SetWorkersService [+] INetInterface::SetResolveService [+] INetInterface::SetDatagramService [+] INetInterface::SetInterfacesService [*] Refactor: INetAdapter::GetStatus -> INetAdapter::GetAdapterStatus [*] Refactor: const NetError &ISocketBase::GetError() -> AuOptional<const NetError &> ISocketBase::GetError() [*] Refactor: INetAdapter to return const references of IPAddresses
This commit is contained in:
parent
5668188945
commit
2717178681
@ -20,15 +20,15 @@ namespace Aurora::IO::Net
|
|||||||
virtual AuUInt16 GetIndex() = 0;
|
virtual AuUInt16 GetIndex() = 0;
|
||||||
|
|
||||||
virtual ENetworkAdapterType GetAdapterType() = 0;
|
virtual ENetworkAdapterType GetAdapterType() = 0;
|
||||||
virtual ENetworkAdapterStatus GetStatus() = 0;
|
virtual ENetworkAdapterStatus GetAdapterStatus() = 0;
|
||||||
|
|
||||||
virtual EIPProtocol GetFamily() = 0;
|
virtual EIPProtocol GetFamily() = 0;
|
||||||
|
|
||||||
virtual IPAddress GetAddress() = 0;
|
virtual const IPAddress &GetAddress() = 0;
|
||||||
virtual IPAddress GetBroadcastAddress() = 0;
|
virtual const IPAddress &GetBroadcastAddress() = 0;
|
||||||
virtual IPAddress GetAnycastAddress() = 0;
|
virtual const IPAddress &GetAnycastAddress() = 0;
|
||||||
virtual IPAddress GetSubnetMask() = 0;
|
virtual const IPAddress &GetSubnetMask() = 0;
|
||||||
virtual IPAddress GetGateway() = 0;
|
virtual const IPAddress &GetGateway() = 0;
|
||||||
|
|
||||||
virtual AuArray<AuUInt8, 8> GetMacAddress() = 0;
|
virtual AuArray<AuUInt8, 8> GetMacAddress() = 0;
|
||||||
|
|
||||||
|
@ -24,14 +24,19 @@ namespace Aurora::IO::Net
|
|||||||
virtual bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) = 0;
|
virtual bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) = 0;
|
||||||
|
|
||||||
virtual AuSPtr<INetSrvWorkers> GetWorkersService() = 0;
|
virtual AuSPtr<INetSrvWorkers> GetWorkersService() = 0;
|
||||||
|
virtual void SetWorkersService(const AuSPtr<INetSrvWorkers> &pWorkers) = 0;
|
||||||
|
|
||||||
virtual AuSPtr<INetSrvResolve> GetResolveService() = 0;
|
virtual AuSPtr<INetSrvResolve> GetResolveService() = 0;
|
||||||
|
virtual void SetResolveService(const AuSPtr<INetSrvResolve> &pResolve) = 0;
|
||||||
|
|
||||||
virtual AuSPtr<INetSrvSockets> GetSocketService() = 0;
|
virtual AuSPtr<INetSrvSockets> GetSocketService() = 0;
|
||||||
|
virtual void SetSocketService(const AuSPtr<INetSrvSockets> &pSockets) = 0;
|
||||||
|
|
||||||
virtual AuSPtr<INetSrvDatagram> GetDatagramService() = 0;
|
virtual AuSPtr<INetSrvDatagram> GetDatagramService() = 0;
|
||||||
|
virtual void SetDatagramService(const AuSPtr<INetSrvDatagram> &pDatagrams) = 0;
|
||||||
|
|
||||||
virtual AuSPtr<INetSrvInterfaces> GetInterfacesService() = 0;
|
virtual AuSPtr<INetSrvInterfaces> GetInterfacesService() = 0;
|
||||||
|
virtual void SetInterfacesService(const AuSPtr<INetSrvInterfaces> &pNetworkInterfaces) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ namespace Aurora::IO::Net
|
|||||||
|
|
||||||
struct ISocketBase
|
struct ISocketBase
|
||||||
{
|
{
|
||||||
virtual const NetError &GetError() = 0;
|
virtual AuOptional<const NetError &> GetError() = 0;
|
||||||
|
|
||||||
virtual const NetEndpoint &GetLocalEndpoint() = 0;
|
virtual const NetEndpoint &GetLocalEndpoint() = 0;
|
||||||
|
|
||||||
virtual void Shutdown(bool bNow = true) = 0;
|
virtual void Shutdown(bool bNow = true) = 0;
|
||||||
|
@ -16,17 +16,7 @@ namespace Aurora::IO::Net
|
|||||||
return this->name.empty() ? this->device : this->name;
|
return this->name.empty() ? this->device : this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress NetAdapter::GetAddress()
|
const IPAddress &NetAdapter::GetSubnetMask()
|
||||||
{
|
|
||||||
return this->address;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress NetAdapter::GetBroadcastAddress()
|
|
||||||
{
|
|
||||||
return this->broadcast;
|
|
||||||
}
|
|
||||||
|
|
||||||
IPAddress NetAdapter::GetSubnetMask()
|
|
||||||
{
|
{
|
||||||
return this->subnet;
|
return this->subnet;
|
||||||
}
|
}
|
||||||
@ -41,7 +31,7 @@ namespace Aurora::IO::Net
|
|||||||
return this->eNetworkType;
|
return this->eNetworkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetworkAdapterStatus NetAdapter::GetStatus()
|
ENetworkAdapterStatus NetAdapter::GetAdapterStatus()
|
||||||
{
|
{
|
||||||
return this->eNetworkStatus;
|
return this->eNetworkStatus;
|
||||||
}
|
}
|
||||||
@ -56,12 +46,22 @@ namespace Aurora::IO::Net
|
|||||||
return this->index;
|
return this->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress NetAdapter::GetAnycastAddress()
|
const IPAddress &NetAdapter::GetAddress()
|
||||||
|
{
|
||||||
|
return this->address;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IPAddress &NetAdapter::GetBroadcastAddress()
|
||||||
|
{
|
||||||
|
return this->broadcast;
|
||||||
|
}
|
||||||
|
|
||||||
|
const IPAddress &NetAdapter::GetAnycastAddress()
|
||||||
{
|
{
|
||||||
return this->anycast;
|
return this->anycast;
|
||||||
}
|
}
|
||||||
|
|
||||||
IPAddress NetAdapter::GetGateway()
|
const IPAddress &NetAdapter::GetGateway()
|
||||||
{
|
{
|
||||||
return this->gateway;
|
return this->gateway;
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,13 @@ namespace Aurora::IO::Net
|
|||||||
EIPProtocol GetFamily() override;
|
EIPProtocol GetFamily() override;
|
||||||
|
|
||||||
ENetworkAdapterType GetAdapterType() override;
|
ENetworkAdapterType GetAdapterType() override;
|
||||||
ENetworkAdapterStatus GetStatus() override;
|
ENetworkAdapterStatus GetAdapterStatus() override;
|
||||||
|
|
||||||
IPAddress GetAddress() override;
|
const IPAddress &GetAddress() override;
|
||||||
IPAddress GetBroadcastAddress() override;
|
const IPAddress &GetBroadcastAddress() override;
|
||||||
IPAddress GetAnycastAddress() override;
|
const IPAddress &GetAnycastAddress() override;
|
||||||
IPAddress GetSubnetMask() override;
|
const IPAddress &GetSubnetMask() override;
|
||||||
IPAddress GetGateway() override;
|
const IPAddress &GetGateway() override;
|
||||||
|
|
||||||
AuList<IPAddress> GetDNS() override;
|
AuList<IPAddress> GetDNS() override;
|
||||||
|
|
||||||
|
@ -170,6 +170,9 @@ namespace Aurora::IO::Net
|
|||||||
// "enough free file descriptor slots to accept them" - recvfrom
|
// "enough free file descriptor slots to accept them" - recvfrom
|
||||||
error.netError = ENetworkError::eResourceConstraint;
|
error.netError = ENetworkError::eResourceConstraint;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
error.netError = ENetworkError::eUnknown;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -19,35 +19,85 @@ namespace Aurora::IO::Net
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NET_INTERFACE_ADD_SERVICE(type, selfHosted, pOverload) \
|
||||||
|
AU_LOCK_GUARD(this->mutex_); \
|
||||||
|
\
|
||||||
|
if (this->pOverload) \
|
||||||
|
{ \
|
||||||
|
return this->pOverload; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
return AuSPtr<type>(AuSharedFromThis(), &this->selfHosted); \
|
||||||
|
}
|
||||||
|
|
||||||
AuSPtr<INetSrvWorkers> NetInterface::GetWorkersService()
|
AuSPtr<INetSrvWorkers> NetInterface::GetWorkersService()
|
||||||
{
|
{
|
||||||
return AuSPtr<INetSrvWorkers>(AuSharedFromThis(), &this->netServiceWorkers_);
|
NET_INTERFACE_ADD_SERVICE(INetSrvWorkers, netServiceWorkers_, pNetServiceOverloadWorkers_);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<INetSrvResolve> NetInterface::GetResolveService()
|
AuSPtr<INetSrvResolve> NetInterface::GetResolveService()
|
||||||
{
|
{
|
||||||
return AuSPtr<INetSrvResolve>(AuSharedFromThis(), &this->netServiceResolve_);
|
NET_INTERFACE_ADD_SERVICE(INetSrvResolve, netServiceResolve_, pNetServiceOverloadResolve_);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<INetSrvSockets> NetInterface::GetSocketService()
|
AuSPtr<INetSrvSockets> NetInterface::GetSocketService()
|
||||||
{
|
{
|
||||||
return AuSPtr<INetSrvSockets>(AuSharedFromThis(), &this->netServiceSockets_);
|
NET_INTERFACE_ADD_SERVICE(INetSrvSockets, netServiceSockets_, pNetServiceOverloadSockets_);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<INetSrvDatagram> NetInterface::GetDatagramService()
|
AuSPtr<INetSrvDatagram> NetInterface::GetDatagramService()
|
||||||
{
|
{
|
||||||
return AuSPtr<INetSrvDatagram>(AuSharedFromThis(), &this->netServiceDatagram_);
|
NET_INTERFACE_ADD_SERVICE(INetSrvDatagram, netServiceDatagram_, pNetServiceOverloadDatagram_);
|
||||||
}
|
}
|
||||||
|
|
||||||
AuSPtr<INetSrvInterfaces> NetInterface::GetInterfacesService()
|
AuSPtr<INetSrvInterfaces> NetInterface::GetInterfacesService()
|
||||||
{
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
|
||||||
|
if (this->pNetServiceOverloadNetworkInterfaces_)
|
||||||
|
{
|
||||||
|
return this->pNetServiceOverloadNetworkInterfaces_;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this->netServiceInterfaces_.IsSupportedOnOS())
|
if (!this->netServiceInterfaces_.IsSupportedOnOS())
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return AuSPtr<INetSrvInterfaces>(AuSharedFromThis(), &this->netServiceInterfaces_);
|
return AuSPtr<INetSrvInterfaces>(AuSharedFromThis(), &this->netServiceInterfaces_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetInterface::SetWorkersService(const AuSPtr<INetSrvWorkers> &pWorkers)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
this->pNetServiceOverloadWorkers_ = pWorkers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetInterface::SetResolveService(const AuSPtr<INetSrvResolve> &pResolve)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
this->pNetServiceOverloadResolve_ = pResolve;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetInterface::SetSocketService(const AuSPtr<INetSrvSockets> &pSockets)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
this->pNetServiceOverloadSockets_ = pSockets;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetInterface::SetDatagramService(const AuSPtr<INetSrvDatagram> &pDatagrams)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
this->pNetServiceOverloadDatagram_ = pDatagrams;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NetInterface::SetInterfacesService(const AuSPtr<INetSrvInterfaces> &pNetworkInterfaces)
|
||||||
|
{
|
||||||
|
AU_LOCK_GUARD(this->mutex_);
|
||||||
|
this->pNetServiceOverloadNetworkInterfaces_ = pNetworkInterfaces;
|
||||||
|
}
|
||||||
|
|
||||||
bool NetInterface::TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit)
|
bool NetInterface::TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit)
|
||||||
{
|
{
|
||||||
auto workerId = AuAtomicAdd<AuUInt>(&this->atomicCounter_, 1u) - 1u;
|
auto workerId = AuAtomicAdd<AuUInt>(&this->atomicCounter_, 1u) - 1u;
|
||||||
|
@ -15,19 +15,25 @@
|
|||||||
|
|
||||||
namespace Aurora::IO::Net
|
namespace Aurora::IO::Net
|
||||||
{
|
{
|
||||||
struct NetInterface : INetInterface, AuEnableSharedFromThis<NetInterface>
|
struct NetInterface : INetInterface,
|
||||||
|
AuEnableSharedFromThis<NetInterface>
|
||||||
{
|
{
|
||||||
NetInterface();
|
NetInterface();
|
||||||
|
|
||||||
AuSPtr<INetSrvWorkers> GetWorkersService() override;
|
AuSPtr<INetSrvWorkers> GetWorkersService() override;
|
||||||
|
void SetWorkersService(const AuSPtr<INetSrvWorkers> &pWorkers) override;
|
||||||
|
|
||||||
AuSPtr<INetSrvResolve> GetResolveService() override;
|
AuSPtr<INetSrvResolve> GetResolveService() override;
|
||||||
|
void SetResolveService(const AuSPtr<INetSrvResolve> &pResolve) override;
|
||||||
|
|
||||||
AuSPtr<INetSrvSockets> GetSocketService() override;
|
AuSPtr<INetSrvSockets> GetSocketService() override;
|
||||||
|
void SetSocketService(const AuSPtr<INetSrvSockets> &pSockets) override;
|
||||||
|
|
||||||
AuSPtr<INetSrvDatagram> GetDatagramService() override;
|
AuSPtr<INetSrvDatagram> GetDatagramService() override;
|
||||||
|
void SetDatagramService(const AuSPtr<INetSrvDatagram> &pSockets) override;
|
||||||
|
|
||||||
AuSPtr<INetSrvInterfaces> GetInterfacesService() override;
|
AuSPtr<INetSrvInterfaces> GetInterfacesService() override;
|
||||||
|
void SetInterfacesService(const AuSPtr<INetSrvInterfaces> &pNetworkInterfaces) override;
|
||||||
|
|
||||||
bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) override;
|
bool TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit) override;
|
||||||
AuSPtr<NetWorker> TryScheduleEx();
|
AuSPtr<NetWorker> TryScheduleEx();
|
||||||
@ -41,7 +47,12 @@ namespace Aurora::IO::Net
|
|||||||
NetSrvResolve netServiceResolve_;
|
NetSrvResolve netServiceResolve_;
|
||||||
NetSrvDatagram netServiceDatagram_;
|
NetSrvDatagram netServiceDatagram_;
|
||||||
NetSrvInterfaces netServiceInterfaces_;
|
NetSrvInterfaces netServiceInterfaces_;
|
||||||
|
AuSPtr<INetSrvWorkers> pNetServiceOverloadWorkers_;
|
||||||
AuUInt atomicCounter_;
|
AuSPtr<INetSrvResolve> pNetServiceOverloadResolve_;
|
||||||
|
AuSPtr<INetSrvSockets> pNetServiceOverloadSockets_;
|
||||||
|
AuSPtr<INetSrvDatagram> pNetServiceOverloadDatagram_;
|
||||||
|
AuSPtr<INetSrvInterfaces> pNetServiceOverloadNetworkInterfaces_;
|
||||||
|
AuUInt atomicCounter_ {};
|
||||||
|
AuMutex mutex_;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -500,7 +500,7 @@ namespace Aurora::IO::Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetError &SocketBase::GetError()
|
AuOptional<const NetError &> SocketBase::GetError()
|
||||||
{
|
{
|
||||||
if (this->error_.netError == ENetworkError::kEnumInvalid)
|
if (this->error_.netError == ENetworkError::kEnumInvalid)
|
||||||
{
|
{
|
||||||
@ -528,6 +528,11 @@ namespace Aurora::IO::Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->error_.netError == ENetworkError::kEnumInvalid)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return this->error_;
|
return this->error_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ namespace Aurora::IO::Net
|
|||||||
const NetEndpoint &GetRemoteEndpoint() override;
|
const NetEndpoint &GetRemoteEndpoint() override;
|
||||||
const NetEndpoint &GetLocalEndpoint() override;
|
const NetEndpoint &GetLocalEndpoint() override;
|
||||||
|
|
||||||
const NetError &GetError() override;
|
AuOptional<const NetError &> GetError() override;
|
||||||
|
|
||||||
AuSPtr<ISocketServer> GetSocketServer() override;
|
AuSPtr<ISocketServer> GetSocketServer() override;
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Aurora::IO::Net
|
namespace Aurora::IO::Net
|
||||||
{
|
{
|
||||||
const NetError &NetDatagramEmulatorISocket::GetError()
|
AuOptional<const NetError &> NetDatagramEmulatorISocket::GetError()
|
||||||
{
|
{
|
||||||
return this->pParent->lastError ?
|
return this->pParent->lastError ?
|
||||||
this->pParent->lastError.value() :
|
this->pParent->lastError.value() :
|
||||||
|
@ -19,7 +19,7 @@ namespace Aurora::IO::Net
|
|||||||
}
|
}
|
||||||
NetDatagramSocketServerSession * const pParent;
|
NetDatagramSocketServerSession * const pParent;
|
||||||
|
|
||||||
const NetError &GetError() override;
|
AuOptional<const NetError &> GetError() override;
|
||||||
const NetEndpoint &GetLocalEndpoint() override;
|
const NetEndpoint &GetLocalEndpoint() override;
|
||||||
|
|
||||||
void Shutdown(bool bNow) override;
|
void Shutdown(bool bNow) override;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Aurora::IO::Net
|
namespace Aurora::IO::Net
|
||||||
{
|
{
|
||||||
const NetError &NetDatagramEmulatorISocketServer::GetError()
|
AuOptional<const NetError &> NetDatagramEmulatorISocketServer::GetError()
|
||||||
{
|
{
|
||||||
return this->pParent->GetError();
|
return this->pParent->GetError();
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace Aurora::IO::Net
|
|||||||
}
|
}
|
||||||
NetDatagramSocketServer * const pParent;
|
NetDatagramSocketServer * const pParent;
|
||||||
|
|
||||||
const NetError &GetError() override;
|
AuOptional<const NetError &> GetError() override;
|
||||||
const NetEndpoint &GetLocalEndpoint() override;
|
const NetEndpoint &GetLocalEndpoint() override;
|
||||||
|
|
||||||
void Shutdown(bool bNow) override;
|
void Shutdown(bool bNow) override;
|
||||||
|
@ -316,9 +316,16 @@ namespace Aurora::IO::Net
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetError &NetDatagramSocketServer::GetError()
|
AuOptional<const NetError &> NetDatagramSocketServer::GetError()
|
||||||
{
|
{
|
||||||
return this->lastError;
|
if (this->lastError.netError == ENetworkError::kEnumInvalid)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this->lastError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetEndpoint &NetDatagramSocketServer::GetLocalEndpoint()
|
const NetEndpoint &NetDatagramSocketServer::GetLocalEndpoint()
|
||||||
|
@ -45,7 +45,7 @@ namespace Aurora::IO::Net
|
|||||||
AuSPtr<NetDatagramSocketServerDriver> ToDriver();
|
AuSPtr<NetDatagramSocketServerDriver> ToDriver();
|
||||||
AuSPtr<ISocketServer> ToSocketServer();
|
AuSPtr<ISocketServer> ToSocketServer();
|
||||||
|
|
||||||
const NetError &GetError() override;
|
AuOptional<const NetError &>GetError() override;
|
||||||
const NetEndpoint &GetLocalEndpoint() override;
|
const NetEndpoint &GetLocalEndpoint() override;
|
||||||
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
AuSPtr<INetWorker> GetLockedWorkerThread() override;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user