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