From cdf5a499cb1d7952bb2cc5050ca441e6435aa4b7 Mon Sep 17 00:00:00 2001 From: Reece Date: Tue, 25 Apr 2023 12:13:16 +0100 Subject: [PATCH] [*] Improved pipe work awareness under protocol stack to allow for propagation of error conditions such that the top most interceptor can kill the pipe work --- Include/Aurora/IO/Protocol/IProtocolStack.hpp | 5 +++-- Source/IO/Protocol/AuProtocolStack.cpp | 22 ++++++++++++++----- Source/IO/Protocol/AuProtocolStack.hpp | 6 ++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Include/Aurora/IO/Protocol/IProtocolStack.hpp b/Include/Aurora/IO/Protocol/IProtocolStack.hpp index db9e1b15..d4b38d0b 100644 --- a/Include/Aurora/IO/Protocol/IProtocolStack.hpp +++ b/Include/Aurora/IO/Protocol/IProtocolStack.hpp @@ -80,8 +80,9 @@ namespace Aurora::IO::Protocol /** * @brief Sends one tick down the protocol stack, regardless of how much data is written into the * next piece/interceptor, and regardless of if another read tick is required. + * @return The error state of the top-most interceptor */ - virtual void DoTick() = 0; + virtual bool DoTick() = 0; /** * @brief @@ -101,5 +102,5 @@ namespace Aurora::IO::Protocol * @param pWork * @return */ - AUKN_SYM AuSPtr NewProtocolStackFromPipe(const AuSPtr &pWork, bool bAutoTick = true); + AUKN_SYM AuSPtr NewProtocolStackFromPipe(const AuSPtr &pWork, bool bAutoTick = true, bool bKillPipeOnFirstRootLevelFalse = true); } \ No newline at end of file diff --git a/Source/IO/Protocol/AuProtocolStack.cpp b/Source/IO/Protocol/AuProtocolStack.cpp index 7e52dc6f..d4186331 100644 --- a/Source/IO/Protocol/AuProtocolStack.cpp +++ b/Source/IO/Protocol/AuProtocolStack.cpp @@ -441,19 +441,29 @@ namespace Aurora::IO::Protocol return AuSPtr(this->pTopPiece, &this->pTopPiece->outputBuffer); } - void ProtocolStack::DoTick() + bool ProtocolStack::DoTick() { if (!this->pSourceBufer) { - return; + return false; } if (!this->pBottomPiece) { - return; + return false; } - this->DoTick(this->pSourceBufer, {}); + if (!this->DoTick(this->pSourceBufer, {})) + { + if (auto pStack = AuTryLockMemoryType(this->pPipeWork)) + { + pStack->TerminateOnThread(true); + } + + return false; + } + + return true; } bool ProtocolStack::DoTick(const AuSPtr &pRead, const AuSPtr &pPiece) @@ -585,7 +595,7 @@ namespace Aurora::IO::Protocol return pStack; } - AUKN_SYM AuSPtr NewProtocolStackFromPipe(const AuSPtr &pWork, bool bAutoTick) + AUKN_SYM AuSPtr NewProtocolStackFromPipe(const AuSPtr &pWork, bool bAutoTick, bool bKillPipeOnFirstRootLevelFalse) { if (!pWork) { @@ -602,6 +612,8 @@ namespace Aurora::IO::Protocol auto pWorkEx = AuStaticCast(pWork); + pStack->pPipeWork = pWorkEx; + if (bAutoTick) { if (pWorkEx->pProtocolStack) diff --git a/Source/IO/Protocol/AuProtocolStack.hpp b/Source/IO/Protocol/AuProtocolStack.hpp index 14cce095..96153ca7 100644 --- a/Source/IO/Protocol/AuProtocolStack.hpp +++ b/Source/IO/Protocol/AuProtocolStack.hpp @@ -7,6 +7,8 @@ ***/ #pragma once +#include "../AuIOPipeProcessor.hpp" + namespace Aurora::IO::Protocol { struct ProtocolPiece; @@ -15,7 +17,7 @@ namespace Aurora::IO::Protocol { ~ProtocolStack(); - void DoTick() override; + bool DoTick() override; bool DoTick(const AuSPtr &read, const AuSPtr &pPiece); AuSPtr AppendInterceptor(const AuSPtr &pInterceptor, AuUInt uOutputBufferSize) override; @@ -46,5 +48,7 @@ namespace Aurora::IO::Protocol AuSPtr pTopPiece; bool bWrittenEnd {}; + + AuWPtr pPipeWork; }; } \ No newline at end of file