diff --git a/Include/Aurora/IO/IAsyncTransaction.hpp b/Include/Aurora/IO/IAsyncTransaction.hpp index 551788c7..47d03e69 100644 --- a/Include/Aurora/IO/IAsyncTransaction.hpp +++ b/Include/Aurora/IO/IAsyncTransaction.hpp @@ -37,8 +37,8 @@ namespace Aurora::IO // Thread-Local! struct IAsyncTransaction { - virtual bool StartRead(AuUInt64 uOffset, const AuSPtr &memoryView) = 0; - virtual bool StartWrite(AuUInt64 uOffset, const AuSPtr &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 &pTransaction, AuUInt64 uOffset, - const AuSPtr &memoryView, + const Memory::MemoryViewWrite &memoryView, AuOptional> callback = {}, - AuOptional> pCompletionGroup = {}) + AuOptional> 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 &pTransaction, AuUInt64 uOffset, - const AuSPtr &memoryView, + const Memory::MemoryViewRead &memoryView, AuOptional> callback = {}, - AuOptional> pCompletionGroup = {}) + AuOptional> 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) { diff --git a/Source/IO/Adapters/AuIOAdapterAsyncDelegators.cpp b/Source/IO/Adapters/AuIOAdapterAsyncDelegators.cpp index ae219802..e2f2be44 100644 --- a/Source/IO/Adapters/AuIOAdapterAsyncDelegators.cpp +++ b/Source/IO/Adapters/AuIOAdapterAsyncDelegators.cpp @@ -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 &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 &memoryView) + bool AsyncReaderWriter::StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView) { if (!memoryView) { diff --git a/Source/IO/Adapters/AuIOAdapterAsyncDelegators.hpp b/Source/IO/Adapters/AuIOAdapterAsyncDelegators.hpp index ba3a6d5d..2c7c0634 100644 --- a/Source/IO/Adapters/AuIOAdapterAsyncDelegators.hpp +++ b/Source/IO/Adapters/AuIOAdapterAsyncDelegators.hpp @@ -20,17 +20,17 @@ namespace Aurora::IO::Adapters AuSPtr pStreamReaderEx; AuSPtr pStreamWriter; AuSPtr pStreamWriterEx; - AuSPtr pReadView; - AuSPtr pWriteView; + Memory::MemoryViewRead pReadView; + Memory::MemoryViewWrite pWriteView; AuWorkerPId workers; void DispatchFrame(ProcessInfo &info) override; void OnFailure() override; - bool StartRead(AuUInt64 uOffset, const AuSPtr &memoryView) override; + bool StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView) override; - bool StartWrite(AuUInt64 uOffset, const AuSPtr &memoryView) override; + bool StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView) override; AuUInt32 GetLastPacketLength() override; diff --git a/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp b/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp index 671c6634..f811631b 100644 --- a/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp +++ b/Source/IO/Adapters/AuIOAdapterAsyncStream.cpp @@ -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 write; - }; - - auto annoying = AuMakeShared(); - 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"); diff --git a/Source/IO/FS/Async.Linux.cpp b/Source/IO/FS/Async.Linux.cpp index ad294e96..3c8c13d7 100644 --- a/Source/IO/FS/Async.Linux.cpp +++ b/Source/IO/FS/Async.Linux.cpp @@ -298,7 +298,7 @@ namespace Aurora::IO::FS this->uBaseOffset = uBaseOffset; } - bool LinuxAsyncFileTransaction::StartRead(AuUInt64 offset, const AuSPtr &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 &memoryView) + bool LinuxAsyncFileTransaction::StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView) { if (HasState()) { diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index aad7fbde..d934c88a 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -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 &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 &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 &pCompletionGroup) diff --git a/Source/IO/FS/Async.NT.hpp b/Source/IO/FS/Async.NT.hpp index 7f778c0f..a0c888b3 100644 --- a/Source/IO/FS/Async.NT.hpp +++ b/Source/IO/FS/Async.NT.hpp @@ -42,8 +42,8 @@ namespace Aurora::IO::FS bool InitWeak(const AuSPtr &handle); void ResetAIO(); - bool StartRead(AuUInt64 offset, const AuSPtr &memoryView) override; - bool StartWrite(AuUInt64 offset, const AuSPtr &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 pNtIpcPipeImpl; - AuSPtr pMemoryHold; + AuMemoryViewRead readView; + AuMemoryViewWrite writeView; private: AuSPtr pHandle_; diff --git a/Source/IO/Net/AuNetSocketChannelOutput.cpp b/Source/IO/Net/AuNetSocketChannelOutput.cpp index 508a624f..d1891f56 100644 --- a/Source/IO/Net/AuNetSocketChannelOutput.cpp +++ b/Source/IO/Net/AuNetSocketChannelOutput.cpp @@ -101,14 +101,6 @@ namespace Aurora::IO::Net return; } - struct View : AuMemoryViewRead - { - View(const AuMemoryViewRead &in) : AuMemoryViewRead(in) - { - } - AuSPtr 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(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(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; } diff --git a/Source/IO/Net/AuNetStream.Linux.cpp b/Source/IO/Net/AuNetStream.Linux.cpp index 38e275db..aca704d4 100644 --- a/Source/IO/Net/AuNetStream.Linux.cpp +++ b/Source/IO/Net/AuNetStream.Linux.cpp @@ -28,7 +28,7 @@ namespace Aurora::IO::Net Reset(); } - bool LinuxAsyncNetworkTransaction::StartRead(AuUInt64 offset, const AuSPtr &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 &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; } } diff --git a/Source/IO/Net/AuNetStream.Linux.hpp b/Source/IO/Net/AuNetStream.Linux.hpp index 5dfea995..71745b7f 100644 --- a/Source/IO/Net/AuNetStream.Linux.hpp +++ b/Source/IO/Net/AuNetStream.Linux.hpp @@ -26,8 +26,8 @@ namespace Aurora::IO::Net LinuxAsyncNetworkTransaction(SocketBase *pSocket); ~LinuxAsyncNetworkTransaction(); - bool StartRead(AuUInt64 offset, const AuSPtr &memoryView) override; - bool StartWrite(AuUInt64 offset, const AuSPtr &memoryView) override; + bool StartRead(AuUInt64 offset, const AuMemoryViewWrite &memoryView) override; + bool StartWrite(AuUInt64 offset, const AuMemoryViewRead &memoryView) override; bool Complete() override; diff --git a/Source/IO/Net/AuNetStream.NT.cpp b/Source/IO/Net/AuNetStream.NT.cpp index 2e80cc1e..adcd8288 100644 --- a/Source/IO/Net/AuNetStream.NT.cpp +++ b/Source/IO/Net/AuNetStream.NT.cpp @@ -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 &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() + (ULONG)writeView.length, + writeView.Begin() } }; @@ -156,7 +158,7 @@ namespace Aurora::IO::Net return this->TranslateLastError(ret != -1); } - bool NtAsyncNetworkTransaction::StartWrite(AuUInt64 offset, const AuSPtr &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() + (ULONG)memoryView.length, + (CHAR *)memoryView.Begin() } }; @@ -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) { diff --git a/Source/IO/Net/AuNetStream.NT.hpp b/Source/IO/Net/AuNetStream.NT.hpp index f7057b0d..898dd5c3 100644 --- a/Source/IO/Net/AuNetStream.NT.hpp +++ b/Source/IO/Net/AuNetStream.NT.hpp @@ -24,8 +24,8 @@ namespace Aurora::IO::Net NtAsyncNetworkTransaction(SocketBase *pSocket); ~NtAsyncNetworkTransaction(); - bool StartRead(AuUInt64 offset, const AuSPtr &memoryView) override; - bool StartWrite(AuUInt64 offset, const AuSPtr &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 pMemoryHold; + AuMemoryViewRead readView; + AuMemoryViewWrite writeView; bool bDisallowRecv {}; bool bDisallowSend {}; bool bSendEOSOnce {}; diff --git a/Source/IO/Net/AuNetWriteQueue.cpp b/Source/IO/Net/AuNetWriteQueue.cpp index f9004a1b..bc0dda9d 100644 --- a/Source/IO/Net/AuNetWriteQueue.cpp +++ b/Source/IO/Net/AuNetWriteQueue.cpp @@ -10,7 +10,7 @@ namespace Aurora::IO::Net { - bool NetWriteQueue::Push(const AuSPtr &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 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() + viewOffset; + this->current_.ptr = viewShared.Begin() + viewOffset; this->current_.length = viewLength - viewOffset; - - return AuUnsafeRaiiToShared(&this->current_); + return this->current_; } bool NetWriteQueue::IsEmpty() diff --git a/Source/IO/Net/AuNetWriteQueue.hpp b/Source/IO/Net/AuNetWriteQueue.hpp index 625b2d3f..c9d5330c 100644 --- a/Source/IO/Net/AuNetWriteQueue.hpp +++ b/Source/IO/Net/AuNetWriteQueue.hpp @@ -12,14 +12,14 @@ namespace Aurora::IO::Net struct SocketBase; struct NetWriteQueue { - bool Push(const AuSPtr &read); + bool Push(const AuMemoryViewRead &read); void NotifyBytesWritten(AuUInt written); - AuSPtr Dequeue(); + AuMemoryViewRead Dequeue(); bool IsEmpty(); SocketBase *pBase {}; private: - AuList>> views_; + AuList> views_; AuMemoryViewRead current_; }; } \ No newline at end of file diff --git a/Source/IO/Net/SocketOverDatagram/AuNetDatagramSocketServerChannel.cpp b/Source/IO/Net/SocketOverDatagram/AuNetDatagramSocketServerChannel.cpp index 91309cb1..debaa3a9 100644 --- a/Source/IO/Net/SocketOverDatagram/AuNetDatagramSocketServerChannel.cpp +++ b/Source/IO/Net/SocketOverDatagram/AuNetDatagramSocketServerChannel.cpp @@ -156,10 +156,7 @@ namespace Aurora::IO::Net if (auto uDelta = uOffset - uStartOffset) { - auto pMem = AuMakeSharedPanic(); - 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); } diff --git a/Source/IO/UNIX/IOSubmit.Linux.cpp b/Source/IO/UNIX/IOSubmit.Linux.cpp index ea5588af..dd8c6985 100644 --- a/Source/IO/UNIX/IOSubmit.Linux.cpp +++ b/Source/IO/UNIX/IOSubmit.Linux.cpp @@ -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 &view) + void ASubmittable::SetMemory(const AuMemoryViewRead &view) { - this->dataPtr_ = AuReinterpretCast(view->ptr); - this->dataLen_ = view->length; - this->memPin_ = view; + this->dataPtr_ = AuReinterpretCast(view.ptr); + this->dataLen_ = view.length; + AuResetMember(this->readView); + AuResetMember(this->writeView); + this->readView = view; } - void ASubmittable::SetMemory(const AuSPtr &view) + void ASubmittable::SetMemory(const AuMemoryViewWrite &view) { - this->dataPtr_ = AuReinterpretCast(view->ptr); - this->dataLen_ = view->length; - this->memPin_ = view; + this->dataPtr_ = AuReinterpretCast(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; diff --git a/Source/Processes/AuOutputOf.cpp b/Source/Processes/AuOutputOf.cpp index 78c697bf..8fbf77b9 100644 --- a/Source/Processes/AuOutputOf.cpp +++ b/Source/Processes/AuOutputOf.cpp @@ -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)