[*] Improved AuProtocolStack API

This commit is contained in:
Reece Wilson 2023-11-30 09:39:56 +00:00
parent 5c40821d6f
commit 5ec28735ed
4 changed files with 105 additions and 129 deletions

View File

@ -9,6 +9,8 @@
namespace Aurora::IO::Protocol
{
AUE_DEFINE_VA(EProtocolWhere, eAppend, ePrepend);
struct IProtocolStack :
IProtocolBaseReader,
IProtocolBaseWriter
@ -20,16 +22,9 @@ namespace Aurora::IO::Protocol
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual AuSPtr<IProtocolPiece> AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
/**
* @brief Inserts the interceptor at the bottom of the protocol stack.
* Warning: AppendInterceptorEx is preferred
* @param pInterceptor
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) = 0;
virtual AuSPtr<IProtocolPiece> AddInterceptor(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize) = 0;
/**
* @brief
@ -37,7 +32,9 @@ namespace Aurora::IO::Protocol
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual AuSPtr<IProtocolPiece> AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
virtual AuSPtr<IProtocolPiece> AddInterceptorEx(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize) = 0;
/**
* @brief defer to AppendInterceptorEx
@ -45,15 +42,10 @@ namespace Aurora::IO::Protocol
* @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
* @param uOutputBufferSize When 0, a hopefully not stupid default is used.
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) = 0;
virtual AuSPtr<IProtocolPiece> AddInterceptorDynamicBuffer(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferDefaultSize,
AuUInt uOutputBufferMaximumSize) = 0;
/**
* @brief Same as AppendInterceptor, except that DoTick will repeat until the input is fully consumed.
@ -73,14 +65,8 @@ namespace Aurora::IO::Protocol
* @param pInterceptorEx
* @return
*/
virtual AuSPtr<IProtocolPiece> AppendSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
/**
* @brief
* @param pInterceptorEx
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
virtual AuSPtr<IProtocolPiece> AddSingleFrameProcessor(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) = 0;
/**
* @brief Defer to AppendSingleFrameProcessor
@ -89,39 +75,19 @@ namespace Aurora::IO::Protocol
* @param uOutputBufferSizeMax
* @return
*/
virtual AuSPtr<IProtocolPiece> PrependSingleFrameProcessorDynamicBuffer(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferDefaultSize, AuUInt uOutputBufferMaximumSize) = 0;
virtual AuSPtr<IProtocolPiece> AddSingleFrameProcessorDynamicBuffer(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferDefaultSize,
AuUInt uOutputBufferMaximumSize) = 0;
/**
* @brief See: AppendSingleFrameProcessor
* @param pInterceptorEx
* @return
*/
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
* @param uOutputBufferSize
* @return
*/
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;
virtual AuSPtr<IProtocolPiece> AddSingleFrameProcessorEx(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize) = 0;
/**
* @brief

View File

@ -24,76 +24,84 @@ namespace Aurora::IO::Protocol
{
}
AuSPtr<IProtocolPiece> ProtocolStack::AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptor(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhere(false, pInterceptor, uOutputBufferSize);
return this->AddInterceptorWhere(eWhere,
pInterceptor,
uOutputBufferSize);
}
AuSPtr<IProtocolPiece> ProtocolStack::AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorEx(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize, false);
return this->AddInterceptorWhereEx(eWhere,
pInterceptorEx,
uOutputBufferSize,
false);
}
AuSPtr<IProtocolPiece> ProtocolStack::AppendSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx)
AuSPtr<IProtocolPiece> ProtocolStack::AddSingleFrameProcessor(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx)
{
return this->AddInterceptorWhereEx(false, pInterceptorEx, 0, true);
return this->AddInterceptorWhereEx(eWhere,
pInterceptorEx,
0,
true);
}
AuSPtr<IProtocolPiece> ProtocolStack::AppendSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
AuSPtr<IProtocolPiece> ProtocolStack::AddSingleFrameProcessorEx(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(false, pInterceptorEx, uOutputBufferSize, true);
return this->AddInterceptorWhereEx(eWhere,
pInterceptorEx,
uOutputBufferSize,
true);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx)
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorDynamicBuffer(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize,
AuUInt uOutputBufferSizeMax)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, 0, true);
return this->AddInterceptorWhereEx(eWhere,
pInterceptorEx,
uOutputBufferSize,
false,
uOutputBufferSizeMax);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
AuSPtr<IProtocolPiece> ProtocolStack::AddSingleFrameProcessorDynamicBuffer(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize,
AuUInt uOutputBufferSizeMax)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, true);
return this->AddInterceptorWhereEx(eWhere,
pInterceptorEx,
uOutputBufferSize,
true,
uOutputBufferSizeMax);
}
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)
{
return this->AddInterceptorWhere(true, pInterceptor, uOutputBufferSize);
}
AuSPtr<IProtocolPiece> ProtocolStack::PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx,
AuUInt uOutputBufferSize)
{
return this->AddInterceptorWhereEx(true, pInterceptorEx, uOutputBufferSize, false);
}
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorWhere(bool bPrepend,
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorWhere(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptor> &pInterceptor,
AuUInt uOutputBufferSize)
{
if (!EProtocolWhereIsValid(eWhere))
{
SysPushErrorArg();
return {};
}
if (!pInterceptor)
{
SysPushErrorArg();
return {};
}
AU_LOCK_GUARD(this->mutex);
if (this->bWrittenEnd)
@ -193,7 +201,7 @@ namespace Aurora::IO::Protocol
pNew->pParent = this;
pNew->pInterceptor = pInterceptor;
if (bPrepend)
if (eWhere == EProtocolWhere::ePrepend)
{
if (this->pBottomPiece)
{
@ -222,12 +230,24 @@ namespace Aurora::IO::Protocol
return pNew;
}
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorWhereEx(bool bPrepend,
AuSPtr<IProtocolPiece> ProtocolStack::AddInterceptorWhereEx(EProtocolWhere eWhere,
const AuSPtr<IProtocolInterceptorEx> &pInterceptor,
AuUInt uOutputBufferSize,
bool bMultipleTick,
AuOptional<AuUInt> uMax)
{
if (!EProtocolWhereIsValid(eWhere))
{
SysPushErrorArg();
return {};
}
if (!pInterceptor)
{
SysPushErrorArg();
return {};
}
AU_LOCK_GUARD(this->mutex);
if (this->bWrittenEnd)
@ -343,7 +363,7 @@ namespace Aurora::IO::Protocol
pNew->pParent = this;
pNew->bMultipleTick = bMultipleTick;
if (bPrepend)
if (eWhere == EProtocolWhere::ePrepend)
{
if (this->pBottomPiece)
{
@ -1052,7 +1072,7 @@ namespace Aurora::IO::Protocol
if (bSingle)
{
if (!pStack->AppendSingleFrameProcessorEx(pPointer, uNextBufferSize))
if (!pStack->AddSingleFrameProcessorEx(EProtocolWhere::eAppend, pPointer, uNextBufferSize))
{
SysPushErrorNested();
return {};
@ -1070,7 +1090,7 @@ namespace Aurora::IO::Protocol
}
else
{
if (!pStack->AppendInterceptorEx(pPointer, uNextBufferSize))
if (!pStack->AddInterceptorEx(EProtocolWhere::eAppend, pPointer, uNextBufferSize))
{
SysPushErrorNested();
return {};

View File

@ -29,29 +29,19 @@ namespace Aurora::IO::Protocol
bool TryReadMore(bool bForce = false);
AuSPtr<IProtocolPiece> AppendInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AppendInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AppendSingleFrameProcessor(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
AuSPtr<IProtocolPiece> AppendSingleFrameProcessorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> PrependInterceptor(const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> PrependInterceptorEx(const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
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> AddInterceptor(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AddInterceptorEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AddSingleFrameProcessor(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
AuSPtr<IProtocolPiece> AddSingleFrameProcessorEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
AuSPtr<IProtocolPiece> AddInterceptorDynamicBuffer(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
AuSPtr<IProtocolPiece> AddSingleFrameProcessorDynamicBuffer(EProtocolWhere eWhere, 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, AuOptional<AuUInt> uMax = {});
AuSPtr<IProtocolPiece> AddInterceptorWhere(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize);
AuSPtr<IProtocolPiece> AddInterceptorWhereEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize, bool bMultipleTick, AuOptional<AuUInt> uMax = {});
AuSPtr<IStreamWriter> AsStreamWriter() override;
AuSPtr<Memory::ByteBuffer> AsWritableByteBuffer() override;

View File

@ -170,7 +170,7 @@ namespace Aurora::IO::TLS
return false;
}
auto pPiece = this->pSendStack_->AppendInterceptorEx(this->GetSendInterceptor(), this->meta_.uOutPageSize);
auto pPiece = this->pSendStack_->AddInterceptorEx(AuIO::Protocol::EProtocolWhere::eAppend, this->GetSendInterceptor(), this->meta_.uOutPageSize);
if (!pPiece)
{
SysPushErrorNet("Couldn't add TLS interceptor");
@ -179,7 +179,7 @@ namespace Aurora::IO::TLS
this->pPiece_ = pPiece;
if (!this->pRecvStack_->AppendInterceptorEx(this->GetRecvInterceptor(), this->meta_.uOutPageSize))
if (!this->pRecvStack_->AddInterceptorEx(AuIO::Protocol::EProtocolWhere::eAppend, this->GetRecvInterceptor(), this->meta_.uOutPageSize))
{
SysPushErrorNet("Couldn't add TLS interceptor");
return false;