[+] IProtocolPiece.GetNextPiece

[+] IProtocolPiece.ReallocateDrainBuffer
[*] Harden protocol piece use after destroy
This commit is contained in:
Reece Wilson 2023-04-29 07:00:29 +01:00
parent c787d85485
commit 6683d3cfdc
3 changed files with 51 additions and 0 deletions

View File

@ -11,6 +11,19 @@ namespace Aurora::IO::Protocol
{
struct IProtocolPiece
{
/**
* @brief
* @return
*/
virtual AuSPtr<IProtocolPiece> GetNextPiece() = 0;
/**
* @brief
* @param uOutputLength
* @return
*/
virtual bool ReallocateDrainBuffer(AuUInt32 uOutputLength) = 0;
/**
* @brief Removes this piece from the stack
*/

View File

@ -14,6 +14,11 @@ namespace Aurora::IO::Protocol
{
AuSPtr<IStreamWriter> ProtocolPiece::ToNextWriter()
{
if (!this->pParent)
{
return {};
}
if (this->pParent->pTopPiece.get() == this)
{
if (this->pParent->pDrainBuffer)
@ -32,8 +37,36 @@ namespace Aurora::IO::Protocol
return this->pWriteInteface ? this->pWriteInteface->GetStreamWriter() : AuSPtr<IStreamWriter> {};
}
AuSPtr<IProtocolPiece> ProtocolPiece::GetNextPiece()
{
return this->pNext;
}
bool ProtocolPiece::ReallocateDrainBuffer(AuUInt32 uOutputLength)
{
if (!this->pParent)
{
return false;
}
if (!this->pNext)
{
if (this->pParent->pDrainBuffer)
{
return false;
}
}
return this->outputBuffer.Resize(uOutputLength);
}
void ProtocolPiece::Remove()
{
if (!this->pParent)
{
return;
}
auto &pBottomPiece = this->pParent->pBottomPiece;
// fix chain
@ -66,6 +99,8 @@ namespace Aurora::IO::Protocol
{
this->pParent->pBottomPiece = this->pNext;
}
this->pParent = nullptr;
}
AuSPtr<Memory::ByteBuffer> ProtocolPiece::GetNextPieceBuffer()

View File

@ -23,6 +23,9 @@ namespace Aurora::IO::Protocol
AuSPtr<IStreamWriter> pOuputWriter;
bool bMultipleTick {};
AuSPtr<IProtocolPiece> GetNextPiece() override;
bool ReallocateDrainBuffer(AuUInt32 uOutputLength) override;
void Remove() override;
AuSPtr<IStreamWriter> ToNextWriter() override;
AuSPtr<IStreamWriter> ToInputWriter() override;