AuroraRuntime/Source/IO/Net/AuNetWorker.cpp

89 lines
2.2 KiB
C++
Raw Normal View History

[+] Network + Protocol + TLS - Initial Commit ============================================================================= Network ]==================================================================== ============================================================================= [+] Added (very) early Aurora::IO::Net implementation [+] AuNet::EHostnameType [+] AuNet::EIPProtocol [+] AuNet::ENetworkError [+] AuNet::ETransportProtocol [+] AuNet::INetInterface [+] AuNet::INetSrvDatagram [+] AuNet::INetSrvResolve [+] AuNet::INetSrvSockets [+] AuNet::INetSrvWorkers [+] AuNet::INetWorker [+] AuNet::IPAddress [+] AuNet::IResolver [+] AuNet::ISocket [+] AuNet::IResolver [+] AuNet::ISocketBase [+] AuNet::ISocketChannel [+] AuNet::ISocketDriver [+] AuNet::ISocketDriverFactory [+] AuNet::ISocketServer [+] AuNet::ISocketServerDriver [+] AuNet::NetEndpoint [+] AuNet::NetError [+] AuNet::NetHostname (+implementation) ============================================================================= Protocol ]=================================================================== ============================================================================= [+] IProtocolInterceptor [+] IProtocolInterceptorEx [+] IProtocolStack (+implementation) ============================================================================= TLS ]======================================================================== ============================================================================= [+] ITLSContext [+] TLSProtocolRecv [+] TLSProtocolSend (+implementation) ============================================================================= IO Bug Fixes ]=============================================================== ============================================================================= [*] IOProcessor::SubmitIOWorkItem should signal the CvEvent, forcing at least once future tick (wont optimize with if in tick & not yet dispatched work items) [*] Split IOPipeWork in into IOPipeProcessor header [+] IOPipeWork::GetBuffer (internal reallocation) [*] Harden against IAsyncTransactions without a loop source [*] Missing null `if (processor->listener)` in IOProcessor [*] Solved some soft-lock conditions under Linux's LoopQueue (added deferred commits) [*] Quick hack: IOProcessor::HasItems() should OR the early can-tick check function. ============================================================================= Other ]====================================================================== ============================================================================= [+] Linux: LSSignalCatcher [+] `static void AuResetMember(Aurora::Memory::ByteBuffer &ref)` for AuROXTL [*] Attempt to enforce a normalization and don't overwrite-readptr-under-istreamwriters policy in ByteBuffer_ReadWrite (circular buffers) [*] Bad ECC ctors ============================================================================= Known issues ]=============================================================== ============================================================================= > Linux net is nowhere near done > UDP socket emulation layer isn't implemented > Ciphersuite API is a stub > Private key API is a stub > ...therefore no TLS servers > Missing thread safety precautions under net > Net implementation is still beri early
2022-08-28 19:02:06 +00:00
/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetWorker.cpp
Date: 2022-8-16
Author: Reece
***/
#include "Networking.hpp"
#include "AuNetWorker.hpp"
#include "AuNetSrvWorkers.hpp"
namespace Aurora::IO::Net
{
NetWorker::NetWorker(NetSrvWorkers *pParent,
AuUInt8 workerIndex,
AuSPtr<IIOProcessor> pIOProcessor) :
pParent_(pParent),
workerIndex_(workerIndex),
pIOProcessor_(pIOProcessor)
{
this->pEvent_ = AuLoop::NewLSEvent(false, true);
SysAssert(bool(this->pEvent_));
}
bool NetWorker::IncrementIOEventTaskCounter()
{
if (AuAtomicAdd(&this->dwAtomicEventCounter_, 1u) != 1)
{
return true;
}
this->pWorkItem_ = this->pIOProcessor_->StartSimpleLSWatchEx(this->ToEvent(),
{},
false);
return bool(this->pWorkItem_);
}
void NetWorker::DecrementIOEventTaskCounter()
{
if (AuAtomicSub(&this->dwAtomicEventCounter_, 1u) == 0)
{
SysAssert(this->pWorkItem_->StopWatch());
}
}
void NetWorker::AddSocket(ISocket *pSocket)
{
SysAssert(AuTryInsert(this->childSockets, pSocket));
}
void NetWorker::RemoveSocket(ISocket *pSocket)
{
/*dont care*/AuTryRemove(this->childSockets, pSocket);
}
AuSPtr<AuLoop::ILSEvent> NetWorker::ToEvent()
{
return this->pEvent_;
}
bool NetWorker::IsOnThread()
{
return this->ToProcessor()->GetOwnedThreadId() == AuThreads::GetThreadId();
}
AuSPtr<IIOProcessor> NetWorker::ToProcessor()
{
return this->pIOProcessor_;
}
AuUInt8 NetWorker::GetWorkerIndex()
{
return this->workerIndex_;
}
void NetWorker::Destroy()
{
auto sockets = AuExchange(this->childSockets, {});
for (const auto &pSocket : sockets)
{
pSocket->Destroy();
}
if (auto pParent = AuExchange(this->pParent_, {}))
{
pParent->RemoveCache(this);
}
}
}