[*] 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! // Thread-Local!
struct IAsyncTransaction struct IAsyncTransaction
{ {
virtual bool StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) = 0; virtual bool StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView) = 0;
virtual bool StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &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) * @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, inline bool ReadAsync(const AuSPtr<IAsyncTransaction> &pTransaction,
AuUInt64 uOffset, AuUInt64 uOffset,
const AuSPtr<Memory::MemoryViewWrite> &memoryView, const Memory::MemoryViewWrite &memoryView,
AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {}, AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {},
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = {}) AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = { Aurora::Async::GetSelfIOGroup() })
{ {
SysCheckArgNotNull(pTransaction, false); SysCheckArgNotNull(pTransaction, false);
if (pCompletionGroup) if (pCompletionGroup && pCompletionGroup.Value())
{ {
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
} }
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback) if (callback)
{ {
@ -156,20 +152,16 @@ namespace Aurora::IO
inline bool WriteAsync(const AuSPtr<IAsyncTransaction> &pTransaction, inline bool WriteAsync(const AuSPtr<IAsyncTransaction> &pTransaction,
AuUInt64 uOffset, AuUInt64 uOffset,
const AuSPtr<Memory::MemoryViewRead> &memoryView, const Memory::MemoryViewRead &memoryView,
AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {}, AuOptional<AuConsumer<AuUInt /*offset*/, AuUInt64 /*length*/>> callback = {},
AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = {}) AuOptional<AuSPtr<CompletionGroup::ICompletionGroup>> pCompletionGroup = { Aurora::Async::GetSelfIOGroup() })
{ {
SysCheckArgNotNull(pTransaction, false); SysCheckArgNotNull(pTransaction, false);
if (pCompletionGroup) if (pCompletionGroup && pCompletionGroup.Value())
{ {
(void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value()); (void)pTransaction->TryAttachToCompletionGroup(pCompletionGroup.Value());
} }
else if (auto pGroup = Aurora::Async::GetSelfIOGroup())
{
(void)pTransaction->TryAttachToCompletionGroup(pGroup);
}
if (callback) if (callback)
{ {

View File

@ -24,22 +24,22 @@ namespace Aurora::IO::Adapters
{ {
if (this->pStreamWriter) 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) 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) else if (this->pWriteView)
{ {
if (this->pStreamReader) 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) 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(); this->Reset();
} }
bool AsyncReaderWriter::StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) bool AsyncReaderWriter::StartRead(AuUInt64 uOffset, const Memory::MemoryViewWrite &memoryView)
{ {
if (!memoryView) if (!memoryView)
{ {
@ -91,7 +91,7 @@ namespace Aurora::IO::Adapters
return pThat->Dispatch(); return pThat->Dispatch();
} }
bool AsyncReaderWriter::StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &memoryView) bool AsyncReaderWriter::StartWrite(AuUInt64 uOffset, const Memory::MemoryViewRead &memoryView)
{ {
if (!memoryView) if (!memoryView)
{ {

View File

@ -20,17 +20,17 @@ namespace Aurora::IO::Adapters
AuSPtr<ISeekingReader> pStreamReaderEx; AuSPtr<ISeekingReader> pStreamReaderEx;
AuSPtr<IStreamWriter> pStreamWriter; AuSPtr<IStreamWriter> pStreamWriter;
AuSPtr<ISeekingWriter> pStreamWriterEx; AuSPtr<ISeekingWriter> pStreamWriterEx;
AuSPtr<Memory::MemoryViewRead> pReadView; Memory::MemoryViewRead pReadView;
AuSPtr<Memory::MemoryViewWrite> pWriteView; Memory::MemoryViewWrite pWriteView;
AuWorkerPId workers; AuWorkerPId workers;
void DispatchFrame(ProcessInfo &info) override; void DispatchFrame(ProcessInfo &info) override;
void OnFailure() 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; AuUInt32 GetLastPacketLength() override;

View File

@ -267,7 +267,9 @@ namespace Aurora::IO::Adapters
(void)parent->transaction->TryAttachToCompletionGroup(this->parent->pCompletionGroup); (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; parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio read"); SysPushErrorNested("Couldn't start async aio read");
@ -436,8 +438,10 @@ namespace Aurora::IO::Adapters
{ {
(void)parent->transaction->TryAttachToCompletionGroup(this->parent->pCompletionGroup); (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; parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio read"); SysPushErrorNested("Couldn't start async aio read");
@ -599,26 +603,10 @@ namespace Aurora::IO::Adapters
parent->transaction->Reset(); parent->transaction->Reset();
parent->bAsyncActive = true; 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 = buffer;
parent->lastAllocation->streamIndex = 0; 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; parent->bAsyncActive = false;
SysPushErrorNested("Couldn't start async aio write"); SysPushErrorNested("Couldn't start async aio write");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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