2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
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);
|
|
|
|
|
2022-08-31 18:49:35 +00:00
|
|
|
SysAssertDbg(viewOffset + written <= AuGet<1>(viewZero)->length);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
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_);
|
|
|
|
}
|
2022-12-12 23:50:05 +00:00
|
|
|
|
|
|
|
bool NetWriteQueue::IsEmpty()
|
|
|
|
{
|
|
|
|
return this->views_.empty();
|
|
|
|
}
|
2022-08-28 19:02:06 +00:00
|
|
|
}
|