From 592afe00a718ba2b05f44fe2ca028abe32584473 Mon Sep 17 00:00:00 2001 From: J Reece Wilson Date: Mon, 1 Jul 2024 11:54:18 +0100 Subject: [PATCH] [*] AuNet: Missing Linux TODO block; harden two callbacks missing a try/catch --- Source/IO/Net/AuNetSocket.cpp | 15 +++++++++++++-- Source/IO/Net/AuNetSocketChannel.cpp | 5 +++++ Source/IO/Net/AuNetSocketChannelInput.cpp | 1 - .../Net/AuNetSocketOverlappedOperation.Unix.cpp | 5 +++++ Source/IO/Net/AuNetStream.Linux.cpp | 17 ++++++++++++++++- Source/IO/Net/AuNetStream.NT.cpp | 9 ++++++++- 6 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Source/IO/Net/AuNetSocket.cpp b/Source/IO/Net/AuNetSocket.cpp index 03bbf63d..7626aa48 100644 --- a/Source/IO/Net/AuNetSocket.cpp +++ b/Source/IO/Net/AuNetSocket.cpp @@ -18,6 +18,8 @@ #if defined(AURORA_IS_MODERNNT_DERIVED) #include "AuNetStream.NT.hpp" +#else + #include "AuNetStream.Linux.hpp" #endif namespace Aurora::IO::Net @@ -694,9 +696,18 @@ namespace Aurora::IO::Net this->socketChannel_.outputChannel.pParent_ = nullptr; #else - // TODO: - #endif + if (this->socketChannel_.inputChannel.pNetReadTransaction) + { + AuStaticCast(this->socketChannel_.inputChannel.pNetReadTransaction)->pSocket = nullptr; + } + this->socketChannel_.inputChannel.pNetReadTransaction.reset(); + + if (pWriteTransaction) + { + AuStaticCast(pWriteTransaction)->pSocket = nullptr; + } + #endif this->CloseSocket(); } diff --git a/Source/IO/Net/AuNetSocketChannel.cpp b/Source/IO/Net/AuNetSocketChannel.cpp index 3133cacd..9747f331 100644 --- a/Source/IO/Net/AuNetSocketChannel.cpp +++ b/Source/IO/Net/AuNetSocketChannel.cpp @@ -585,6 +585,11 @@ namespace Aurora::IO::Net { this->StopTime(); + if (this->inputChannel.pNetReader) + { + this->inputChannel.pNetReader->End(); + } + this->PrivateUserDataClear(); this->pCachedReader.reset(); diff --git a/Source/IO/Net/AuNetSocketChannelInput.cpp b/Source/IO/Net/AuNetSocketChannelInput.cpp index e4c4f242..b01b866b 100644 --- a/Source/IO/Net/AuNetSocketChannelInput.cpp +++ b/Source/IO/Net/AuNetSocketChannelInput.cpp @@ -79,7 +79,6 @@ namespace Aurora::IO::Net void SocketChannelInput::WarmOnEstablish() { auto sharedThis = AuSPtr(this->pParent_->SharedFromThis(), this); - AuIO::IOPipeRequestAIO req; req.output.handleBufferedStream.pOnData = AuUnsafeRaiiToShared(this); req.output.type = EPipeCallbackType::eTryHandleBufferedPart; diff --git a/Source/IO/Net/AuNetSocketOverlappedOperation.Unix.cpp b/Source/IO/Net/AuNetSocketOverlappedOperation.Unix.cpp index a00a2af8..510dbd0b 100644 --- a/Source/IO/Net/AuNetSocketOverlappedOperation.Unix.cpp +++ b/Source/IO/Net/AuNetSocketOverlappedOperation.Unix.cpp @@ -69,6 +69,11 @@ namespace Aurora::IO::Net const AuSPtr &pWorker) { this->pSocket = that; + if (!this->pEvent) + { + return false; + } + auto bStatus = pWorker->ToProcessor()->StartSimpleLSWatchEx(this->pEvent, AuSPtr(that, this), true); diff --git a/Source/IO/Net/AuNetStream.Linux.cpp b/Source/IO/Net/AuNetStream.Linux.cpp index 65bb56df..3a412839 100644 --- a/Source/IO/Net/AuNetStream.Linux.cpp +++ b/Source/IO/Net/AuNetStream.Linux.cpp @@ -380,7 +380,22 @@ namespace Aurora::IO::Net if (this->pSub) { - this->pSub->OnAsyncFileOpFinished(this->dwLastAbstractOffset, read); + try + { + this->pSub->OnAsyncFileOpFinished(this->dwLastAbstractOffset, read); + } + catch (...) + { + SysPushErrorCatch(); + } + } + + if (!read) + { + if (this->pSocket) + { + this->pSocket->SendEnd(); + } } } diff --git a/Source/IO/Net/AuNetStream.NT.cpp b/Source/IO/Net/AuNetStream.NT.cpp index de721f3a..2e80cc1e 100644 --- a/Source/IO/Net/AuNetStream.NT.cpp +++ b/Source/IO/Net/AuNetStream.NT.cpp @@ -551,7 +551,14 @@ namespace Aurora::IO::Net if (this->pSub) { - this->pSub->OnAsyncFileOpFinished(this->dwLastAbstractOffset, read); + try + { + this->pSub->OnAsyncFileOpFinished(this->dwLastAbstractOffset, read); + } + catch (...) + { + SysPushErrorCatch(); + } } }