[+] IProtocolPiece::GetPreviousPiece()
[+] IProtocolPiece::ReallocateSourceBuffer() [*] IProtocolPiece::GetInputWriter() [*] IProtocolPiece::GetNextWriter()
This commit is contained in:
parent
9ba725973f
commit
76d3759295
@ -25,6 +25,12 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> GetNextPiece() = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IProtocolPiece> GetPreviousPiece() = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param uOutputLength
|
||||
@ -32,6 +38,13 @@ namespace Aurora::IO::Protocol
|
||||
*/
|
||||
virtual bool ReallocateDrainBuffer(AuUInt32 uOutputLength) = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @param uInputLength
|
||||
* @return
|
||||
*/
|
||||
virtual bool ReallocateSourceBuffer(AuUInt32 uInputLength) = 0;
|
||||
|
||||
/**
|
||||
* @brief Removes this piece from the stack
|
||||
*/
|
||||
@ -41,13 +54,19 @@ namespace Aurora::IO::Protocol
|
||||
* @brief
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IStreamWriter> ToInputWriter() = 0;
|
||||
virtual AuSPtr<IStreamWriter> GetInputWriter() = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IStreamReader> GetOutputReader() = 0;
|
||||
|
||||
/**
|
||||
* @brief Fetches an IStreamWriter representation of the next piece in the stack
|
||||
* @return
|
||||
*/
|
||||
virtual AuSPtr<IStreamWriter> ToNextWriter() = 0;
|
||||
virtual AuSPtr<IStreamWriter> GetNextWriter() = 0;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
@ -28,7 +28,7 @@ namespace Aurora::IO::Protocol
|
||||
}
|
||||
}
|
||||
|
||||
AuSPtr<IStreamWriter> ProtocolPiece::ToNextWriter()
|
||||
AuSPtr<IStreamWriter> ProtocolPiece::GetNextWriter()
|
||||
{
|
||||
if (!this->pParent)
|
||||
{
|
||||
@ -50,7 +50,7 @@ namespace Aurora::IO::Protocol
|
||||
this->pOuputWriter;
|
||||
}
|
||||
|
||||
AuSPtr<IStreamWriter> ProtocolPiece::ToInputWriter()
|
||||
AuSPtr<IStreamWriter> ProtocolPiece::GetInputWriter()
|
||||
{
|
||||
return this->pWriteInteface ? this->pWriteInteface->GetStreamWriter() : AuSPtr<IStreamWriter> {};
|
||||
}
|
||||
@ -60,6 +60,17 @@ namespace Aurora::IO::Protocol
|
||||
return this->pNext;
|
||||
}
|
||||
|
||||
AuSPtr<IProtocolPiece> ProtocolPiece::GetPreviousPiece()
|
||||
{
|
||||
return this->pBefore;
|
||||
}
|
||||
|
||||
AuSPtr<IStreamReader> ProtocolPiece::GetOutputReader()
|
||||
{
|
||||
// TODO: cache if required
|
||||
return IO::Adapters::NewByteBufferReadAdapter(AuSPtr<AuByteBuffer>(this->SharedFromThis(), &this->outputBuffer));
|
||||
}
|
||||
|
||||
bool ProtocolPiece::ReallocateDrainBuffer(AuUInt32 uOutputLength)
|
||||
{
|
||||
if (!this->pParent)
|
||||
@ -86,6 +97,40 @@ namespace Aurora::IO::Protocol
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool ProtocolPiece::ReallocateSourceBuffer(AuUInt32 uInputLength)
|
||||
{
|
||||
if (!this->pParent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AU_LOCK_GUARD(this->pParent->mutex);
|
||||
|
||||
if (auto pBefore = this->pBefore)
|
||||
{
|
||||
if (pBefore->outputBuffer)
|
||||
{
|
||||
pBefore->outputBuffer.flagNoRealloc = false;
|
||||
auto bRet = pBefore->outputBuffer.Resize(uInputLength);
|
||||
if (!pBefore->uMax.has_value())
|
||||
{
|
||||
pBefore->outputBuffer.flagNoRealloc = true;
|
||||
}
|
||||
return bRet;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->pParent->bOwnsSource &&
|
||||
this->pParent->pSourceBufer)
|
||||
{
|
||||
return this->pParent->pSourceBufer->Resize(uInputLength);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProtocolPiece::Remove()
|
||||
{
|
||||
this->PrivateUserDataClear();
|
||||
@ -99,7 +144,7 @@ namespace Aurora::IO::Protocol
|
||||
auto &pBottomPiece = this->pParent->pBottomPiece;
|
||||
|
||||
// fix chain
|
||||
AuSPtr<IProtocolPiece> pLast;
|
||||
AuSPtr<ProtocolPiece> pLast;
|
||||
auto pCurrent = pBottomPiece;
|
||||
while (true)
|
||||
{
|
||||
@ -110,7 +155,11 @@ namespace Aurora::IO::Protocol
|
||||
|
||||
if (pCurrent.get() == this)
|
||||
{
|
||||
AuReinterpretCast<ProtocolPiece>(pLast)->pNext = pCurrent->pNext;
|
||||
if (auto pNext = pCurrent->pNext)
|
||||
{
|
||||
pNext->pBefore = pLast;
|
||||
}
|
||||
pLast->pNext = pCurrent->pNext;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -21,18 +21,23 @@ namespace Aurora::IO::Protocol
|
||||
AuSPtr<IProtocolInterceptorEx> pInterceptorEx;
|
||||
AuSPtr<IProtocolNext> pWriteInteface;
|
||||
AuSPtr<ProtocolPiece> pNext;
|
||||
AuSPtr<ProtocolPiece> pBefore;
|
||||
AuByteBuffer outputBuffer;
|
||||
AuSPtr<IStreamWriter> pOuputWriter;
|
||||
bool bMultipleTick {};
|
||||
AuOptional<AuUInt> uMax;
|
||||
AuUInt64 uStartingSize {};
|
||||
friend struct ProtocolStack; // IProtocolPiece::PrivateUserDataClear()
|
||||
|
||||
AuSPtr<ProtocolStack> GetParent() override;
|
||||
AuSPtr<IProtocolPiece> GetNextPiece() override;
|
||||
AuSPtr<IProtocolPiece> GetPreviousPiece() override;
|
||||
bool ReallocateDrainBuffer(AuUInt32 uOutputLength) override;
|
||||
bool ReallocateSourceBuffer(AuUInt32 uInputLength) override;
|
||||
void Remove() override;
|
||||
AuSPtr<IStreamWriter> ToNextWriter() override;
|
||||
AuSPtr<IStreamWriter> ToInputWriter() override;
|
||||
AuSPtr<IStreamWriter> GetNextWriter() override;
|
||||
AuSPtr<IStreamWriter> GetInputWriter() override;
|
||||
AuSPtr<IStreamReader> GetOutputReader() override;
|
||||
AuSPtr<Memory::ByteBuffer> GetNextPieceBuffer() override;
|
||||
AuSPtr<IProtocolInterceptorEx> GetExtendedInterceptor() override;
|
||||
AuSPtr<IProtocolInterceptor> GetShortPipeInterceptor() override;
|
||||
|
@ -203,9 +203,10 @@ namespace Aurora::IO::Protocol
|
||||
|
||||
if (eWhere == EProtocolWhere::ePrepend)
|
||||
{
|
||||
if (this->pBottomPiece)
|
||||
if (auto pBottomPiece = this->pBottomPiece)
|
||||
{
|
||||
pNew->pNext = this->pBottomPiece;
|
||||
pBottomPiece->pBefore = pNew;
|
||||
pNew->pNext = pBottomPiece;
|
||||
}
|
||||
|
||||
this->pBottomPiece = pNew;
|
||||
@ -214,6 +215,7 @@ namespace Aurora::IO::Protocol
|
||||
{
|
||||
if (this->pTopPiece)
|
||||
{
|
||||
pNew->pBefore = this->pTopPiece;
|
||||
this->pTopPiece->pNext = pNew;
|
||||
}
|
||||
|
||||
@ -365,9 +367,10 @@ namespace Aurora::IO::Protocol
|
||||
|
||||
if (eWhere == EProtocolWhere::ePrepend)
|
||||
{
|
||||
if (this->pBottomPiece)
|
||||
if (auto pBottomPiece = this->pBottomPiece)
|
||||
{
|
||||
pNew->pNext = this->pBottomPiece;
|
||||
pBottomPiece->pBefore = pNew;
|
||||
pNew->pNext = pBottomPiece;
|
||||
}
|
||||
|
||||
this->pBottomPiece = pNew;
|
||||
@ -376,6 +379,7 @@ namespace Aurora::IO::Protocol
|
||||
{
|
||||
if (this->pTopPiece)
|
||||
{
|
||||
pNew->pBefore = this->pTopPiece;
|
||||
this->pTopPiece->pNext = pNew;
|
||||
}
|
||||
|
||||
@ -483,6 +487,7 @@ namespace Aurora::IO::Protocol
|
||||
|
||||
if (this->pTopPiece)
|
||||
{
|
||||
pNew->pBefore = this->pTopPiece;
|
||||
this->pTopPiece->pNext = pNew;
|
||||
}
|
||||
|
||||
@ -518,10 +523,12 @@ namespace Aurora::IO::Protocol
|
||||
auto pCur = pItr;
|
||||
pItr = pCur->pNext;
|
||||
pCur->pNext.reset();
|
||||
pCur->pBefore.reset();
|
||||
pCur->pInterceptor.reset();
|
||||
pCur->pInterceptorEx.reset();
|
||||
pCur->pOuputWriter.reset();
|
||||
pCur->pWriteInteface.reset();
|
||||
pCur->PrivateUserDataClear();
|
||||
}
|
||||
|
||||
this->pBottomPiece.reset();
|
||||
@ -815,7 +822,7 @@ namespace Aurora::IO::Protocol
|
||||
pBase = pRead->readPtr;
|
||||
}
|
||||
|
||||
auto pNextStream = pCurrent->ToNextWriter();
|
||||
auto pNextStream = pCurrent->GetNextWriter();
|
||||
|
||||
if (!pCurrent->pInterceptor->OnDataAvailable({ pBase, uCount }, pNextStream))
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ namespace Aurora::IO::TLS
|
||||
{
|
||||
AuUInt count {};
|
||||
if (Aurora::IO::EStreamError::eErrorNone !=
|
||||
pPiece->ToNextWriter()->Write(AuMemoryViewStreamRead { AuMemoryViewRead { pIn, length }, count }))
|
||||
pPiece->GetNextWriter()->Write(AuMemoryViewStreamRead { AuMemoryViewRead { pIn, length }, count }))
|
||||
{
|
||||
SysPushErrorIO("TLS couldn't flush write into next protocol layer or drain");
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user