============================================================================= 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
180 lines
4.4 KiB
C++
180 lines
4.4 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuNetSocketOverlappedOperation.Unix.cpp
|
|
Date: 2022-8-26
|
|
Author: Reece
|
|
***/
|
|
#include "Networking.hpp"
|
|
#include "AuNetSocketOverlappedOperation.hpp"
|
|
#include <Source/IO/Loop/LSEvent.hpp>
|
|
|
|
#include "AuNetSocket.Unix.hpp"
|
|
#include "AuNetError.hpp"
|
|
|
|
namespace Aurora::IO::Net
|
|
{
|
|
SocketOverlappedOperation::SocketOverlappedOperation(bool bMultipleTrigger) :
|
|
bMultipleTrigger(bMultipleTrigger)
|
|
{
|
|
this->pEvent = AuLoop::NewLSEvent(false, true);
|
|
if (!this->pEvent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
SocketOverlappedOperation::SocketOverlappedOperation(const AuSPtr<AuLoop::ILoopSource> &pTrigger)
|
|
{
|
|
this->pEvent = pTrigger;
|
|
}
|
|
|
|
bool SocketOverlappedOperation::FinishOperation(const AuSPtr<void> &pThat,
|
|
const AuSPtr<INetWorker> &pWorker,
|
|
bool bReturnCode)
|
|
|
|
{
|
|
return this->FinishOperationEx(pThat, pWorker, bReturnCode, errno);
|
|
}
|
|
|
|
bool SocketOverlappedOperation::FinishOperationEx(const AuSPtr<void> &pThat,
|
|
const AuSPtr<INetWorker> &pWorker,
|
|
bool bReturnCode,
|
|
AuUInt32 dwErrorCode)
|
|
{
|
|
if (bReturnCode)
|
|
{
|
|
this->OnIOComplete();
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if ((dwErrorCode == EAGAIN) ||
|
|
(dwErrorCode == EINPROGRESS))
|
|
{
|
|
return this->BeginOperation(pThat, pWorker);
|
|
}
|
|
else
|
|
{
|
|
// ERROR
|
|
SysPushErrorIO("Couldn't connect [overlapped] (0x{:x})", dwErrorCode);
|
|
this->uOsError = dwErrorCode;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool SocketOverlappedOperation::BeginOperation(const AuSPtr<void> &that,
|
|
const AuSPtr<INetWorker> &pWorker)
|
|
{
|
|
this->pSocket = that;
|
|
auto bStatus = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
|
|
AuSPtr<AuIO::IIOSimpleEventListener>(that, this),
|
|
true);
|
|
if (!bStatus)
|
|
{
|
|
this->pSocket.reset();
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void SocketOverlappedOperation::UpdateTrigger(const AuSPtr<AuLoop::ILoopSource> &pTrigger)
|
|
{
|
|
this->pEvent = pTrigger;
|
|
}
|
|
|
|
bool SocketOverlappedOperation::IsValid()
|
|
{
|
|
return bool(this->pEvent);
|
|
}
|
|
|
|
void SocketOverlappedOperation::OnIOTick()
|
|
{
|
|
if (!this->bMultipleTrigger)
|
|
{
|
|
return;
|
|
}
|
|
|
|
AuLogDbg("On tick");
|
|
auto pTemp = AuExchange(this->pSocket, {});
|
|
|
|
if (this->HasFailed())
|
|
{
|
|
this->OnOverlappedFailure(this->ToError());
|
|
}
|
|
else
|
|
{
|
|
this->OnOverlappedComplete();
|
|
}
|
|
}
|
|
|
|
void SocketOverlappedOperation::OnIOComplete()
|
|
{
|
|
if (this->bMultipleTrigger)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (AuExchange(this->bHasFlipped, true))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this->HasFailed())
|
|
{
|
|
this->OnOverlappedFailure(this->ToError());
|
|
}
|
|
else
|
|
{
|
|
this->OnOverlappedComplete();
|
|
}
|
|
|
|
this->pSocket.reset();
|
|
}
|
|
|
|
void SocketOverlappedOperation::OnIOFailure()
|
|
{
|
|
if (AuExchange(this->bHasFlipped, true))
|
|
{
|
|
return;
|
|
}
|
|
|
|
this->OnOverlappedFailure(this->ToError());
|
|
this->pSocket.reset();
|
|
}
|
|
|
|
bool SocketOverlappedOperation::HasFailed()
|
|
{
|
|
return this->ToOsError() != 0;
|
|
}
|
|
|
|
AuUInt SocketOverlappedOperation::ToOsError()
|
|
{
|
|
if (this->uOsError)
|
|
{
|
|
return this->uOsError;
|
|
}
|
|
|
|
return this->uOsError;
|
|
}
|
|
|
|
bool SocketOverlappedOperation::HasComplete()
|
|
{
|
|
if (this->HasFailed())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return this->ToOsError() == 0;
|
|
}
|
|
|
|
NetError SocketOverlappedOperation::ToError()
|
|
{
|
|
NetError error;
|
|
NetError_SetOsError(error, this->ToOsError());
|
|
return error;
|
|
}
|
|
} |