AuroraRuntime/Source/IO/Protocol/AuProtocolStackSpecialWriter.cpp

66 lines
1.5 KiB
C++
Raw Normal View History

/***
Copyright (C) 2022-2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuProtocolStackSpecialWriter.cpp
File: AuProtocolStack.cpp
Date: 2022-8-24
Date: 2023-09-21
Author: Reece
***/
#include "Protocol.hpp"
#include "AuProtocolStack.hpp"
#include "AuProtocolStackSpecialWriter.hpp"
namespace Aurora::IO::Protocol
{
SpecialWriter::SpecialWriter(ProtocolStack *pParent) :
pParent(pParent)
{ }
EStreamError SpecialWriter::IsOpen()
{
auto pStack = this->pParent;
if (pStack->bDead)
{
return EStreamError::eErrorHandleClosed;
}
if (!pStack->pSourceBufer)
{
return EStreamError::eErrorStreamNotOpen;
}
return EStreamError::eErrorNone;
}
EStreamError SpecialWriter::Write(const Memory::MemoryViewStreamRead &parameters)
{
2023-12-28 16:49:11 +00:00
parameters.outVariable = 0;
auto pStack = this->pParent;
if (pStack->bDead)
{
return EStreamError::eErrorHandleClosed;
}
auto pStackBuffer = pStack->pSourceBufer; //pStack->AsWritableByteBuffer();
if (!pStackBuffer)
{
return EStreamError::eErrorStreamNotOpen;
}
parameters.outVariable = pStackBuffer->Write(parameters.ptr, parameters.length);
return EStreamError::eErrorNone;
}
void SpecialWriter::Close()
{
this->pParent->Terminate();
}
void SpecialWriter::Flush()
{
this->pParent->DoTick();
}
}