[*] Minor net fixes

[*] Fix async shutdown / inline shutdown condition
[*] Fix multiple net triggers
[*] Fix spurious UDP Session Socket timeouts
This commit is contained in:
Reece Wilson 2024-10-19 17:47:05 +01:00
parent a2322470b8
commit 1fb36548ea
12 changed files with 71 additions and 12 deletions

View File

@ -314,7 +314,7 @@ namespace Aurora::IO::Net
}
else
{
if (!this->socketChannel_.outputChannel.AsWritableByteBuffer()->RemainingBytes())
if (this->socketChannel_.outputChannel.CanShutdown())
{
this->Shutdown(true);
}

View File

@ -282,7 +282,7 @@ namespace Aurora::IO::Net
}
else
{
if (!this->socketChannel_.outputChannel.AsWritableByteBuffer()->RemainingBytes())
if (this->socketChannel_.outputChannel.CanShutdown())
{
this->Shutdown(true);
}

View File

@ -318,6 +318,8 @@ namespace Aurora::IO::Net
return;
}
this->connectOperation.ReleaseWatcher();
auto pDriver = this->pSocketDriver_;
if (bool(pDriver))
{
@ -635,6 +637,7 @@ namespace Aurora::IO::Net
return;
}
this->connectOperation.ReleaseWatcher();
this->socketChannel_.StopTime();
this->pWorker_->RemoveSocket(this);

View File

@ -263,6 +263,11 @@ namespace Aurora::IO::Net
return this->outputWriteQueue_.IsEmpty() && AuAtomicLoad(&this->uCompleteCounter_) == 0;
}
bool SocketChannelOutput::CanShutdown()
{
return this->CanResize() && !this->AsWritableByteBuffer()->RemainingBytes();
}
void SocketChannelOutput::OnAsyncFileOpFinished(AuUInt64 offset, AuUInt32 length)
{
AuAtomicSub(&this->outputBuffer_.uInUseCounter, 1u);

View File

@ -37,6 +37,7 @@ namespace Aurora::IO::Net
AuByteBuffer &GetByteBuffer();
bool CanResize();
bool CanShutdown();
private:
friend struct SocketBase;

View File

@ -49,9 +49,24 @@ namespace Aurora::IO::Net
if (dwErrorCode == ERROR_IO_PENDING)
{
this->pSocket = that;
SysAssert(pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
if (auto pOld = AuTryLockMemoryType(this->wpThat))
{
return true;
}
else
{
auto pThat = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
AuSPtr<AuIO::IIOSimpleEventListener>(that, this),
true));
!this->bMultipleTrigger);
if (!pThat)
{
return false;
}
this->wpThat = pThat;
return true;
}
return true;
}
else
@ -64,6 +79,16 @@ namespace Aurora::IO::Net
}
}
void SocketOverlappedOperation::ReleaseWatcher()
{
if (auto pOld = AuTryLockMemoryType(this->wpThat))
{
pOld->StopWatch();
}
AuResetMember(this->wpThat);
}
bool SocketOverlappedOperation::IsValid()
{
return bool(this->pEvent);

View File

@ -49,7 +49,10 @@ namespace Aurora::IO::Net
bool IsValid();
void ReleaseWatcher();
private:
bool bHasFlipped {};
AuWPtr<IIOProcessorItem> wpThat;
};
}

View File

@ -68,24 +68,41 @@ namespace Aurora::IO::Net
bool SocketOverlappedOperation::BeginOperation(const AuSPtr<void> &that,
const AuSPtr<INetWorker> &pWorker)
{
this->pSocket = that;
if (!this->pEvent)
{
return false;
}
auto bStatus = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
this->pSocket = that;
if (auto pOld = AuTryLockMemoryType(this->wpThat))
{
return true;
}
auto pThat = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
AuSPtr<AuIO::IIOSimpleEventListener>(that, this),
true);
if (!bStatus)
!this->bMultipleTrigger);
if (!pThat)
{
this->pSocket.reset();
return false;
}
this->wpThat = pThat;
return true;
}
void SocketOverlappedOperation::ReleaseWatcher()
{
if (auto pOld = AuTryLockMemoryType(this->wpThat))
{
pOld->StopWatch();
}
AuResetMember(this->wpThat);
}
void SocketOverlappedOperation::UpdateTrigger(const AuSPtr<AuLoop::ILoopSource> &pTrigger)
{
this->pEvent = pTrigger;

View File

@ -53,8 +53,10 @@ namespace Aurora::IO::Net
bool IsValid();
void ReleaseWatcher();
private:
bool bHasFlipped {};
AuWPtr<IIOProcessorItem> wpThat;
};
}

View File

@ -136,5 +136,6 @@ namespace Aurora::IO::Net
void SocketServerImpl::DetroyServer()
{
this->acceptOperation_.ReleaseWatcher();
}
}

View File

@ -14,6 +14,7 @@ namespace Aurora::IO::Net
{
this->Start();
this->calculator.AddData(uBytes);
this->uLastTimeSteadyMS = AuTime::SteadyClockMS();
}
AuInt64 SocketStats::GetFirstTickTimeMS()

View File

@ -32,8 +32,9 @@ namespace Aurora::IO::Net
{
auto uLastRecv = pSession->channel.GetRecvStatsEx().uLastTimeSteadyMS;
auto uLastSend = pSession->channel.GetSendStatsEx().uLastTimeSteadyMS;
if ((uSocketTimeoutRecvMS && (uLastRecv + uSocketTimeoutRecvMS < uNow)) ||
(uSocketTimeoutAnyMS && ((uLastRecv + uSocketTimeoutAnyMS < uNow) || (uLastSend + uSocketTimeoutAnyMS < uNow))))
if ((uSocketTimeoutRecvMS && (uLastRecv && (uLastRecv + uSocketTimeoutRecvMS < uNow))) ||
(uSocketTimeoutAnyMS && ((uLastRecv && (uLastRecv + uSocketTimeoutAnyMS < uNow)) ||
(uLastSend && (uLastSend + uSocketTimeoutAnyMS < uNow)))))
{
abortions[pSession->pWorker].push_back(pSession);
}