/*** 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() { this->pCondVar_ = AuThreadPrimitives::CriticalSectionUnique(); SysAssert(this->pCondVar_); } AuSPtr NetSrvWorkers::Attach(const AuSPtr &processor) { AU_LOCK_GUARD(this->spinLock_); auto worker = AuMakeShared(this, this->workerPool_.size(), processor); if (!worker) { SysPushErrorIO("Can't spawn. No memory"); return {}; } if (!AuTryInsert(this->workerPool_, worker)) { SysPushErrorIO(""); return {}; } return worker; } void NetSrvWorkers::Destroy() { } void NetSrvWorkers::RemoveCache(NetWorker *worker) { AU_LOCK_GUARD(this->spinLock_); 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 NetSrvWorkers::GetWorkerByIndex(AuUInt index) { AU_LOCK_GUARD(this->spinLock_); return this->workerPool_[index % this->workerPool_.size()]; } AuSPtr NetSrvWorkers::GetWorkerByIndexSafe(AuUInt index) { return this->GetWorkerByIndex(index); } }