Reece Wilson
267c2216b0
(...missing send) [+] AuIO::Buffer::ViewReader [+] AuIO::Buffer::ViewSeekableReadable [+] AuIO::Buffer::ViewWriter [*] Clean up AuCompression [*[ AuLog messages must always crunch for memory [*] Various bug fixes [*] Refactor+clean up
70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuProtocolPiece.cpp
|
|
Date: 2022-8-24
|
|
Author: Reece
|
|
***/
|
|
#include "Protocol.hpp"
|
|
#include "AuProtocolPiece.hpp"
|
|
#include "AuProtocolStack.hpp"
|
|
#include "IProtocolNext.hpp"
|
|
|
|
namespace Aurora::IO::Protocol
|
|
{
|
|
AuSPtr<IStreamWriter> ProtocolPiece::ToNextWriter()
|
|
{
|
|
if (this->pParent->pTopPiece.get() == this)
|
|
{
|
|
if (this->pParent->pDrainBuffer)
|
|
{
|
|
return AuMakeShared<Buffered::BlobWriter>(this->pParent->pDrainBuffer);
|
|
}
|
|
}
|
|
|
|
return this->pNext ?
|
|
this->pNext->pWriteInteface->GetStreamWriter() :
|
|
this->pOuputWriter;
|
|
}
|
|
|
|
void ProtocolPiece::Remove()
|
|
{
|
|
auto &pBottomPiece = this->pParent->pBottomPiece;
|
|
|
|
// fix chain
|
|
AuSPtr<IProtocolPiece> pLast;
|
|
auto pCurrent = pBottomPiece;
|
|
while (true)
|
|
{
|
|
if (!pCurrent)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (pCurrent.get() == this)
|
|
{
|
|
AuReinterpretCast<ProtocolPiece>(pLast)->pNext = pCurrent->pNext;
|
|
break;
|
|
}
|
|
|
|
pLast = pCurrent;
|
|
pCurrent = pCurrent->pNext;
|
|
}
|
|
|
|
// fix head pointers
|
|
if (this->pParent->pTopPiece.get() == this)
|
|
{
|
|
this->pParent->pTopPiece = AuReinterpretCast<ProtocolPiece>(pLast);
|
|
}
|
|
|
|
if (this->pParent->pBottomPiece.get() == this)
|
|
{
|
|
this->pParent->pBottomPiece = this->pNext;
|
|
}
|
|
}
|
|
|
|
AuSPtr<Memory::ByteBuffer> ProtocolPiece::GetNextPieceBuffer()
|
|
{
|
|
return AuSPtr<AuByteBuffer>(AuSharedFromThis(), &this->outputBuffer);
|
|
}
|
|
} |