From 4a584ce73ae026b24b8b6347c7a0bd372ed23c64 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Sat, 10 Jun 2023 20:33:19 +0100 Subject: [PATCH] [+] Future proof IProtocolInterceptorEx with an optional `pParent` in the only Aurora Interface methods last argument --- .../IO/Protocol/IProtocolInterceptorEx.hpp | 17 ++++++++++++++++- Source/Compression/AuCompressionInterceptor.cpp | 3 ++- Source/Compression/AuCompressionInterceptor.hpp | 3 ++- Source/IO/Protocol/AuProtocolStack.cpp | 2 +- Source/IO/TLS/TLSProtocolRecv.cpp | 3 ++- Source/IO/TLS/TLSProtocolRecv.hpp | 3 ++- Source/IO/TLS/TLSProtocolSend.cpp | 3 ++- Source/IO/TLS/TLSProtocolSend.hpp | 3 ++- 8 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Include/Aurora/IO/Protocol/IProtocolInterceptorEx.hpp b/Include/Aurora/IO/Protocol/IProtocolInterceptorEx.hpp index 3634584e..c19ea97b 100644 --- a/Include/Aurora/IO/Protocol/IProtocolInterceptorEx.hpp +++ b/Include/Aurora/IO/Protocol/IProtocolInterceptorEx.hpp @@ -9,14 +9,29 @@ namespace Aurora::IO::Protocol { + struct IProtocolPiece; + AUKN_INTERFACE(IProtocolInterceptorEx, /** * @brief + * + * @param pReadInByteBuffer a buffer to read from. returning false returns the readPtr of this buffer. + * @param pWriteOutByteBuffer a buffer to write into. you should return false if that buffer begins to fail. + * @param pProtocolStack A pointer that might be used to store user contexts. might be null. \ + * This is only provided for convenience to users outside of Aurora Runtime. \ + * + * * @return false restores the read head of pReadInByteBuffer. future callbacks will still be made. * true nothing; pReadInByteBuffer's heads will remain set by the user and the tick is propagated down the stack. + * * @warning the error flags of both bytebuffers can seize up the protocol stack by design. + * + * @warning: Some interfaces permit arbitrary users to call OnDataAvailable. + * In fact, all Aurora Runtime (compress, TLS, etc) implementers should support out of protocol-stack support. + * This is an important detail to note: **pProtocolStack might be null** */ AUI_METHOD(bool, OnDataAvailable, (const AuSPtr &, pReadInByteBuffer, - const AuSPtr &, pWriteOutByteBuffer)) + const AuSPtr &, pWriteOutByteBuffer, + const AuSPtr&, pProtocolPiece)) ); } \ No newline at end of file diff --git a/Source/Compression/AuCompressionInterceptor.cpp b/Source/Compression/AuCompressionInterceptor.cpp index 465efac8..ecea1ac4 100644 --- a/Source/Compression/AuCompressionInterceptor.cpp +++ b/Source/Compression/AuCompressionInterceptor.cpp @@ -53,7 +53,8 @@ namespace Aurora::Compression } bool CompressionInterceptor::OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) { this->pLastBuffer_ = pReadInByteBuffer; this->pBaseStream_->SetWeakBuffer(pReadInByteBuffer); diff --git a/Source/Compression/AuCompressionInterceptor.hpp b/Source/Compression/AuCompressionInterceptor.hpp index 28b47ae9..ba41681f 100644 --- a/Source/Compression/AuCompressionInterceptor.hpp +++ b/Source/Compression/AuCompressionInterceptor.hpp @@ -19,7 +19,8 @@ namespace Aurora::Compression const AuSPtr &pBaseStream); bool OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) override; + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) override; inline virtual IO::EStreamError IsOpen() override; diff --git a/Source/IO/Protocol/AuProtocolStack.cpp b/Source/IO/Protocol/AuProtocolStack.cpp index 5046cb0d..4ee7b9fb 100644 --- a/Source/IO/Protocol/AuProtocolStack.cpp +++ b/Source/IO/Protocol/AuProtocolStack.cpp @@ -597,7 +597,7 @@ namespace Aurora::IO::Protocol } } - if (!pCurrent->pInterceptorEx->OnDataAvailable(pRead, pNextStream)) + if (!pCurrent->pInterceptorEx->OnDataAvailable(pRead, pNextStream, pCurrent)) { if (pNextStream) { diff --git a/Source/IO/TLS/TLSProtocolRecv.cpp b/Source/IO/TLS/TLSProtocolRecv.cpp index f97a97f8..1baccdb7 100644 --- a/Source/IO/TLS/TLSProtocolRecv.cpp +++ b/Source/IO/TLS/TLSProtocolRecv.cpp @@ -16,7 +16,8 @@ namespace Aurora::IO::TLS } bool TLSProtocolRecv::OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) { this->bHasRead = false; this->pReadInByteBuffer = pReadInByteBuffer; diff --git a/Source/IO/TLS/TLSProtocolRecv.hpp b/Source/IO/TLS/TLSProtocolRecv.hpp index 9d6eafed..df48921f 100644 --- a/Source/IO/TLS/TLSProtocolRecv.hpp +++ b/Source/IO/TLS/TLSProtocolRecv.hpp @@ -16,7 +16,8 @@ namespace Aurora::IO::TLS TLSProtocolRecv(TLSContext *pParent); virtual bool OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) override; + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) override; bool TryHandshake(); diff --git a/Source/IO/TLS/TLSProtocolSend.cpp b/Source/IO/TLS/TLSProtocolSend.cpp index 0e7cbb5b..8146eb07 100644 --- a/Source/IO/TLS/TLSProtocolSend.cpp +++ b/Source/IO/TLS/TLSProtocolSend.cpp @@ -16,7 +16,8 @@ namespace Aurora::IO::TLS } bool TLSProtocolSend::OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) { if (!this->pParent_->bIsAlive) { diff --git a/Source/IO/TLS/TLSProtocolSend.hpp b/Source/IO/TLS/TLSProtocolSend.hpp index a5ab1628..5026821d 100644 --- a/Source/IO/TLS/TLSProtocolSend.hpp +++ b/Source/IO/TLS/TLSProtocolSend.hpp @@ -16,7 +16,8 @@ namespace Aurora::IO::TLS TLSProtocolSend(TLSContext *pParent); virtual bool OnDataAvailable(const AuSPtr &pReadInByteBuffer, - const AuSPtr &pWriteOutByteBuffer) override; + const AuSPtr &pWriteOutByteBuffer, + const AuSPtr &pProtocolPiece) override; private: