[*] AuSPtr<AuMemoryViewXXXX> is now an anti-pattern. After 3 fucking years, memory views of shared control blocks and atomic in use counters are properly utilized everywhere. We do not need generic superclasses to be safe anymore

This commit is contained in:
Reece Wilson 2024-07-12 20:22:48 +01:00
parent d803f1547c
commit af5c8e86c0
17 changed files with 134 additions and 144 deletions

View File

@ -37,8 +37,8 @@ namespace Aurora::IO
// Thread-Local!
struct IAsyncTransaction
{
virtual bool StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) = 0;
virtual bool StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &memoryView) = 0;
virtual bool StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView) = 0;
virtual bool StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView) = 0;
/**
* @brief "Non-blocking" is-signaled and call any callback routines (similar to nt alertable sleeps of a period zero)
@ -127,20 +127,16 @@ namespace Aurora::IO
inline bool ReadAsync(const AuSPtr<IAsyncTransaction> &pTransaction,
AuUInt64 uOffset,
const AuSPtr<Memory::MemoryViewWrite> &memoryView,
const Memory::MemoryViewWrite &memoryView,
AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {},
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = {})
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = { Aurora::Async::GetSelfIOGroup() })
{
SysCheckArgNotNull(pTransaction, false);
if (pCompletionGroup)
if (pCompletionGroup && pCompletionGroup.Value())
{
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
}
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback)
{
@ -156,20 +152,16 @@ namespace Aurora::IO
inline bool WriteAsync(const AuSPtr<IAsyncTransaction> &pTransaction,
AuUInt64 uOffset,
const AuSPtr<Memory::MemoryViewRead> &memoryView,
const Memory::MemoryViewRead &memoryView,
AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {},
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = {})
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = { Aurora::Async::GetSelfIOGroup() })
{
SysCheckArgNotNull(pTransaction, false);
if (pCompletionGroup)
if (pCompletionGroup && pCompletionGroup.Value())
{
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
}
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback)
{

View File

@ -24,22 +24,22 @@ namespace Aurora::IO::Adapters
{
if (this->pStreamWriter)
{
this->eStreamError = this->pStreamWriter->Write(AuMemoryViewStreamRead(*this->pReadView, this->uLastLength));
this->eStreamError = this->pStreamWriter->Write(AuMemoryViewStreamRead(this->pReadView, this->uLastLength));
}
else if (this->pStreamWriterEx)
{
this->eStreamError = this->pStreamWriterEx->ArbitraryWrite(this->iBaseOffset + this->uLastOffset, AuMemoryViewStreamRead(*this->pReadView, this->uLastLength));
this->eStreamError = this->pStreamWriterEx->ArbitraryWrite(this->iBaseOffset + this->uLastOffset, AuMemoryViewStreamRead(this->pReadView, this->uLastLength));
}
}
else if (this->pWriteView)
{
if (this->pStreamReader)
{
this->eStreamError = this->pStreamReader->Read(AuMemoryViewStreamWrite(*this->pWriteView, this->uLastLength));
this->eStreamError = this->pStreamReader->Read(AuMemoryViewStreamWrite(this->pWriteView, this->uLastLength));
}
else if (this->pStreamReaderEx)
{
this->eStreamError = this->pStreamReaderEx->ArbitraryRead(this->iBaseOffset + this->uLastOffset, AuMemoryViewStreamWrite(*this->pWriteView, this->uLastLength));
this->eStreamError = this->pStreamReaderEx->ArbitraryRead(this->iBaseOffset + this->uLastOffset, AuMemoryViewStreamWrite(this->pWriteView, this->uLastLength));
}
}
}
@ -58,7 +58,7 @@ namespace Aurora::IO::Adapters
this->Reset();
}
bool AsyncReaderWriter::StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView)
bool AsyncReaderWriter::StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView)
{
if (!memoryView)
{
@ -91,7 +91,7 @@ namespace Aurora::IO::Adapters
return pThat->Dispatch();
}
bool AsyncReaderWriter::StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &memoryView)
bool AsyncReaderWriter::StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView)
{
if (!memoryView)
{

View File

@ -20,17 +20,17 @@ namespace Aurora::IO::Adapters
AuSPtr<ISeekingReader> pStreamReaderEx;
AuSPtr<IStreamWriter> pStreamWriter;
AuSPtr<ISeekingWriter> pStreamWriterEx;
AuSPtr<Memory::MemoryViewRead> pReadView;
AuSPtr<Memory::MemoryViewWrite> pWriteView;
Memory::MemoryViewRead pReadView;
Memory::MemoryViewWrite pWriteView;
AuWorkerPId workers;
void DispatchFrame(ProcessInfo &info) override;
void OnFailure() override;
bool StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) override;
bool StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView) override;
bool StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &memoryView) override;
bool StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView) override;
AuUInt32 GetLastPacketLength() override;

View File

@ -267,7 +267,9 @@ namespace Aurora::IO::Adapters
(void)parent->transaction->TryAttachToCompletionGroup(this->parent->pCompletionGroup);
}
if (!parent->transaction->StartRead(parent->bIsStream ? 0 : parent->readOffset, parent->lastAllocation))
auto buffer = parent->lastAllocation;
if (!parent->transaction->StartRead(parent->bIsStream ? 0 : parent->writeOffset, AuMemoryViewWrite { AuMemoryViewWrite { buffer->ptr, buffer->length }, buffer }))
{
parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio read");
@ -436,8 +438,10 @@ namespace Aurora::IO::Adapters
{
(void)parent->transaction->TryAttachToCompletionGroup(this->parent->pCompletionGroup);
}
auto pBuffer = parent->lastAllocation;
if (!parent->transaction->StartRead(parent->bIsStream ? 0 : parent->readOffset, parent->lastAllocation))
if (!parent->transaction->StartRead(parent->bIsStream ? 0 : parent->readOffset, AuMemoryViewWrite { AuMemoryViewWrite { pBuffer->ptr, pBuffer->length }, pBuffer }))
{
parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio read");
@ -599,26 +603,10 @@ namespace Aurora::IO::Adapters
parent->transaction->Reset();
parent->bAsyncActive = true;
struct WriteMem : AuMemoryViewRead
{
AuSPtr<AsyncStreamMemory> write;
};
auto annoying = AuMakeShared<WriteMem>();
if (!annoying)
{
SysPushErrorMem();
return;
}
annoying->write = buffer;
annoying->ptr = buffer->ptr;
annoying->length = buffer->length;
parent->lastAllocation = buffer;
parent->lastAllocation->streamIndex = 0;
if (!parent->transaction->StartWrite(parent->bIsStream ? 0 : parent->writeOffset, annoying))
if (!parent->transaction->StartWrite(parent->bIsStream ? 0 : parent->writeOffset, AuMemoryViewRead { AuMemoryViewRead { buffer->ptr, buffer->length }, buffer }))
{
parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio write");

View File

@ -298,7 +298,7 @@ namespace Aurora::IO::FS
this->uBaseOffset = uBaseOffset;
}
bool LinuxAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView)
bool LinuxAsyncFileTransaction::StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView)
{
if (HasState())
{
@ -384,7 +384,7 @@ namespace Aurora::IO::FS
}
}
bool LinuxAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView)
bool LinuxAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView)
{
if (HasState())
{

View File

@ -267,7 +267,8 @@ namespace Aurora::IO::FS
pipe->OnEndOfReadStream();
}
that->pMemoryHold.reset();
AuResetMember(that->readView);
AuResetMember(that->writeView);
that->pPin.reset();
return true;
}
@ -306,7 +307,8 @@ namespace Aurora::IO::FS
}
SetEvent(lpOverlapped->hEvent);
auto pStupid = AuExchange(hold->pMemoryHold, {});
auto pStupid1 = AuExchange(hold->readView, {});
auto pStupid2 = AuExchange(hold->writeView, {});
hold->CompleteEx(dwNumberOfBytesTransfered, true);
}
@ -329,7 +331,7 @@ namespace Aurora::IO::FS
return true;
}
bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView)
bool NtAsyncFileTransaction::StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView)
{
if (this->isIrredeemable_)
{
@ -348,7 +350,8 @@ namespace Aurora::IO::FS
return {};
}
if (this->pMemoryHold)
if (this->readView ||
this->writeView)
{
SysPushErrorIO("IO Operation in progress");
return {};
@ -371,10 +374,10 @@ namespace Aurora::IO::FS
::ResetEvent(this->event);
}
this->pMemoryHold = memoryView;
this->writeView = memoryView;
this->bHasFailed = false;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->qwLastAbstractOffset = offset;
this->dwLastBytes = 0;
@ -385,11 +388,11 @@ namespace Aurora::IO::FS
this->overlap.Offset = AuBitsToLower(offset);
this->overlap.OffsetHigh = AuBitsToHigher(offset);
auto ret = ::ReadFileEx((HANDLE)optRead.value(), memoryView->ptr, memoryView->length, &this->overlap, FileOperationCompletion);
auto ret = ::ReadFileEx((HANDLE)optRead.value(), memoryView.ptr, memoryView.length, &this->overlap, FileOperationCompletion);
return TranslateNtStatus(this, ret);
}
bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView)
bool NtAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView)
{
if (this->isIrredeemable_)
{
@ -408,7 +411,8 @@ namespace Aurora::IO::FS
return {};
}
if (this->pMemoryHold)
if (this->readView ||
this->writeView)
{
SysPushErrorIO("IO Operation in progress");
return {};
@ -432,9 +436,9 @@ namespace Aurora::IO::FS
this->bHasFailed = false;
this->pMemoryHold = memoryView;
this->readView = memoryView;
this->dwLastBytes = 0;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->qwLastAbstractOffset = offset;
this->ResetAIO();
@ -443,7 +447,7 @@ namespace Aurora::IO::FS
this->overlap.Offset = AuBitsToLower(offset);
this->overlap.OffsetHigh = AuBitsToHigher(offset);
auto ret = ::WriteFileEx((HANDLE)optWrite.value(), memoryView->ptr, memoryView->length, &this->overlap, FileOperationCompletion);
auto ret = ::WriteFileEx((HANDLE)optWrite.value(), memoryView.ptr, memoryView.length, &this->overlap, FileOperationCompletion);
return TranslateNtStatus(this, ret);
}
@ -501,7 +505,8 @@ namespace Aurora::IO::FS
this->dwLastBytes = 0;
this->dwLastAbstractStat = 0;
AuResetMember(this->pMemoryHold);
AuResetMember(this->readView);
AuResetMember(this->writeView);
}
bool NtAsyncFileTransaction::TryAttachToCompletionGroup(const AuSPtr<CompletionGroup::ICompletionGroup> &pCompletionGroup)

View File

@ -42,8 +42,8 @@ namespace Aurora::IO::FS
bool InitWeak(const AuSPtr<IIOHandle> &handle);
void ResetAIO();
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView) override;
bool isIrredeemable_ {};
@ -92,7 +92,8 @@ namespace Aurora::IO::FS
AuUInt64 uBaseOffset {};
AuWPtr<Aurora::IO::IPC::IPCPipeImpl> pNtIpcPipeImpl;
AuSPtr<void> pMemoryHold;
AuMemoryViewRead readView;
AuMemoryViewWrite writeView;
private:
AuSPtr<IIOHandle> pHandle_;

View File

@ -101,14 +101,6 @@ namespace Aurora::IO::Net
return;
}
struct View : AuMemoryViewRead
{
View(const AuMemoryViewRead &in) : AuMemoryViewRead(in)
{
}
AuSPtr<void> pin;
};
while (this->pOutSendPointer_ != this->outputBuffer_.writePtr)
{
if (this->pOutSendPointer_ == this->outputBuffer_.writePtr)
@ -116,6 +108,7 @@ namespace Aurora::IO::Net
break;
}
// TODO: replace legacy code with circular buffer safe utils?
if (this->pOutSendPointer_ == this->outputBuffer_.base + this->outputBuffer_.length)
{
this->pOutSendPointer_ = this->outputBuffer_.base;
@ -133,13 +126,11 @@ namespace Aurora::IO::Net
auto pBase = (AuUInt8 *)this->pOutSendPointer_;
auto uLen = (AuUInt8 *)this->outputBuffer_.base + this->outputBuffer_.length - pBase;
auto pView = AuMakeSharedPanic<View>(AuMemoryViewRead(pBase, uLen));
SysAssert(pView);
pView->pin = this->pParent_->SharedFromThis();
this->outputWriteQueue_.Push(pView);
auto mem = AuMemoryViewRead { AuMemoryViewRead { pBase, (AuUInt)uLen }, this->pParent_->SharedFromThis() };
this->pOutSendPointer_ = (AuUInt8 *)this->pOutSendPointer_ + uLen;
this->outputWriteQueue_.Push(mem);
}
else
{
@ -147,12 +138,10 @@ namespace Aurora::IO::Net
auto pWriteHead = (AuUInt8 *)this->outputBuffer_.writePtr;
auto uLen = pWriteHead - pBase;
auto pView = AuMakeSharedPanic<View>(AuMemoryViewRead(pBase, uLen));
SysAssert(pView);
pView->pin = this->pParent_->SharedFromThis();
auto mem = AuMemoryViewRead { AuMemoryViewRead { pBase, (AuUInt)uLen }, this->pParent_->SharedFromThis() };
this->outputWriteQueue_.Push(pView);
this->pOutSendPointer_ = pWriteHead ;
this->pOutSendPointer_ = pWriteHead;
this->outputWriteQueue_.Push(mem);
}
}
}
@ -229,7 +218,7 @@ namespace Aurora::IO::Net
if (!this->pNetWriteTransaction_->StartWrite(0, pFrameToSend))
{
this->pParent_->ToWorkerEx()->DecrementIOEventTaskCounter();
SysPushErrorIO("Couldn't dispatch the to-send frame, had: {} bytes remaining to send", pFrameToSend->length);
SysPushErrorIO("Couldn't dispatch the to-send frame, had: {} bytes remaining to send", pFrameToSend.length);
this->pParent_->SendErrorBeginShutdown({});
return false;
}

View File

@ -28,7 +28,7 @@ namespace Aurora::IO::Net
Reset();
}
bool LinuxAsyncNetworkTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView)
bool LinuxAsyncNetworkTransaction::StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView)
{
if (this->bDisallowRecv)
{
@ -64,7 +64,7 @@ namespace Aurora::IO::Net
//this->pMemoryHold = memoryView;
this->bHasFailed = false;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->dwLastAbstractOffset = offset;
this->dwLastBytes = 0;
@ -98,7 +98,7 @@ namespace Aurora::IO::Net
}
}
bool LinuxAsyncNetworkTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView)
bool LinuxAsyncNetworkTransaction::StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView)
{
if (this->bDisallowSend)
{
@ -134,7 +134,7 @@ namespace Aurora::IO::Net
//this->pMemoryHold = memoryView;
this->bHasFailed = false;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->dwLastAbstractOffset = offset;
this->dwLastBytes = 0;
@ -168,25 +168,25 @@ namespace Aurora::IO::Net
#if 0
AuLogDbg("{} -> {} {}, {}, {} {}", this->GetSocket(),
memoryView->ptr,
memoryView->length,
memoryView.ptr,
memoryView.length,
0,
(void *)netEndpoint.hint,
this->iSocketLength);
#endif
if (::sendto(this->GetSocket(),
memoryView->ptr,
memoryView->length,
memoryView.ptr,
memoryView.length,
0,
(struct sockaddr *)netEndpoint.hint,
EndpointToLength(netEndpoint)) != memoryView->length)
EndpointToLength(netEndpoint)) != memoryView.length)
{
LIOS_SendProcess(0, false, errno);
return true;
}
LIOS_SendProcess(memoryView->length, true, errno);
LIOS_SendProcess(memoryView.length, true, errno);
return true;
}
}

View File

@ -26,8 +26,8 @@ namespace Aurora::IO::Net
LinuxAsyncNetworkTransaction(SocketBase *pSocket);
~LinuxAsyncNetworkTransaction();
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView) override;
bool Complete() override;

View File

@ -48,11 +48,12 @@ namespace Aurora::IO::Net
}
SetEvent(lpOverlapped->hEvent);
auto pHold = AuExchange(hold->pMemoryHold, {});
auto pHold1 = AuExchange(hold->readView, {});
auto pHold2 = AuExchange(hold->writeView, {});
hold->CompleteEx(cbTransferred, true);
}
bool NtAsyncNetworkTransaction::StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView)
bool NtAsyncNetworkTransaction::StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView)
{
if (this->bDisallowRecv)
{
@ -87,7 +88,8 @@ namespace Aurora::IO::Net
return {};
}
if (this->pMemoryHold)
if (this->readView ||
this->writeView)
{
SysPushErrorIO("IO Operation in progress");
return {};
@ -95,10 +97,10 @@ namespace Aurora::IO::Net
this->bLatch = false;
this->pMemoryHold = memoryView;
this->writeView = memoryView;
this->bHasFailed = false;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->dwLastAbstractOffset = offset;
this->dwLastBytes = 0;
@ -109,8 +111,8 @@ namespace Aurora::IO::Net
WSABUF bufferArray[] {
{
(ULONG)memoryView->length,
memoryView->Begin<CHAR>()
(ULONG)writeView.length,
writeView.Begin<CHAR>()
}
};
@ -156,7 +158,7 @@ namespace Aurora::IO::Net
return this->TranslateLastError(ret != -1);
}
bool NtAsyncNetworkTransaction::StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView)
bool NtAsyncNetworkTransaction::StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView)
{
if (this->bDisallowSend)
{
@ -191,7 +193,8 @@ namespace Aurora::IO::Net
return {};
}
if (this->pMemoryHold)
if (this->readView ||
this->writeView)
{
SysPushErrorIO("IO Operation in progress");
return {};
@ -199,10 +202,10 @@ namespace Aurora::IO::Net
this->bLatch = false;
this->pMemoryHold = memoryView;
this->readView = memoryView;
this->bHasFailed = false;
this->dwLastAbstractStat = memoryView->length;
this->dwLastAbstractStat = memoryView.length;
this->dwLastAbstractOffset = offset;
this->dwLastBytes = 0;
@ -213,8 +216,8 @@ namespace Aurora::IO::Net
WSABUF bufferArray[] {
{
(ULONG)memoryView->length,
(CHAR *)memoryView->Begin<CHAR>()
(ULONG)memoryView.length,
(CHAR *)memoryView.Begin<CHAR>()
}
};
@ -295,7 +298,9 @@ namespace Aurora::IO::Net
this->pSocket->SendEnd();
}
this->pMemoryHold.reset();
AuResetMember(this->readView);
AuResetMember(this->writeView);
this->pPin.reset();
return true;
}
@ -367,7 +372,8 @@ namespace Aurora::IO::Net
return true;
}
if (!this->pMemoryHold)
if (!this->readView &&
!this->writeView)
{
if (bForce)
{

View File

@ -24,8 +24,8 @@ namespace Aurora::IO::Net
NtAsyncNetworkTransaction(SocketBase *pSocket);
~NtAsyncNetworkTransaction();
bool StartRead(AuUInt64 offset, const AuSPtr<AuMemoryViewWrite> &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuSPtr<AuMemoryViewRead> &memoryView) override;
bool StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView) override;
bool StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView) override;
bool CompleteEx(AuUInt completeRoutine, bool bForce = false);
@ -81,7 +81,8 @@ namespace Aurora::IO::Net
AuUInt32 dwRecvFlags {};
AuUInt32 dwSendFlags {};
bool bHasFailed {};
AuSPtr<void> pMemoryHold;
AuMemoryViewRead readView;
AuMemoryViewWrite writeView;
bool bDisallowRecv {};
bool bDisallowSend {};
bool bSendEOSOnce {};

View File

@ -10,7 +10,7 @@
namespace Aurora::IO::Net
{
bool NetWriteQueue::Push(const AuSPtr<AuMemoryViewRead> &read)
bool NetWriteQueue::Push(const AuMemoryViewRead &read)
{
return AuTryInsert(this->views_, AuMakeTuple(0, read));
}
@ -21,10 +21,10 @@ namespace Aurora::IO::Net
SysAssert(written);
auto &viewZero = this->views_[0];
auto &viewLength = AuGet<1>(viewZero)->length;
auto &viewLength = AuGet<1>(viewZero).length;
auto &viewOffset = AuGet<0>(viewZero);
SysAssertDbg(viewOffset + written <= AuGet<1>(viewZero)->length);
SysAssertDbg(viewOffset + written <= AuGet<1>(viewZero).length);
viewOffset += written;
@ -34,7 +34,7 @@ namespace Aurora::IO::Net
}
}
AuSPtr<AuMemoryViewRead> NetWriteQueue::Dequeue()
AuMemoryViewRead NetWriteQueue::Dequeue()
{
if (this->views_.empty())
{
@ -43,13 +43,12 @@ namespace Aurora::IO::Net
auto &viewZero = this->views_[0];
auto &viewShared = AuGet<1>(viewZero);
auto &viewLength = viewShared->length;
auto &viewLength = viewShared.length;
auto &viewOffset = AuGet<0>(viewZero);
this->current_.ptr = viewShared->Begin<AuUInt8>() + viewOffset;
this->current_.ptr = viewShared.Begin<AuUInt8>() + viewOffset;
this->current_.length = viewLength - viewOffset;
return AuUnsafeRaiiToShared(&this->current_);
return this->current_;
}
bool NetWriteQueue::IsEmpty()

View File

@ -12,14 +12,14 @@ namespace Aurora::IO::Net
struct SocketBase;
struct NetWriteQueue
{
bool Push(const AuSPtr<AuMemoryViewRead> &read);
bool Push(const AuMemoryViewRead &read);
void NotifyBytesWritten(AuUInt written);
AuSPtr<AuMemoryViewRead> Dequeue();
AuMemoryViewRead Dequeue();
bool IsEmpty();
SocketBase *pBase {};
private:
AuList<AuTuple<AuUInt, AuSPtr<AuMemoryViewRead>>> views_;
AuList<AuTuple<AuUInt, AuMemoryViewRead>> views_;
AuMemoryViewRead current_;
};
}

View File

@ -156,10 +156,7 @@ namespace Aurora::IO::Net
if (auto uDelta = uOffset - uStartOffset)
{
auto pMem = AuMakeSharedPanic<DatagramMemory>();
pMem->pHold = this->pParent_->SharedFromThis();
pMem->ptr = this->outputBuffer.readPtr;
pMem->length = uDelta;
auto mem = AuMemoryViewRead { AuMemoryViewRead { this->outputBuffer.readPtr, uDelta }, this->pParent_->SharedFromThis() };
this->sendStats_.AddBytes(uDelta);
if (auto pParent = AuTryLockMemoryType(this->pParent_->pParentServer))
@ -177,7 +174,7 @@ namespace Aurora::IO::Net
this->OnComplete();
}));
if (pWriteTransaction->StartWrite(0, pMem))
if (pWriteTransaction->StartWrite(0, mem))
{
AuAtomicAdd(&this->uFence_, 1u);
}

View File

@ -52,6 +52,9 @@ namespace Aurora::IO::UNIX
pinSelf = this->pin_;
pinMem = this->memPin_;
auto cp1 = context->readView;
auto cp2 = context->writeView;
if (AuExchange(this->bIsReadPending, false))
{
// Psyche - it was just the poll half of a blocking read
@ -106,20 +109,26 @@ namespace Aurora::IO::UNIX
{
this->pin_.reset();
this->memPin_.reset();
AuResetMember(this->readView);
AuResetMember(this->writeView);
}
void ASubmittable::SetMemory(const AuSPtr<AuMemoryViewRead> &view)
void ASubmittable::SetMemory(const AuMemoryViewRead &view)
{
this->dataPtr_ = AuReinterpretCast<AuUInt64>(view->ptr);
this->dataLen_ = view->length;
this->memPin_ = view;
this->dataPtr_ = AuReinterpretCast<AuUInt64>(view.ptr);
this->dataLen_ = view.length;
AuResetMember(this->readView);
AuResetMember(this->writeView);
this->readView = view;
}
void ASubmittable::SetMemory(const AuSPtr<AuMemoryViewWrite> &view)
void ASubmittable::SetMemory(const AuMemoryViewWrite &view)
{
this->dataPtr_ = AuReinterpretCast<AuUInt64>(view->ptr);
this->dataLen_ = view->length;
this->memPin_ = view;
this->dataPtr_ = AuReinterpretCast<AuUInt64>(view.ptr);
this->dataLen_ = view.length;
AuResetMember(this->readView);
AuResetMember(this->writeView);
this->writeView = view;
}
bool ASubmittable::HasState()
@ -393,6 +402,9 @@ namespace Aurora::IO::UNIX
pinSelf = context->pin_;
pinMem = context->memPin_;
auto cp1 = context->readView;
auto cp2 = context->writeView;
if (!pinSelf)
{
return true;

View File

@ -113,7 +113,7 @@ namespace Aurora::Processes
if (length)
{
result.strStdout += AuString(stdOutPipe.begin(), stdOutPipe.begin() + length);
pTransactionA->StartRead(0, AuUnsafeRaiiToShared(&readOutView));
pTransactionA->StartRead(0, readOutView);
}
}));
@ -124,17 +124,17 @@ namespace Aurora::Processes
if (length)
{
result.strStderr += AuString(stdErrPipe.begin(), stdErrPipe.begin() + length);
pTransactionB->StartRead(0, AuUnsafeRaiiToShared(&readErrView));
pTransactionB->StartRead(0, readErrView);
}
}));
if (!pTransactionA->StartRead(0, AuUnsafeRaiiToShared(&readOutView)))
if (!pTransactionA->StartRead(0, readOutView))
{
result.bFailed = true;
return result;
}
if (!pTransactionB->StartRead(0, AuUnsafeRaiiToShared(&readErrView)))
if (!pTransactionB->StartRead(0, readErrView))
{
result.bFailed = true;
pTransactionA->SetCallback({});
@ -620,7 +620,7 @@ namespace Aurora::Processes
(void)pTransactionA->TryAttachToCompletionGroup(pResult->pCompletionGroup);
if (!pTransactionA->StartRead(0, AuUnsafeRaiiToShared(&pResult->readOutView)))
if (!pTransactionA->StartRead(0, pResult->readOutView))
{
pResult->Finalize();
}
@ -649,7 +649,7 @@ namespace Aurora::Processes
(void)pTransactionB->TryAttachToCompletionGroup(pResult->pCompletionGroup);
if (!pTransactionB->StartRead(0, AuUnsafeRaiiToShared(&pResult->readErrView)))
if (!pTransactionB->StartRead(0, pResult->readErrView))
{
pResult->Finalize();
}
@ -660,13 +660,13 @@ namespace Aurora::Processes
}
}));
if (!pResult->pTransactionA->StartRead(0, AuUnsafeRaiiToShared(&pResult->readOutView)))
if (!pResult->pTransactionA->StartRead(0, pResult->readOutView))
{
pResult->result.bFailed = true;
return pResult;
}
if (!pResult->pTransactionB->StartRead(0, AuUnsafeRaiiToShared(&pResult->readErrView)))
if (!pResult->pTransactionB->StartRead(0, pResult->readErrView))
{
pResult->result.bFailed = true;
if (pResult->pTransactionA)