104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuNetInterface.cpp
|
|
Date: 2022-8-16
|
|
Author: Reece
|
|
***/
|
|
#include "Networking.hpp"
|
|
#include "AuNetInterface.hpp"
|
|
#include "AuNetWorker.hpp"
|
|
|
|
namespace Aurora::IO::Net
|
|
{
|
|
NetInterface::NetInterface() :
|
|
netServiceResolve_(this),
|
|
netServiceSockets_(this),
|
|
netServiceDatagram_(this)
|
|
{
|
|
|
|
}
|
|
|
|
AuSPtr<INetSrvWorkers> NetInterface::GetWorkersService()
|
|
{
|
|
return AuSPtr<INetSrvWorkers>(AuSharedFromThis(), &this->netServiceWorkers_);
|
|
}
|
|
|
|
AuSPtr<INetSrvResolve> NetInterface::GetResolveService()
|
|
{
|
|
return AuSPtr<INetSrvResolve>(AuSharedFromThis(), &this->netServiceResolve_);
|
|
}
|
|
|
|
AuSPtr<INetSrvSockets> NetInterface::GetSocketService()
|
|
{
|
|
return AuSPtr<INetSrvSockets>(AuSharedFromThis(), &this->netServiceSockets_);
|
|
}
|
|
|
|
AuSPtr<INetSrvDatagram> NetInterface::GetDatagramService()
|
|
{
|
|
return AuSPtr<INetSrvDatagram>(AuSharedFromThis(), &this->netServiceDatagram_);
|
|
}
|
|
|
|
AuSPtr<INetSrvInterfaces> NetInterface::GetInterfacesService()
|
|
{
|
|
if (!this->netServiceInterfaces_.IsSupportedOnOS())
|
|
{
|
|
return {};
|
|
}
|
|
return AuSPtr<INetSrvInterfaces>(AuSharedFromThis(), &this->netServiceInterfaces_);
|
|
}
|
|
|
|
bool NetInterface::TrySchedule(const AuSPtr<IIOProcessorWorkUnit> &pWorkUnit)
|
|
{
|
|
auto workerId = AuAtomicAdd<AuUInt>(&this->atomicCounter_, 1u) - 1u;
|
|
auto worker = this->netServiceWorkers_.GetWorkerByIndex(workerId);
|
|
if (!worker)
|
|
{
|
|
SysPushErrorIO("No Worker");
|
|
return {};
|
|
}
|
|
|
|
return worker->ToProcessor()->SubmitIOWorkItem(pWorkUnit);
|
|
}
|
|
|
|
AuSPtr<NetWorker> NetInterface::TryScheduleEx()
|
|
{
|
|
AuSPtr<NetWorker> worker;
|
|
|
|
do
|
|
{
|
|
worker = this->netServiceWorkers_.GetWorkerByIndex(AuAtomicAdd<AuUInt>(&this->atomicCounter_, 1u) - 1u);
|
|
} while (!worker);
|
|
|
|
return worker;
|
|
}
|
|
|
|
void NetInterface::Shutdown()
|
|
{
|
|
|
|
}
|
|
|
|
void NetInterface::Destroy()
|
|
{
|
|
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<INetInterface> NewNetworkInterface()
|
|
{
|
|
if (!IsNetReady())
|
|
{
|
|
SysPushErrorNet("Platform network service isn't available");
|
|
return {};
|
|
}
|
|
|
|
auto iface = AuMakeShared<NetInterface>();
|
|
if (!iface)
|
|
{
|
|
return iface;
|
|
}
|
|
|
|
// TODO: ...
|
|
|
|
return iface;
|
|
}
|
|
} |