[+] IProtocolStack::AppendInterceptorDynamicBuffer
[+] IProtocolStack::PrependInterceptorDynamicBuffer [+] IProtocolStack::PrependSingleFrameProcessorDynamicBuffer [+] IProtocolStack::AppendSingleFrameProcessorDynamicBuffer [+] IProtocolStack::IsValid [+] IProtocolPiece::ExchangeMaximumBufferLength
This commit is contained in:
parent
5c29787f9c
commit
48c2175be9
@ -68,6 +68,8 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolInterceptor> GetShortPipeInterceptor() = 0;
|
||||
|
||||
virtual AuOptional<AuUInt> ExchangeMaximumBufferLength(AuOptional<AuUInt> optMax) = 0;
|
||||
|
||||
AURT_ADD_USR_DATA;
|
||||
};
|
||||
}
|
@ -9,7 +9,9 @@
|
||||
|
||||
namespace Aurora::IO::Protocol
|
||||
{
|
||||
struct IProtocolStack : IProtocolBaseReader, IProtocolBaseWriter
|
||||
struct IProtocolStack :
|
||||
IProtocolBaseReader,
|
||||
IProtocolBaseWriter
|
||||
{
|
||||
/**
|
||||
* @brief
|
||||
@ -37,6 +39,14 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief defer to AppendInterceptorEx
|
||||
* @param pInterceptorEx
|
||||
* @param uOutputBufferSize
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> AppendInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferDefaultSize, AuUInt uOutputBufferMaximumSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief Inserts the interceptor at the bottom of the protocol stack
|
||||
* @param pInterceptorEx
|
||||
@ -72,6 +82,15 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
|
||||
|
||||
/**
|
||||
* @brief Defer to AppendSingleFrameProcessor
|
||||
* @param pInterceptorEx
|
||||
* @param uOutputBufferSize
|
||||
* @param uOutputBufferSizeMax
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferDefaultSize, AuUInt uOutputBufferMaximumSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief See: AppendSingleFrameProcessor
|
||||
* @param pInterceptorEx
|
||||
@ -79,6 +98,15 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> AppendSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param pInterceptorEx
|
||||
* @param uOutputBufferSize
|
||||
* @param uOutputBufferSizeMax
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> AppendSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferDefaultSize, AuUInt uOutputBufferMaximumSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param pInterceptorEx
|
||||
@ -87,6 +115,14 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief defer to PrependSingleFrameProcessorEx
|
||||
* @param pInterceptorEx
|
||||
* @param uOutputBufferSize
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> PrependInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferDefaultSize, AuUInt uOutputBufferMaximumSize) = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param pInterceptor
|
||||
@ -119,6 +155,8 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> GetInterceptorAtIndex(AuUInt32 uIndex) = 0;
|
||||
|
||||
virtual bool IsValid() = 0;
|
||||
|
||||
AURT_ADD_USR_DATA;
|
||||
};
|
||||
|
||||
|
@ -145,4 +145,19 @@ namespace Aurora::IO::Protocol
|
||||
{
|
||||
return this->pInterceptor;
|
||||
}
|
||||
|
||||
AuOptional<AuUInt> ProtocolPiece::ExchangeMaximumBufferLength(AuOptional<AuUInt> optMax)
|
||||
{
|
||||
if (!optMax)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!this->uMax)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return AuExchange(this->uMax, optMax);
|
||||
}
|
||||
}
|
@ -12,7 +12,9 @@ namespace Aurora::IO::Protocol
|
||||
struct IProtocolNext;
|
||||
struct ProtocolStack;
|
||||
|
||||
struct ProtocolPiece : IProtocolPiece, AuEnableSharedFromThis<ProtocolPiece>
|
||||
struct ProtocolPiece :
|
||||
IProtocolPiece,
|
||||
AuEnableSharedFromThis<ProtocolPiece>
|
||||
{
|
||||
ProtocolStack *pParent;
|
||||
AuSPtr<IProtocolInterceptor> pInterceptor;
|
||||
@ -22,7 +24,8 @@ namespace Aurora::IO::Protocol
|
||||
AuByteBuffer outputBuffer;
|
||||
AuSPtr<IStreamWriter> pOuputWriter;
|
||||
bool bMultipleTick {};
|
||||
|
||||
AuOptional<AuUInt> uMax;
|
||||
AuUInt64 uStartingSize {};
|
||||
|
||||
AuSPtr<ProtocolStack> GetParent() override;
|
||||
AuSPtr<IProtocolPiece> GetNextPiece() override;
|
||||
@ -33,5 +36,6 @@ namespace Aurora::IO::Protocol
|
||||
AuSPtr<Memory::ByteBuffer> GetNextPieceBuffer() override;
|
||||
AuSPtr<IProtocolInterceptorEx> GetExtendedInterceptor() override;
|
||||
AuSPtr<IProtocolInterceptor> GetShortPipeInterceptor() override;
|
||||
AuOptional<AuUInt> ExchangeMaximumBufferLength(AuOptional<AuUInt> optMax) override;
|
||||
};
|
||||
}
|
@ -58,6 +58,26 @@ namespace Aurora::IO::Protocol
|
||||
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, true);
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::AppendInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax)
|
||||
{
|
||||
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize, false, uOutputBufferSizeMax);
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::PrependInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax)
|
||||
{
|
||||
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, false, uOutputBufferSizeMax);
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::PrependSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax)
|
||||
{
|
||||
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, true, uOutputBufferSizeMax);
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::AppendSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax)
|
||||
{
|
||||
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize, true, uOutputBufferSizeMax);
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
|
||||
AuUInt uOutputBufferSize)
|
||||
{
|
||||
@ -195,7 +215,8 @@ namespace Aurora::IO::Protocol
|
||||
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorWhereEx(bool bPrepend,
|
||||
const AuSPtr<IProtocolInterceptorEx> &pInterceptor,
|
||||
AuUInt uOutputBufferSize,
|
||||
bool bMultipleTick)
|
||||
bool bMultipleTick,
|
||||
AuOptional<AuUInt> uMax)
|
||||
{
|
||||
AU_LOCK_GUARD(this->mutex);
|
||||
|
||||
@ -228,6 +249,14 @@ namespace Aurora::IO::Protocol
|
||||
return {};
|
||||
}
|
||||
|
||||
if (uMax)
|
||||
{
|
||||
pNew->uMax = uMax;
|
||||
pNew->outputBuffer.flagAlwaysExpandable = pNew->outputBuffer.flagExpandable = 1;
|
||||
}
|
||||
|
||||
pNew->uStartingSize = uOutputBufferSize;
|
||||
|
||||
// Circular ref
|
||||
pNew->pOuputWriter = AuMakeShared<AuIO::Buffered::BlobWriter>(AuSPtr<Memory::ByteBuffer>(pNew, &pNew->outputBuffer));
|
||||
|
||||
@ -635,7 +664,10 @@ namespace Aurora::IO::Protocol
|
||||
}
|
||||
}
|
||||
|
||||
if (!pCurrent->pInterceptorEx->OnDataAvailable(pRead, pNextStream, pCurrent))
|
||||
bool bStatus = pCurrent->pInterceptorEx->OnDataAvailable(pRead, pNextStream, pCurrent);
|
||||
|
||||
|
||||
if (!bStatus)
|
||||
{
|
||||
if (pNextStream)
|
||||
{
|
||||
@ -644,6 +676,37 @@ namespace Aurora::IO::Protocol
|
||||
|
||||
return bTryAgainAtleastOnce;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pCurrent->uMax.has_value())
|
||||
{
|
||||
auto bytesRem = pCurrent->outputBuffer.RemainingBytes();
|
||||
auto maxVal = pCurrent->uMax.value();
|
||||
if (bytesRem >= maxVal)
|
||||
{
|
||||
this->Terminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
auto target = AuMin(AuPageRound<AuUInt>(bytesRem + ((bytesRem / 4) * 3), 128), maxVal);
|
||||
target = AuMax(target, pCurrent->uStartingSize);
|
||||
|
||||
if (target >= pCurrent->outputBuffer.allocSize ||
|
||||
((pCurrent->outputBuffer.length > target) && (bytesRem < pCurrent->uStartingSize)))
|
||||
{
|
||||
AuByteBuffer replacement(target, true, false);
|
||||
if (!replacement.WriteFrom(pCurrent->outputBuffer))
|
||||
{
|
||||
this->Terminate();
|
||||
return false;
|
||||
}
|
||||
|
||||
pCurrent->outputBuffer = AuMove(replacement);
|
||||
pCurrent->outputBuffer.flagAlwaysExpandable =
|
||||
pCurrent->outputBuffer.flagExpandable = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pNextStream)
|
||||
{
|
||||
@ -743,6 +806,11 @@ namespace Aurora::IO::Protocol
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ProtocolStack::IsValid()
|
||||
{
|
||||
return !this->bDead;
|
||||
}
|
||||
|
||||
void ProtocolStack::DiscardAllocCaches()
|
||||
{
|
||||
AuResetMember(this->pStreamReaderCache);
|
||||
|
@ -39,12 +39,19 @@ namespace Aurora::IO::Protocol
|
||||
AuSPtr<IProtocolPiece> PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
|
||||
AuSPtr<IProtocolPiece> PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
|
||||
|
||||
|
||||
AuSPtr<IProtocolPiece> AppendInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
||||
AuSPtr<IProtocolPiece> PrependInterceptorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
||||
|
||||
AuSPtr<IProtocolPiece> PrependSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
||||
AuSPtr<IProtocolPiece> AppendSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
||||
|
||||
AuSPtr<IProtocolPiece> AddEndInterceptor(const AuSPtr<IProtocolInterceptorEx> &pInterceptor) override;
|
||||
|
||||
void Destroy() override;
|
||||
|
||||
AuSPtr<IProtocolPiece> AddInterceptorWhere(bool bPrepend, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize);
|
||||
AuSPtr<IProtocolPiece> AddInterceptorWhereEx(bool bPrepend, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize, bool bMultipleTick);
|
||||
AuSPtr<IProtocolPiece> AddInterceptorWhereEx(bool bPrepend, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize, bool bMultipleTick, AuOptional<AuUInt> uMax = {});
|
||||
|
||||
AuSPtr<IStreamWriter> AsStreamWriter() override;
|
||||
AuSPtr<Memory::ByteBuffer> AsWritableByteBuffer() override;
|
||||
@ -55,6 +62,8 @@ namespace Aurora::IO::Protocol
|
||||
AuList<AuSPtr<IProtocolPiece>> GetArrayOfInterceptors() override;
|
||||
AuSPtr<IProtocolPiece> GetInterceptorAtIndex(AuUInt32 uIndex) override;
|
||||
|
||||
bool IsValid() override;
|
||||
|
||||
EProtocolStackCreateType eType;
|
||||
bool bDead {};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user