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

View File

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

View File

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

View File

@ -170,7 +170,7 @@ namespace Aurora::IO::TLS
return false; 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) if (!pPiece)
{ {
SysPushErrorNet("Couldn't add TLS interceptor"); SysPushErrorNet("Couldn't add TLS interceptor");
@ -179,7 +179,7 @@ namespace Aurora::IO::TLS
this->pPiece_ = pPiece; 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"); SysPushErrorNet("Couldn't add TLS interceptor");
return false; return false;