AuroraRuntime/Source/IO/Net/AuNetSrvWorkers.cpp

73 lines
1.8 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSrvWorkers.cpp
Date: 2022-8-16
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetSrvWorkers.hpp"
#include "AuNetWorker.hpp"
namespace Aurora::IO::Net
{
NetSrvWorkers::NetSrvWorkers()
{
}
AuSPtr<INetWorker> NetSrvWorkers::Attach(const AuSPtr<IIOProcessor> &processor)
{
AU_LOCK_GUARD(this->mutex_);
auto worker = AuMakeShared<NetWorker>(this,
this->workerPool_.size(),
processor);
if (!worker)
{
SysPushErrorIO("Can't spawn. No memory");
return {};
}
if (!AuTryInsert(this->workerPool_, AuConstReference(worker)))
{
SysPushErrorIO("");
return {};
}
return worker;
}
void NetSrvWorkers::Destroy()
{
}
void NetSrvWorkers::RemoveCache(NetWorker *worker)
{
AU_LOCK_GUARD(this->mutex_);
for (AuUInt i = 0;
i < this->workerPool_.size();
i++)
{
if (bool(this->workerPool_[i]) &&
bool(this->workerPool_[i].get() == worker))
{
this->workerPool_[i].reset();
return;
}
}
SysPushErrorIO("Couldn't remove socket from cache. What kind of condition is this?");
}
AuSPtr<NetWorker> NetSrvWorkers::GetWorkerByIndex(AuUInt index)
{
AU_LOCK_GUARD(this->mutex_);
return this->workerPool_[index % this->workerPool_.size()];
}
AuSPtr<INetWorker> NetSrvWorkers::GetWorkerByIndexSafe(AuUInt index)
{
return this->GetWorkerByIndex(index);
}
}