AuroraRuntime/Source/IO/Protocol/AuProtocolStackSpecialWriter.cpp
Jamie Reece Wilson 994fcb5010 [*/+] Added/Moved code to AuProtocolStackSpecialWriter[.cpp]
[+] Further mutex guarantees under protocol stacks (hardening)
2023-09-21 21:18:59 +01:00

64 lines
1.5 KiB
C++

/***
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)
{
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();
}
}