AuroraRuntime/Source/IO/Net/AuNetWriteQueue.cpp
Reece Wilson 267c2216b0 [+] UDP over socket API via existing INetSrvDatagram layer
(...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
2022-12-12 23:50:05 +00:00

59 lines
1.5 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetWriteQueue.cpp
Date: 2022-8-21
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuNetWriteQueue.hpp"
namespace Aurora::IO::Net
{
bool NetWriteQueue::Push(const AuSPtr<AuMemoryViewRead> &read)
{
return AuTryInsert(this->views_, AuMakeTuple(0, read));
}
void NetWriteQueue::NotifyBytesWritten(AuUInt written)
{
SysAssert(this->views_.size());
SysAssert(written);
auto &viewZero = this->views_[0];
auto &viewLength = AuGet<1>(viewZero)->length;
auto &viewOffset = AuGet<0>(viewZero);
SysAssertDbg(viewOffset + written <= AuGet<1>(viewZero)->length);
viewOffset += written;
if (viewOffset == viewLength)
{
this->views_.erase(this->views_.begin());
}
}
AuSPtr<AuMemoryViewRead> NetWriteQueue::Dequeue()
{
if (this->views_.empty())
{
return {};
}
auto &viewZero = this->views_[0];
auto &viewShared = AuGet<1>(viewZero);
auto &viewLength = viewShared->length;
auto &viewOffset = AuGet<0>(viewZero);
this->current_.ptr = viewShared->Begin<AuUInt8>() + viewOffset;
this->current_.length = viewLength - viewOffset;
return AuUnsafeRaiiToShared(&this->current_);
}
bool NetWriteQueue::IsEmpty()
{
return this->views_.empty();
}
}