[*] 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 else
{ {
if (!this->socketChannel_.outputChannel.AsWritableByteBuffer()->RemainingBytes()) if (this->socketChannel_.outputChannel.CanShutdown())
{ {
this->Shutdown(true); this->Shutdown(true);
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -49,9 +49,24 @@ namespace Aurora::IO::Net
if (dwErrorCode == ERROR_IO_PENDING) if (dwErrorCode == ERROR_IO_PENDING)
{ {
this->pSocket = that; this->pSocket = that;
SysAssert(pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
AuSPtr<AuIO::IIOSimpleEventListener>(that, this), if (auto pOld = AuTryLockMemoryType(this->wpThat))
true)); {
return true;
}
else
{
auto pThat = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent,
AuSPtr<AuIO::IIOSimpleEventListener>(that, this),
!this->bMultipleTrigger);
if (!pThat)
{
return false;
}
this->wpThat = pThat;
return true;
}
return true; return true;
} }
else 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() bool SocketOverlappedOperation::IsValid()
{ {
return bool(this->pEvent); return bool(this->pEvent);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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