[*] Cleanup/refactor of AuIO
This commit is contained in:
parent
fa0d46d4c7
commit
401cf09962
@ -10,6 +10,6 @@
|
||||
namespace Aurora::IO
|
||||
{
|
||||
AUKN_INTERFACE(IAsyncFinishedSubscriber,
|
||||
AUI_METHOD(void, OnAsyncFileOpFinished, (AuUInt64, offset, AuUInt32, length))
|
||||
AUI_METHOD(void, OnAsyncFileOpFinished, (AuUInt64, uOffset, AuUInt32, uLength))
|
||||
);
|
||||
}
|
@ -24,8 +24,8 @@ namespace Aurora::IO
|
||||
*/
|
||||
struct IAsyncTransaction
|
||||
{
|
||||
virtual bool StartRead(AuUInt64 offset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) = 0;
|
||||
virtual bool StartWrite(AuUInt64 offset, const AuSPtr<Memory::MemoryViewRead> &memoryView) = 0;
|
||||
virtual bool StartRead(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewWrite> &memoryView) = 0;
|
||||
virtual bool StartWrite(AuUInt64 uOffset, const AuSPtr<Memory::MemoryViewRead> &memoryView) = 0;
|
||||
|
||||
/**
|
||||
* @brief Non-blocking is-signaled and call callback poll routine
|
||||
@ -53,12 +53,12 @@ namespace Aurora::IO
|
||||
* @brief Registers an NT-like APC callback for the IO transaction.
|
||||
* Can be executed under any Aurora loop subsystem sleep
|
||||
*/
|
||||
virtual void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &sub) = 0;
|
||||
virtual void SetCallback(const AuSPtr<IAsyncFinishedSubscriber> &pSubscriber) = 0;
|
||||
|
||||
/**
|
||||
* @brief Block for completion
|
||||
*/
|
||||
virtual bool Wait(AuUInt32 timeout) = 0;
|
||||
virtual bool Wait(AuUInt32 uTimeout) = 0;
|
||||
|
||||
/**
|
||||
* @brief Provides a loop source that becomes signaled once the transaction is complete.
|
||||
|
@ -19,6 +19,6 @@ namespace Aurora::IO
|
||||
};
|
||||
|
||||
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewByteBufferPair();
|
||||
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewByteBufferPairEx(AuUInt length, bool permitResize);
|
||||
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewRingByteBuffer(AuUInt length);
|
||||
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewByteBufferPairEx(AuUInt uLength, bool bPermitResize);
|
||||
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewRingByteBuffer(AuUInt uLength);
|
||||
}
|
@ -16,8 +16,17 @@ namespace Aurora::IO
|
||||
virtual AuUInt32 GetRawBytesLimit() = 0;
|
||||
};
|
||||
|
||||
AUKN_SYM AuSPtr<IIOBufferedProcessor> NewBufferedProcessor(const AuSPtr<IStreamReader> &source,
|
||||
const AuSPtr<IIOPipeInterceptor> &processor,
|
||||
const AuSPtr<IStreamWriter> &drain, // TODO: share IOPipeCallback
|
||||
AuUInt32 bufferSize);
|
||||
/**
|
||||
* @brief
|
||||
* @param source
|
||||
* @param processor
|
||||
* @param drain
|
||||
* @param bufferSize
|
||||
* @deprecated by Aurora::IO::Protocol (tobe AuProtocol:: and AuIOProtocol::)
|
||||
* @return
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOBufferedProcessor> NewBufferedProcessor(const AuSPtr<IStreamReader> &pSource,
|
||||
const AuSPtr<IIOPipeInterceptor> &pProcessor,
|
||||
const AuSPtr<IStreamWriter> &pDrain, // TODO: share IOPipeCallback
|
||||
AuUInt32 uBufferSize);
|
||||
}
|
@ -12,7 +12,7 @@ namespace Aurora::IO
|
||||
struct IOPipeData;
|
||||
|
||||
AUKN_INTERFACE(IIOPipeEventListener,
|
||||
AUI_METHOD(void, OnPipePartialEvent, (AuUInt, transferred)),
|
||||
AUI_METHOD(void, OnPipePartialEvent, (AuUInt, uTransferred)),
|
||||
AUI_METHOD(void, OnPipeSuccessEvent, ()),
|
||||
AUI_METHOD(void, OnPipeFailureEvent, ())
|
||||
);
|
||||
|
@ -55,7 +55,27 @@ namespace Aurora::IO
|
||||
virtual bool HasItems () = 0;
|
||||
};
|
||||
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessor(bool tickOnly, const AuSPtr<Loop::ILoopQueue> &queue);
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessorOnThread(bool tickOnly, Async::WorkerPId_t id);
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessorNoQueue(bool tickOnly);
|
||||
/**
|
||||
* @brief Creates an IOProcessor to execute tasks on a given loop queue
|
||||
* @param bTickOnly True if kernel yielding on IO objects is disabled in favor of forced TPS.
|
||||
* Do note that the throughput of a tick will differ per platform. Accept rate,
|
||||
* throughput, etc may need tweaking, if you wish to drive an IIOProcessor using
|
||||
* a timer or the manual tick functions.
|
||||
* @param pQueue
|
||||
* @return
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessor(bool bTickOnly, const AuSPtr<Loop::ILoopQueue> &pQueue);
|
||||
|
||||
/**
|
||||
* @brief Creates an IOProcessor to execute tasks on the loop queue of a given AuAsync thread id
|
||||
* @param bTickOnly True if kernel yielding on IO objects is disabled in favor of forced TPS.
|
||||
* Do note that the throughput of a tick will differ per platform. Accept rate,
|
||||
* throughput, etc may need tweaking, if you wish to drive an IIOProcessor using
|
||||
* a timer or the manual tick functions.
|
||||
* @param pQueue
|
||||
* @return
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessorOnThread(bool bTickOnly, Async::WorkerPId_t id);
|
||||
|
||||
AUKN_SYM AuSPtr<IIOProcessor> NewIOProcessorNoQueue(bool bTickOnly);
|
||||
}
|
@ -11,6 +11,9 @@ namespace Aurora::IO
|
||||
{
|
||||
struct IIOProcessorManualInvoker
|
||||
{
|
||||
/**
|
||||
* @brief Used to invoke a tick on an IIOProcessor
|
||||
*/
|
||||
virtual void InvokeManualTick() = 0;
|
||||
};
|
||||
}
|
@ -15,5 +15,8 @@ namespace Aurora::IO
|
||||
AUI_METHOD(void, OnIOComplete, ())
|
||||
);
|
||||
|
||||
AUKN_SYM AuSPtr<IIOEventListener> DesimplifyIOEventListenerAdapter(const AuSPtr<IIOSimpleEventListener> &interface);
|
||||
/**
|
||||
* @brief Creates an adapter to convert an object that implements the simple listener interface to the annoying internal listener interface (7 callbacks)
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOEventListener> DesimplifyIOEventListenerAdapter(const AuSPtr<IIOSimpleEventListener> &pInterface);
|
||||
}
|
@ -12,9 +12,22 @@ namespace Aurora::IO
|
||||
struct IIOWatachableIOLoopSource : IIOWaitableItem
|
||||
{
|
||||
virtual AuSPtr<Loop::ILoopSource> GetLoopSource() = 0;
|
||||
virtual AuSPtr<Loop::ILoopSource> SetLoopSource(const AuSPtr<Loop::ILoopSource> &ls) = 0;
|
||||
virtual AuSPtr<Loop::ILoopSource> SetLoopSource(const AuSPtr<Loop::ILoopSource> &pLoopSource) = 0;
|
||||
};
|
||||
|
||||
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource> &ptr);
|
||||
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSourceEx(const AuSPtr<Loop::ILoopSource>& ptr, AuUInt32 msTimeout);
|
||||
/**
|
||||
* @brief Creates an adapter given an ILoopSource for the IO subsystem to wait on
|
||||
* @param pLoopSource
|
||||
* @return
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSource(const AuSPtr<Loop::ILoopSource> &pLoopSource);
|
||||
|
||||
/**
|
||||
* @brief Creates an adapter given an ILoopSource for the IO subsystem to wait on
|
||||
* @param pLoopSource
|
||||
* @param uMsTimeout
|
||||
* @return
|
||||
*/
|
||||
AUKN_SYM AuSPtr<IIOWatachableIOLoopSource> NewWaitableLoopSourceEx(const AuSPtr<Loop::ILoopSource> &pLoopSource,
|
||||
AuUInt32 uMsTimeout);
|
||||
}
|
@ -9,7 +9,6 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
|
||||
// Unstable and hacky interface
|
||||
// You shouldn't try to implement this yourself
|
||||
// Defer to IIOWaitableIOLoopSource, IIOWaitableIOTimer, and IIOWaitableTickLimiter for intended impl usage
|
||||
@ -29,5 +28,4 @@ namespace Aurora::IO
|
||||
|
||||
AUI_METHOD(bool, ApplyRateLimit, ())
|
||||
);
|
||||
|
||||
}
|
@ -46,5 +46,5 @@ namespace Aurora::IO
|
||||
virtual bool Reset() = 0;
|
||||
};
|
||||
|
||||
AUKN_SYM AuSPtr<IAsyncStreamAdapter> NewAsyncStreamAdapter(const AuSPtr<IAsyncTransaction> &transaction, bool isStream);
|
||||
AUKN_SYM AuSPtr<IAsyncStreamAdapter> NewAsyncStreamAdapter(const AuSPtr<IAsyncTransaction> &pTransaction, bool bIsStream);
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewByteBufferReadAdapter(const AuSPtr<Memory::ByteBuffer> &buffer);
|
||||
AUKN_SYM AuSPtr<ISeekingReader> NewByteBufferLinearSeekableAdapter(const AuSPtr<Memory::ByteBuffer> &buffer);
|
||||
AUKN_SYM AuSPtr<IStreamWriter> NewByteBufferWriteAdapter(const AuSPtr<Memory::ByteBuffer> &buffer);
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewByteBufferReadAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer);
|
||||
AUKN_SYM AuSPtr<ISeekingReader> NewByteBufferLinearSeekableAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer);
|
||||
AUKN_SYM AuSPtr<IStreamWriter> NewByteBufferWriteAdapter(const AuSPtr<Memory::ByteBuffer> &pBuffer);
|
||||
}
|
@ -9,6 +9,6 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewCompressionReadAdapter(const AuSPtr<Compression::ICompressionStream> &compresionStream);
|
||||
AUKN_SYM AuSPtr<ISeekingReader> NewCompressionSeekingAdapter(const AuSPtr<Compression::ICompressionStream> &compresionStream);
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewCompressionReadAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream);
|
||||
AUKN_SYM AuSPtr<ISeekingReader> NewCompressionSeekingAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream);
|
||||
}
|
@ -9,5 +9,5 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewSeekingReadAdapter(const AuSPtr<ISeekingReader> &reader);
|
||||
AUKN_SYM AuSPtr<IStreamReader> NewSeekingReadAdapter(const AuSPtr<ISeekingReader> &pReader);
|
||||
}
|
@ -18,13 +18,13 @@ namespace Aurora::IO
|
||||
|
||||
struct
|
||||
{
|
||||
AuSPtr<IIOBufferedStreamAvailable> onData;
|
||||
AuSPtr<IIOBufferedStreamAvailable> pOnData;
|
||||
} handleBufferedStream;
|
||||
|
||||
struct
|
||||
{
|
||||
AuSPtr<IIOPipeInterceptor> intercepter;
|
||||
AuSPtr<IStreamWriter> writer;
|
||||
AuSPtr<IIOPipeInterceptor> pIntercepter;
|
||||
AuSPtr<IStreamWriter> pWriter;
|
||||
|
||||
bool bFlushWriter {true};
|
||||
} forwardStream;
|
||||
|
@ -16,17 +16,17 @@ namespace Aurora::IO
|
||||
/**
|
||||
* @brief IO trigger
|
||||
*/
|
||||
AuSPtr<IIOWaitableItem> watchItem;
|
||||
AuSPtr<IIOWaitableItem> pWatchItem;
|
||||
|
||||
/**
|
||||
* @brief Input source
|
||||
*/
|
||||
AuSPtr<IStreamReader> reader;
|
||||
AuSPtr<IStreamReader> pReader;
|
||||
|
||||
/**
|
||||
* @brief Callbacks
|
||||
*/
|
||||
AuSPtr<IPipeBackend> backend;
|
||||
AuSPtr<IPipeBackend> pBackend;
|
||||
|
||||
/**
|
||||
* @brief Enables aggressive stream consumption, allowing for bias towards clients if they were to send a lot of data (including dos)
|
||||
|
@ -16,31 +16,31 @@ namespace Aurora::IO
|
||||
/**
|
||||
* @brief Amount of bytes to transfer or zero if run until EoS/EoF
|
||||
*/
|
||||
AuUInt32 lengthOrZero {};
|
||||
AuUInt32 uLengthOrZero {};
|
||||
|
||||
/**
|
||||
* @brief true if the underlying stream uses relative stream positions
|
||||
* (IE: a network or pipe stream that cannot seek backwards and fowards)
|
||||
* (Inversely, file devices and similar IO subsystems use IO packets with absolute offsets)
|
||||
*/
|
||||
bool isStream {false};
|
||||
bool bIsStream {false};
|
||||
|
||||
/**
|
||||
* @brief internal frame size, that is one iteration of file or stream read, in bytes or zero if fallback
|
||||
* Windows is inclined to read every single requested byte of a file stream asynchronously
|
||||
* Streams, on all platforms, yield as soon as there is data available to copy over (usually)
|
||||
*/
|
||||
AuUInt32 pageLengthOrZero {};
|
||||
AuUInt32 uPageLengthOrZero {};
|
||||
|
||||
/**
|
||||
* @brief internal buffer size or zero if fallback
|
||||
*/
|
||||
AuUInt32 bufferLengthOrZero {};
|
||||
AuUInt32 uBufferLengthOrZero {};
|
||||
|
||||
/**
|
||||
* @brief event listener
|
||||
*/
|
||||
AuSPtr<IIOPipeEventListener> listener;
|
||||
AuSPtr<IIOPipeEventListener> pListener;
|
||||
|
||||
/**
|
||||
* @brief Used as the buffer size for streams of page length 0
|
||||
|
@ -13,7 +13,7 @@ namespace Aurora::IO
|
||||
|
||||
struct IOPipeRequestAIO : IOPipeRequest
|
||||
{
|
||||
AuSPtr<IAsyncTransaction> asyncTransaction;
|
||||
AuSPtr<IAsyncTransaction> pAsyncTransaction;
|
||||
|
||||
IOPipeCallback output;
|
||||
};
|
||||
|
@ -15,7 +15,7 @@ namespace Aurora::IO
|
||||
* @param timeout Timeout in milliseconds, zero = indefinite
|
||||
* @return true on preemption, false on timeout
|
||||
*/
|
||||
AUKN_SYM bool WaitFor(AuUInt32 milliseconds, bool waitEntireFrame = true);
|
||||
AUKN_SYM bool WaitFor(AuUInt32 uMilliseconds, bool bWaitEntireFrame = true);
|
||||
|
||||
/**
|
||||
* Sleeps for the given timeout in milliseconds
|
||||
@ -24,7 +24,7 @@ namespace Aurora::IO
|
||||
* @param timeout Timeout in milliseconds, zero = indefinite
|
||||
* @return True if an IO event occurred
|
||||
*/
|
||||
AUKN_SYM bool IOSleep(AuUInt32 milliseconds);
|
||||
AUKN_SYM bool IOSleep(AuUInt32 uMilliseconds);
|
||||
|
||||
/**
|
||||
* Sleeps up to the given timeout in milliseconds
|
||||
@ -33,7 +33,7 @@ namespace Aurora::IO
|
||||
* @param timeout Timeout in milliseconds, zero = indefinite
|
||||
* @return True if an IO event occurred
|
||||
*/
|
||||
AUKN_SYM bool IOYieldFor(AuUInt32 milliseconds);
|
||||
AUKN_SYM bool IOYieldFor(AuUInt32 uMilliseconds);
|
||||
|
||||
/**
|
||||
* Nonblocking yield for IO alerts
|
||||
|
@ -11,7 +11,8 @@ namespace Aurora::IO
|
||||
{
|
||||
AUKN_INTERFACE(ISeekingReader,
|
||||
AUI_METHOD(EStreamError, IsOpen, ()),
|
||||
AUI_METHOD(EStreamError, ArbitraryRead, (AuUInt, offset, const Memory::MemoryViewStreamWrite&, paramters)),
|
||||
AUI_METHOD(EStreamError, ArbitraryRead, (AuUInt, uOffset,
|
||||
const Memory::MemoryViewStreamWrite&, writeView)),
|
||||
AUI_METHOD(void, Close, ())
|
||||
);
|
||||
}
|
@ -13,10 +13,10 @@ namespace Aurora::IO
|
||||
{
|
||||
struct IOBufferedProcessor : IIOBufferedProcessor
|
||||
{
|
||||
AuSPtr<IStreamReader> source;
|
||||
AuSPtr<IStreamWriter> drain;
|
||||
AuSPtr<IIOPipeInterceptor> processor;
|
||||
AuUInt32 bufferSize {};
|
||||
AuSPtr<IStreamReader> pSource;
|
||||
AuSPtr<IStreamWriter> pDrain;
|
||||
AuSPtr<IIOPipeInterceptor> pProcessor;
|
||||
AuUInt32 uBufferSize {};
|
||||
AuByteBuffer buffer;
|
||||
|
||||
AU_DEFINE_FOR_VA(IOBufferedProcessor,
|
||||
@ -25,7 +25,7 @@ namespace Aurora::IO
|
||||
AU_DEFINE_EQUALS_VA, // add equals operator
|
||||
AU_DEFINE_MOVE_VA, // add move assignment operator
|
||||
AU_DEFINE_COPY_VA), // add copy assignment operator
|
||||
(source, drain, processor, bufferSize));
|
||||
(pSource, pDrain, pProcessor, uBufferSize));
|
||||
|
||||
|
||||
AuUInt32 TryProcessBuffered() override;
|
||||
@ -39,7 +39,7 @@ namespace Aurora::IO
|
||||
{
|
||||
if (this->buffer.IsEmpty())
|
||||
{
|
||||
this->buffer.Allocate(this->bufferSize);
|
||||
this->buffer.Allocate(this->uBufferSize);
|
||||
this->buffer.flagCircular = true; // !!!
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ namespace Aurora::IO
|
||||
AuUInt read {};
|
||||
try
|
||||
{
|
||||
if (this->source->Read(AuMemoryViewStreamWrite(AuMemoryViewWrite(this->buffer.writePtr, canBuffer), read)) !=
|
||||
if (this->pSource->Read(AuMemoryViewStreamWrite(AuMemoryViewWrite(this->buffer.writePtr, canBuffer), read)) !=
|
||||
AuIO::EStreamError::eErrorNone)
|
||||
{
|
||||
return TryPump();
|
||||
@ -82,12 +82,17 @@ namespace Aurora::IO
|
||||
|
||||
do
|
||||
{
|
||||
if (this->buffer.flagCircular && this->buffer.readPtr == this->buffer.base + this->buffer.length)
|
||||
{
|
||||
this->buffer.readPtr = this->buffer.base;
|
||||
}
|
||||
|
||||
AuUInt canRead = this->buffer.RemainingBytes();
|
||||
canRead = AuMin<AuUInt>(canRead, (this->buffer.length + this->buffer.base) - this->buffer.readPtr);
|
||||
|
||||
try
|
||||
{
|
||||
if (!this->processor->OnDataAvailable(AuMemoryViewStreamRead(AuMemoryViewRead(this->buffer.readPtr, canRead), bytesProcessed), this->drain))
|
||||
if (!this->pProcessor->OnDataAvailable(AuMemoryViewStreamRead(AuMemoryViewRead(this->buffer.readPtr, canRead), bytesProcessed), this->pDrain))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -100,7 +105,7 @@ namespace Aurora::IO
|
||||
this->buffer.readPtr += bytesProcessed;
|
||||
bytesProcessedTotal += bytesProcessed;
|
||||
|
||||
if (this->buffer.readPtr == this->buffer.base + this->buffer.length)
|
||||
if (this->buffer.flagCircular && this->buffer.readPtr == this->buffer.base + this->buffer.length)
|
||||
{
|
||||
this->buffer.readPtr = this->buffer.base;
|
||||
}
|
||||
@ -117,14 +122,14 @@ namespace Aurora::IO
|
||||
|
||||
AuUInt32 IOBufferedProcessor::GetRawBytesLimit()
|
||||
{
|
||||
return this->bufferSize;
|
||||
return this->uBufferSize;
|
||||
}
|
||||
|
||||
AUKN_SYM AuSPtr<IIOBufferedProcessor> NewBufferedProcessor(const AuSPtr<IStreamReader> &source,
|
||||
const AuSPtr<IIOPipeInterceptor> &processor,
|
||||
const AuSPtr<IStreamWriter> &drain,
|
||||
AuUInt32 bufferSize)
|
||||
AUKN_SYM AuSPtr<IIOBufferedProcessor> NewBufferedProcessor(const AuSPtr<IStreamReader> &pSource,
|
||||
const AuSPtr<IIOPipeInterceptor> &pProcessor,
|
||||
const AuSPtr<IStreamWriter> &pDrain,
|
||||
AuUInt32 uBufferSize)
|
||||
{
|
||||
return AuMakeShared<IOBufferedProcessor>(source, drain, processor, bufferSize);
|
||||
return AuMakeShared<IOBufferedProcessor>(pSource, pDrain, pProcessor, uBufferSize);
|
||||
}
|
||||
}
|
@ -19,13 +19,13 @@ namespace Aurora::IO
|
||||
endCallback(this),
|
||||
output(request.output)
|
||||
{
|
||||
this->frameCap_ = request.pageLengthOrZero ? request.pageLengthOrZero : request.kFallbackPageSize;
|
||||
this->bufferSize_ = request.bufferLengthOrZero ? request.bufferLengthOrZero : request.kFallbackBufferSize;
|
||||
this->bytesWrittenLimit_ = request.lengthOrZero;
|
||||
this->asyncTransaction_ = request.asyncTransaction;
|
||||
this->asyncAdapter_ = NewAsyncStreamAdapter(request.asyncTransaction, request.isStream);
|
||||
SysAssert(this->asyncAdapter_);
|
||||
this->asyncStreamReader_ = this->asyncAdapter_->ToStreamReader();
|
||||
this->uFrameCap_ = request.uPageLengthOrZero ? request.uPageLengthOrZero : request.kFallbackPageSize;
|
||||
this->uBufferSize_ = request.uBufferLengthOrZero ? request.uBufferLengthOrZero : request.kFallbackBufferSize;
|
||||
this->uBytesWrittenLimit_ = request.uLengthOrZero;
|
||||
this->pAsyncTransaction_ = request.pAsyncTransaction;
|
||||
this->pAsyncAdapter_ = NewAsyncStreamAdapter(request.pAsyncTransaction, request.bIsStream);
|
||||
SysAssert(this->pAsyncAdapter_);
|
||||
this->pAsyncStreamReader_ = this->pAsyncAdapter_->ToStreamReader();
|
||||
}
|
||||
|
||||
IOPipeWork::IOPipeWork(const AuSPtr<IOPipeProcessor> &parent, const IOPipeRequestBasic &request) :
|
||||
@ -35,9 +35,9 @@ namespace Aurora::IO
|
||||
endCallback(this),
|
||||
output(request.output)
|
||||
{
|
||||
this->bufferSize_ = request.bufferLengthOrZero ? request.bufferLengthOrZero : request.kFallbackBufferSize;
|
||||
this->frameCap_ = request.pageLengthOrZero ? request.pageLengthOrZero : request.kFallbackPageSize;
|
||||
this->bytesWrittenLimit_ = request.lengthOrZero;
|
||||
this->uBufferSize_ = request.uBufferLengthOrZero ? request.uBufferLengthOrZero : request.kFallbackBufferSize;
|
||||
this->uFrameCap_ = request.uPageLengthOrZero ? request.uPageLengthOrZero : request.kFallbackPageSize;
|
||||
this->uBytesWrittenLimit_ = request.uLengthOrZero;
|
||||
}
|
||||
|
||||
void IOPipeWork::Tick_FrameEpilogue()
|
||||
@ -50,7 +50,7 @@ namespace Aurora::IO
|
||||
|
||||
void IOPipeWork::Tick_Any()
|
||||
{
|
||||
if (this->asyncTransaction_)
|
||||
if (this->pAsyncTransaction_)
|
||||
{
|
||||
this->AsyncPump();
|
||||
}
|
||||
@ -110,9 +110,9 @@ namespace Aurora::IO
|
||||
{
|
||||
AuSPtr<IIOProcessorItem> ret;
|
||||
|
||||
if (this->asyncTransaction_)
|
||||
if (this->pAsyncTransaction_)
|
||||
{
|
||||
auto pWaitable = this->asyncAdapter_->ToWaitable();
|
||||
auto pWaitable = this->pAsyncAdapter_->ToWaitable();
|
||||
if (pWaitable)
|
||||
{
|
||||
ret = this->parent_->parent_->StartIOWatch(pWaitable, AuSharedFromThis());
|
||||
@ -124,7 +124,7 @@ namespace Aurora::IO
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = this->parent_->parent_->StartIOWatch(this->input_.watchItem, AuSharedFromThis());
|
||||
ret = this->parent_->parent_->StartIOWatch(this->input_.pWatchItem, AuSharedFromThis());
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
@ -132,7 +132,7 @@ namespace Aurora::IO
|
||||
}
|
||||
}
|
||||
|
||||
this->watch = ret;
|
||||
this->pWatch = ret;
|
||||
|
||||
if (this->parent_->parent_->CheckThread())
|
||||
{
|
||||
@ -165,7 +165,7 @@ namespace Aurora::IO
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this->buffer_.Allocate(this->bufferSize_, AuHwInfo::GetPageSize(), true))
|
||||
if (!this->buffer_.Allocate(this->uBufferSize_, AuHwInfo::GetPageSize(), true))
|
||||
{
|
||||
SysPushErrorMem();
|
||||
TerminateOnThread(true);
|
||||
@ -185,7 +185,7 @@ namespace Aurora::IO
|
||||
{
|
||||
AuMemoryViewWrite internalBuffer;
|
||||
|
||||
auto err = this->asyncStreamReader_->Dequeue(0, internalBuffer);
|
||||
auto err = this->pAsyncStreamReader_->Dequeue(0, internalBuffer);
|
||||
if (err != EStreamError::eErrorNone)
|
||||
{
|
||||
SysPushErrorIO("Async Stream Error: {}", err);
|
||||
@ -200,7 +200,7 @@ namespace Aurora::IO
|
||||
return;
|
||||
}
|
||||
|
||||
err = this->asyncStreamReader_->Dequeue(internalBuffer.length, internalBuffer);
|
||||
err = this->pAsyncStreamReader_->Dequeue(internalBuffer.length, internalBuffer);
|
||||
if (err != EStreamError::eErrorNone)
|
||||
{
|
||||
SysPushErrorIO("Async Stream Error: {}", err);
|
||||
@ -221,7 +221,7 @@ namespace Aurora::IO
|
||||
AuUInt read {};
|
||||
try
|
||||
{
|
||||
if (this->input_.reader->Read(AuMemoryViewStreamWrite(AuMemoryViewWrite(this->buffer_.writePtr, canBuffer), read)) !=
|
||||
if (this->input_.pReader->Read(AuMemoryViewStreamWrite(AuMemoryViewWrite(this->buffer_.writePtr, canBuffer), read)) !=
|
||||
AuIO::EStreamError::eErrorNone)
|
||||
{
|
||||
TerminateOnThread();
|
||||
@ -248,11 +248,11 @@ namespace Aurora::IO
|
||||
{
|
||||
AuUInt canBuffer = this->buffer_.RemainingWrite();
|
||||
canBuffer = AuMin(canBuffer, AuUInt((this->buffer_.length + this->buffer_.base) - this->buffer_.writePtr));
|
||||
canBuffer = AuMin(AuUInt(this->frameCap_), canBuffer);
|
||||
canBuffer = AuMin(AuUInt(this->uFrameCap_), canBuffer);
|
||||
|
||||
this->nextWriteAsync_ = AuMemoryViewWrite(this->buffer_.writePtr, canBuffer);
|
||||
|
||||
if (this->asyncStreamReader_->BeginRead(AuSPtr<AuMemoryViewWrite>(this->SharedFromThis(), &this->nextWriteAsync_)) !=
|
||||
if (this->pAsyncStreamReader_->BeginRead(AuSPtr<AuMemoryViewWrite>(this->SharedFromThis(), &this->nextWriteAsync_)) !=
|
||||
AuIO::EStreamError::eErrorNone)
|
||||
{
|
||||
TerminateOnThread(true);
|
||||
@ -284,15 +284,15 @@ namespace Aurora::IO
|
||||
return;
|
||||
}
|
||||
|
||||
if (this->asyncTransaction_)
|
||||
if (this->pAsyncTransaction_)
|
||||
{
|
||||
ReadNextAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->input_.backend)
|
||||
if (this->input_.pBackend)
|
||||
{
|
||||
this->input_.backend->OnEndPump();
|
||||
this->input_.pBackend->OnEndPump();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -323,7 +323,7 @@ namespace Aurora::IO
|
||||
{
|
||||
if (this->output.type == EPipeCallbackType::eTryHandleBufferedPart)
|
||||
{
|
||||
if (!this->output.handleBufferedStream.onData->OnDataAvailable(this->buffer_))
|
||||
if (!this->output.handleBufferedStream.pOnData->OnDataAvailable(this->buffer_))
|
||||
{
|
||||
bytesProcessed = 0;
|
||||
this->buffer_.readPtr = this->buffer_.base + readHead;
|
||||
@ -335,7 +335,7 @@ namespace Aurora::IO
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!this->output.forwardStream.intercepter->OnDataAvailable(AuMemoryViewStreamRead(AuMemoryViewRead(this->buffer_.readPtr, canRead), bytesProcessed), this->output.forwardStream.writer))
|
||||
if (!this->output.forwardStream.pIntercepter->OnDataAvailable(AuMemoryViewStreamRead(AuMemoryViewRead(this->buffer_.readPtr, canRead), bytesProcessed), this->output.forwardStream.pWriter))
|
||||
{
|
||||
bytesProcessed = 0;
|
||||
}
|
||||
@ -390,7 +390,7 @@ namespace Aurora::IO
|
||||
{
|
||||
if (this->output.forwardStream.bFlushWriter)
|
||||
{
|
||||
this->output.forwardStream.writer->Flush();
|
||||
this->output.forwardStream.pWriter->Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,11 +401,11 @@ namespace Aurora::IO
|
||||
this->bShouldReadNext = true;
|
||||
}
|
||||
|
||||
this->bytesWritten_ += bytesProcessedTotal;
|
||||
this->uBytesWritten_ += bytesProcessedTotal;
|
||||
|
||||
if (this->request.listener)
|
||||
if (this->request.pListener)
|
||||
{
|
||||
this->request.listener->OnPipePartialEvent(bytesProcessedTotal);
|
||||
this->request.pListener->OnPipePartialEvent(bytesProcessedTotal);
|
||||
}
|
||||
|
||||
return bytesProcessedTotal;
|
||||
@ -413,7 +413,7 @@ namespace Aurora::IO
|
||||
|
||||
bool IOPipeWork::IsAtRequestedEnd()
|
||||
{
|
||||
return this->bytesWrittenLimit_ && (this->bytesWrittenLimit_ <= this->bytesWritten_);
|
||||
return this->uBytesWrittenLimit_ && (this->uBytesWrittenLimit_ <= this->uBytesWritten_);
|
||||
}
|
||||
|
||||
AuByteBuffer *IOPipeWork::GetBuffer()
|
||||
@ -423,12 +423,12 @@ namespace Aurora::IO
|
||||
|
||||
void IOPipeWork::RunOnThread()
|
||||
{
|
||||
if (this->input_.backend)
|
||||
if (this->input_.pBackend)
|
||||
{
|
||||
this->input_.backend->OnStart();
|
||||
this->input_.pBackend->OnStart();
|
||||
}
|
||||
|
||||
if (this->asyncTransaction_)
|
||||
if (this->pAsyncTransaction_)
|
||||
{
|
||||
PrepareAsync();
|
||||
}
|
||||
@ -447,50 +447,50 @@ namespace Aurora::IO
|
||||
|
||||
this->bActive = false;
|
||||
|
||||
if (this->watch)
|
||||
if (this->pWatch)
|
||||
{
|
||||
watch->StopWatch();
|
||||
this->pWatch->StopWatch();
|
||||
}
|
||||
|
||||
if (this->request.listener)
|
||||
if (this->request.pListener)
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
// We explicitly failed...
|
||||
this->request.listener->OnPipeFailureEvent();
|
||||
this->request.pListener->OnPipeFailureEvent();
|
||||
}
|
||||
else if (this->bytesWrittenLimit_ && (this->bytesWrittenLimit_ > this->bytesWritten_))
|
||||
else if (this->uBytesWrittenLimit_ && (this->uBytesWrittenLimit_ > this->uBytesWritten_))
|
||||
{
|
||||
// Finished without error early
|
||||
this->request.listener->OnPipeFailureEvent();
|
||||
this->request.pListener->OnPipeFailureEvent();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We finished...
|
||||
this->request.listener->OnPipeSuccessEvent();
|
||||
this->request.pListener->OnPipeSuccessEvent();
|
||||
}
|
||||
|
||||
this->request.listener.reset();
|
||||
this->request.pListener.reset();
|
||||
}
|
||||
|
||||
this->output.handleBufferedStream.onData.reset();
|
||||
this->output.forwardStream.intercepter.reset();
|
||||
this->output.forwardStream.writer.reset();
|
||||
this->output.handleBufferedStream.pOnData.reset();
|
||||
this->output.forwardStream.pIntercepter.reset();
|
||||
this->output.forwardStream.pWriter.reset();
|
||||
|
||||
if (this->input_.backend)
|
||||
if (this->input_.pBackend)
|
||||
{
|
||||
this->input_.backend->OnEnd();
|
||||
this->input_.backend.reset();
|
||||
this->input_.pBackend->OnEnd();
|
||||
this->input_.pBackend.reset();
|
||||
}
|
||||
|
||||
if (auto transaction = this->asyncTransaction_)
|
||||
if (auto transaction = this->pAsyncTransaction_)
|
||||
{
|
||||
transaction->Reset();
|
||||
this->asyncTransaction_.reset();
|
||||
this->pAsyncTransaction_.reset();
|
||||
}
|
||||
|
||||
this->asyncAdapter_.reset();
|
||||
this->asyncStreamReader_.reset();
|
||||
this->pAsyncAdapter_.reset();
|
||||
this->pAsyncStreamReader_.reset();
|
||||
}
|
||||
|
||||
IOPipeProcessor::IOPipeProcessor(IOProcessor *parent) :
|
||||
|
@ -35,10 +35,10 @@ namespace Aurora::IO
|
||||
|
||||
struct IOPipeWork : IIOPipeWork, IIOEventListenerFunctional, AuEnableSharedFromThis<IIOPipeWork>
|
||||
{
|
||||
IOPipeWork(const AuSPtr<IOPipeProcessor> &parent, const IOPipeRequestAIO &request);
|
||||
IOPipeWork(const AuSPtr<IOPipeProcessor> &parent, const IOPipeRequestBasic &request);
|
||||
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestAIO &request);
|
||||
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestBasic &request);
|
||||
|
||||
AuSPtr<IIOProcessorItem> watch;
|
||||
AuSPtr<IIOProcessorItem> pWatch;
|
||||
|
||||
void Tick_FrameEpilogue() override;
|
||||
void Tick_Any() override;
|
||||
@ -51,7 +51,7 @@ namespace Aurora::IO
|
||||
virtual bool End() override;
|
||||
|
||||
void RunOnThread();
|
||||
void TerminateOnThread(bool error = false);
|
||||
void TerminateOnThread(bool bError = false);
|
||||
|
||||
// INIT
|
||||
void PrepareStream();
|
||||
@ -80,19 +80,19 @@ namespace Aurora::IO
|
||||
struct /*not a union. the following members are mutex*/
|
||||
{
|
||||
IOPipeInputData input_;
|
||||
AuSPtr<IAsyncTransaction> asyncTransaction_;
|
||||
AuSPtr<IAsyncStreamAdapter> asyncAdapter_;
|
||||
AuSPtr<IAsyncStreamReader> asyncStreamReader_;
|
||||
AuSPtr<IAsyncTransaction> pAsyncTransaction_;
|
||||
AuSPtr<IAsyncStreamAdapter> pAsyncAdapter_;
|
||||
AuSPtr<IAsyncStreamReader> pAsyncStreamReader_;
|
||||
};
|
||||
|
||||
IOPipeCallback output;
|
||||
IOWorkStart startCallback;
|
||||
IOWorkEnd endCallback;
|
||||
bool bActive {true};
|
||||
AuUInt32 bufferSize_ {};
|
||||
AuUInt32 frameCap_ {};
|
||||
AuUInt bytesWritten_ {};
|
||||
AuUInt bytesWrittenLimit_ {};
|
||||
AuUInt32 uBufferSize_ {};
|
||||
AuUInt32 uFrameCap_ {};
|
||||
AuUInt uBytesWritten_ {};
|
||||
AuUInt uBytesWrittenLimit_ {};
|
||||
AuByteBuffer buffer_;
|
||||
};
|
||||
|
||||
|
@ -16,11 +16,12 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
IOProcessor::IOProcessor(AuUInt threadId, bool tickOnly,
|
||||
IOProcessor::IOProcessor(AuUInt threadId,
|
||||
bool bTickOnly,
|
||||
AuAsync::WorkerPId_t worker,
|
||||
const AuSPtr<AuLoop::ILoopQueue> &loop) :
|
||||
mutliplexIOAndTimer(!tickOnly),
|
||||
loopQueue(loop),
|
||||
const AuSPtr<AuLoop::ILoopQueue> &pLoopQueue) :
|
||||
mutliplexIOAndTimer(!bTickOnly),
|
||||
pLoopQueue(pLoopQueue),
|
||||
asyncWorker(worker),
|
||||
threadId(threadId),
|
||||
streamProcessors(this)
|
||||
@ -101,7 +102,7 @@ namespace Aurora::IO
|
||||
return;
|
||||
}
|
||||
|
||||
AuStaticCast<Loop::LoopQueue>(this->loopQueue)->AddHook([that = AuSharedFromThis()]()
|
||||
AuStaticCast<Loop::LoopQueue>(this->pLoopQueue)->AddHook([that = AuSharedFromThis()]()
|
||||
{
|
||||
that->RunTick();
|
||||
});
|
||||
@ -204,9 +205,9 @@ namespace Aurora::IO
|
||||
|
||||
for (auto &item : this->items.allItems)
|
||||
{
|
||||
if (item->item->IsRunOnSelfIO() && item->item->IsRunOnSelfIOCheckedOnTimerTick())
|
||||
if (item->pItem->IsRunOnSelfIO() && item->pItem->IsRunOnSelfIOCheckedOnTimerTick())
|
||||
{
|
||||
auto ls = item->item->GetSelfIOSource();
|
||||
auto ls = item->pItem->GetSelfIOSource();
|
||||
if (ls && ls->IsSignaled())
|
||||
{
|
||||
// Should deadlock without critical sections
|
||||
@ -220,16 +221,16 @@ namespace Aurora::IO
|
||||
{
|
||||
for (auto &a : this->items.onTickReceivers)
|
||||
{
|
||||
if (a->listener)
|
||||
if (a->pListener)
|
||||
{
|
||||
try
|
||||
{
|
||||
a->listener->Tick_RunOnTick();
|
||||
a->pListener->Tick_RunOnTick();
|
||||
|
||||
if (!AuExists(this->items.workSignaled, a) &&
|
||||
!AuExists(this->items.onTickReceivers, a))
|
||||
{
|
||||
a->listener->Tick_Any();
|
||||
a->pListener->Tick_Any();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
@ -243,12 +244,12 @@ namespace Aurora::IO
|
||||
|
||||
for (auto &a : this->items.workSignaled)
|
||||
{
|
||||
if (a->listener)
|
||||
if (a->pListener)
|
||||
{
|
||||
try
|
||||
{
|
||||
a->listener->Tick_SelfIOEvent();
|
||||
a->listener->Tick_Any();
|
||||
a->pListener->Tick_SelfIOEvent();
|
||||
a->pListener->Tick_Any();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -274,12 +275,12 @@ namespace Aurora::IO
|
||||
continue;
|
||||
}
|
||||
|
||||
if (a->listener)
|
||||
if (a->pListener)
|
||||
{
|
||||
try
|
||||
{
|
||||
a->listener->Tick_OtherIOEvent();
|
||||
a->listener->Tick_Any();
|
||||
a->pListener->Tick_OtherIOEvent();
|
||||
a->pListener->Tick_Any();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -299,14 +300,14 @@ namespace Aurora::IO
|
||||
|
||||
for (auto &pumped : this->items.finalizeQueue)
|
||||
{
|
||||
if (!pumped->listener)
|
||||
if (!pumped->pListener)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
pumped->listener->Tick_FrameEpilogue();
|
||||
pumped->pListener->Tick_FrameEpilogue();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -344,15 +345,15 @@ namespace Aurora::IO
|
||||
|
||||
try
|
||||
{
|
||||
if (processor->listener)
|
||||
if (processor->pListener)
|
||||
{
|
||||
if (fatal)
|
||||
{
|
||||
processor->listener->OnFailureCompletion();
|
||||
processor->pListener->OnFailureCompletion();
|
||||
}
|
||||
else
|
||||
{
|
||||
processor->listener->OnNominalCompletion();
|
||||
processor->pListener->OnNominalCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -361,7 +362,7 @@ namespace Aurora::IO
|
||||
SysPushErrorCatch();
|
||||
}
|
||||
|
||||
auto item = processor->item;
|
||||
auto item = processor->pItem;
|
||||
|
||||
if (item->IsRunOnTick())
|
||||
{
|
||||
@ -452,7 +453,7 @@ namespace Aurora::IO
|
||||
}
|
||||
else
|
||||
{
|
||||
return this->loopQueue->WaitAny(msMax);
|
||||
return this->pLoopQueue->WaitAny(msMax);
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,7 +559,7 @@ namespace Aurora::IO
|
||||
|
||||
void IOProcessor::UpdateTimers()
|
||||
{
|
||||
this->timers.lsTicker->UpdateTickRateIfAnyNs(this->refreshRateNs);
|
||||
this->timers.pLsTicker->UpdateTickRateIfAnyNs(this->refreshRateNs);
|
||||
this->timers.nbTicker.nsTimeStep = this->refreshRateNs;
|
||||
|
||||
if (!this->timers.nbTicker.nextTriggerTime)
|
||||
@ -581,21 +582,21 @@ namespace Aurora::IO
|
||||
|
||||
void IOProcessor::AddTimerLS()
|
||||
{
|
||||
this->ToQueue()->SourceAdd(this->timers.lsTicker);
|
||||
this->ToQueue()->AddCallback(this->timers.lsTicker, AuSPtr<AuLoop::ILoopSourceSubscriber>(AuSharedFromThis(), &this->timers));
|
||||
this->ToQueue()->SourceAdd(this->timers.pLsTicker);
|
||||
this->ToQueue()->AddCallback(this->timers.pLsTicker, AuSPtr<AuLoop::ILoopSourceSubscriber>(AuSharedFromThis(), &this->timers));
|
||||
this->ToQueue()->Commit();
|
||||
}
|
||||
|
||||
void IOProcessor::StartAsyncTimerIfAny()
|
||||
{
|
||||
if (!this->workItem)
|
||||
if (!this->pWorkItem)
|
||||
{
|
||||
this->workItem = this->asyncWorker.pool->NewWorkItem(this->asyncWorker, AuSharedFromThis());
|
||||
this->pWorkItem = this->asyncWorker.pool->NewWorkItem(this->asyncWorker, AuSharedFromThis());
|
||||
}
|
||||
|
||||
this->workItem->SetSchedTimeNs(this->refreshRateNs);
|
||||
this->pWorkItem->SetSchedTimeNs(this->refreshRateNs);
|
||||
|
||||
this->workItem->Dispatch();
|
||||
this->pWorkItem->Dispatch();
|
||||
}
|
||||
|
||||
void IOProcessor::RemoveTimer()
|
||||
@ -612,13 +613,13 @@ namespace Aurora::IO
|
||||
|
||||
void IOProcessor::CancelWorkItem()
|
||||
{
|
||||
if (!this->workItem)
|
||||
if (!this->pWorkItem)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->workItem->Cancel();
|
||||
this->workItem.reset();
|
||||
this->pWorkItem->Cancel();
|
||||
this->pWorkItem.reset();
|
||||
}
|
||||
|
||||
void IOProcessor::RemoveLSTimer()
|
||||
@ -629,7 +630,7 @@ namespace Aurora::IO
|
||||
return;
|
||||
}
|
||||
|
||||
queue->SourceRemove(this->timers.lsTicker);
|
||||
queue->SourceRemove(this->timers.pLsTicker);
|
||||
}
|
||||
|
||||
bool IOProcessor::IsAsync()
|
||||
@ -643,13 +644,14 @@ namespace Aurora::IO
|
||||
this->timers.nbTicker.nextTriggerTime;
|
||||
}
|
||||
|
||||
bool IOProcessor::RequestRemovalForItemFromAnyThread(const AuSPtr<IIOProcessorItem> &processor)
|
||||
bool IOProcessor::RequestRemovalForItemFromAnyThread(const AuSPtr<IIOProcessorItem> &pProcessor)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
AuSPtr<IIOProcessorItem> IOProcessor::StartIOWatchEx(const AuSPtr<IIOWaitableItem>& object, const AuSPtr<IIOEventListener>& listener, bool singleshot)
|
||||
AuSPtr<IIOProcessorItem> IOProcessor::StartIOWatchEx(const AuSPtr<IIOWaitableItem> &pItem,
|
||||
const AuSPtr<IIOEventListener> &pListener,
|
||||
bool bSingleshot)
|
||||
{
|
||||
if (!CheckThread())
|
||||
{
|
||||
@ -657,16 +659,16 @@ namespace Aurora::IO
|
||||
}
|
||||
|
||||
auto item = AuMakeShared<IOProcessorItem>();
|
||||
item->parent = this;
|
||||
item->listener = listener;
|
||||
item->item = object;
|
||||
item->singleshot = singleshot;
|
||||
item->pParent = this;
|
||||
item->pListener = pListener;
|
||||
item->pItem = pItem;
|
||||
item->bSingleshot = bSingleshot;
|
||||
|
||||
AU_LOCK_GUARD(this->items.mutex);
|
||||
|
||||
this->items.allItems.push_back(item);
|
||||
|
||||
if (object->IsRunOnTick())
|
||||
if (pItem->IsRunOnTick())
|
||||
{
|
||||
if (!AuTryInsert(this->items.onTickReceivers, item))
|
||||
{
|
||||
@ -675,7 +677,7 @@ namespace Aurora::IO
|
||||
}
|
||||
}
|
||||
|
||||
if (object->IsRunOnOtherTick())
|
||||
if (pItem->IsRunOnOtherTick())
|
||||
{
|
||||
if (!AuTryInsert(this->items.onOtherReceivers, item))
|
||||
{
|
||||
@ -684,16 +686,16 @@ namespace Aurora::IO
|
||||
}
|
||||
}
|
||||
|
||||
if (object->IsRunOnSelfIO())
|
||||
if (pItem->IsRunOnSelfIO())
|
||||
{
|
||||
auto src = object->GetSelfIOSource();
|
||||
auto src = pItem->GetSelfIOSource();
|
||||
if (!src)
|
||||
{
|
||||
SysPushErrorGeneric();
|
||||
return {};
|
||||
}
|
||||
|
||||
auto timeout = object->IOTimeoutInMS();
|
||||
auto timeout = pItem->IOTimeoutInMS();
|
||||
if (timeout)
|
||||
{
|
||||
if (!this->ToQueue()->SourceAddWithTimeout(src, timeout))
|
||||
@ -790,7 +792,7 @@ namespace Aurora::IO
|
||||
|
||||
AuSPtr<AuLoop::ILoopQueue> IOProcessor::ToQueue()
|
||||
{
|
||||
return this->loopQueue;
|
||||
return this->pLoopQueue;
|
||||
}
|
||||
|
||||
void IOProcessor::ReleaseAllWatches()
|
||||
@ -806,7 +808,7 @@ namespace Aurora::IO
|
||||
|
||||
for (auto &io : this->items.registeredIO)
|
||||
{
|
||||
queue->SourceRemove(io->item->GetSelfIOSource());
|
||||
queue->SourceRemove(io->pItem->GetSelfIOSource());
|
||||
}
|
||||
|
||||
queue->Commit();
|
||||
|
@ -85,7 +85,7 @@ namespace Aurora::IO
|
||||
|
||||
bool RequestRemovalForItemFromAnyThread(const AuSPtr<IIOProcessorItem> &processor);
|
||||
|
||||
AuSPtr<AuLoop::ILoopQueue> loopQueue;
|
||||
AuSPtr<AuLoop::ILoopQueue> pLoopQueue;
|
||||
|
||||
AuUInt threadId;
|
||||
|
||||
@ -110,7 +110,7 @@ namespace Aurora::IO
|
||||
IOProcessorItems items;
|
||||
IOProcessorTimers timers;
|
||||
AuAsync::WorkerPId_t asyncWorker;
|
||||
AuSPtr<AuAsync::IWorkItem> workItem;
|
||||
AuSPtr<AuAsync::IWorkItem> pWorkItem;
|
||||
|
||||
AuThreadPrimitives::MutexUnique_t mutex;
|
||||
|
||||
|
@ -14,34 +14,34 @@ namespace Aurora::IO
|
||||
{
|
||||
bool IOProcessorItem::StopWatch()
|
||||
{
|
||||
if (this->parent->CheckThread() &&
|
||||
this->parent->bFrameStart)
|
||||
if (this->pParent->CheckThread() &&
|
||||
this->pParent->bFrameStart)
|
||||
{
|
||||
this->parent->ClearProcessor(AuSharedFromThis(), false);
|
||||
this->pParent->ClearProcessor(AuSharedFromThis(), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return this->parent->items.ScheduleFinish(AuSharedFromThis(), false);
|
||||
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), false);
|
||||
}
|
||||
|
||||
bool IOProcessorItem::FailWatch()
|
||||
{
|
||||
if (this->parent->CheckThread() &&
|
||||
this->parent->bFrameStart)
|
||||
if (this->pParent->CheckThread() &&
|
||||
this->pParent->bFrameStart)
|
||||
{
|
||||
this->parent->ClearProcessor(AuSharedFromThis(), true);
|
||||
this->pParent->ClearProcessor(AuSharedFromThis(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return this->parent->items.ScheduleFinish(AuSharedFromThis(), true);
|
||||
return this->pParent->items.ScheduleFinish(AuSharedFromThis(), true);
|
||||
}
|
||||
|
||||
|
||||
bool IOProcessorItem::OnFinished(const AuSPtr<AuLoop::ILoopSource>& source, AuUInt8 pos)
|
||||
{
|
||||
if (this->singleshot)
|
||||
if (this->bSingleshot)
|
||||
{
|
||||
if (AuExchange(this->triggered, true))
|
||||
if (AuExchange(this->bTriggered, true))
|
||||
{
|
||||
StopWatch();
|
||||
return false;
|
||||
@ -49,7 +49,7 @@ namespace Aurora::IO
|
||||
}
|
||||
|
||||
IOAlert(false);
|
||||
return this->singleshot;
|
||||
return this->bSingleshot;
|
||||
}
|
||||
|
||||
void IOProcessorItem::OnTimeout(const AuSPtr<AuLoop::ILoopSource>& source)
|
||||
@ -65,31 +65,31 @@ namespace Aurora::IO
|
||||
|
||||
void IOProcessorItem::IOAlert(bool force)
|
||||
{
|
||||
if (!this->parent->IsTickOnly())
|
||||
if (!this->pParent->IsTickOnly())
|
||||
{
|
||||
if (!this->parent->bFrameStart)
|
||||
if (!this->pParent->bFrameStart)
|
||||
{
|
||||
if (force)
|
||||
{
|
||||
this->parent->TickFor(AuSharedFromThis());
|
||||
this->pParent->TickFor(AuSharedFromThis());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->parent->TickForHack(AuSharedFromThis());
|
||||
this->pParent->TickForHack(AuSharedFromThis());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->parent->TickForRegister(AuSharedFromThis());
|
||||
this->pParent->TickForRegister(AuSharedFromThis());
|
||||
}
|
||||
}
|
||||
else if (force) // manual tick
|
||||
{
|
||||
if (this->parent->CheckThread())
|
||||
if (this->pParent->CheckThread())
|
||||
{
|
||||
this->parent->TickFor(AuSharedFromThis());
|
||||
this->pParent->TickFor(AuSharedFromThis());
|
||||
}
|
||||
else if (parent->IsAsync())
|
||||
else if (this->pParent->IsAsync())
|
||||
{
|
||||
// TODO:
|
||||
}
|
||||
@ -99,8 +99,7 @@ namespace Aurora::IO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (this->singleshot)
|
||||
if (this->bSingleshot)
|
||||
{
|
||||
StopWatch();
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ namespace Aurora::IO
|
||||
|
||||
struct IOProcessorItem : AuLoop::ILoopSourceSubscriberEx, IIOProcessorItem, AuEnableSharedFromThis<IOProcessorItem>
|
||||
{
|
||||
IOProcessor *parent;
|
||||
bool singleshot{};
|
||||
bool triggered{};
|
||||
IOProcessor *pParent;
|
||||
bool bSingleshot{};
|
||||
bool bTriggered{};
|
||||
|
||||
AuSPtr<IIOWaitableItem> item;
|
||||
AuSPtr<IIOEventListener> listener;
|
||||
AuSPtr<IIOWaitableItem> pItem;
|
||||
AuSPtr<IIOEventListener> pListener;
|
||||
|
||||
// ILoopSourceSubscriber
|
||||
bool OnFinished(const AuSPtr<AuLoop::ILoopSource> &source, AuUInt8 pos) override;
|
||||
@ -34,5 +34,4 @@ namespace Aurora::IO
|
||||
//
|
||||
void IOAlert(bool force);
|
||||
};
|
||||
|
||||
}
|
@ -12,16 +12,16 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
bool IOProcessorTimers::Init(IOProcessor *parent, AuSPtr<AuLoop::ITimer> lsTicker)
|
||||
bool IOProcessorTimers::Init(IOProcessor *pParent, AuSPtr<AuLoop::ITimer> pLsTicker)
|
||||
{
|
||||
this->parent = parent;
|
||||
this->lsTicker = lsTicker;
|
||||
return bool(this->parent) && bool(lsTicker);
|
||||
this->pParent = pParent;
|
||||
this->pLsTicker = pLsTicker;
|
||||
return bool(this->pParent) && bool(pLsTicker);
|
||||
}
|
||||
|
||||
bool IOProcessorTimers::OnFinished(const AuSPtr<AuLoop::ILoopSource> &source)
|
||||
bool IOProcessorTimers::OnFinished(const AuSPtr<AuLoop::ILoopSource> &pSource)
|
||||
{
|
||||
this->parent->ManualTick();
|
||||
this->pParent->ManualTick();
|
||||
return false;
|
||||
}
|
||||
}
|
@ -13,8 +13,8 @@ namespace Aurora::IO
|
||||
|
||||
struct IOProcessorTimers : AuLoop::ILoopSourceSubscriber
|
||||
{
|
||||
IOProcessor *parent {};
|
||||
AuSPtr<AuLoop::ITimer> lsTicker;
|
||||
IOProcessor *pParent {};
|
||||
AuSPtr<AuLoop::ITimer> pLsTicker;
|
||||
Utility::RateLimiter nbTicker;
|
||||
|
||||
bool Init(IOProcessor *parent, AuSPtr<AuLoop::ITimer> lsTicker);
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Aurora::IO
|
||||
{
|
||||
IOSimpleEventListener::IOSimpleEventListener(const AuSPtr<IIOSimpleEventListener> &parent) : parent(parent)
|
||||
IOSimpleEventListener::IOSimpleEventListener(const AuSPtr<IIOSimpleEventListener> &pParent) : pParent(pParent)
|
||||
{
|
||||
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace Aurora::IO
|
||||
|
||||
void IOSimpleEventListener::Tick_Any()
|
||||
{
|
||||
this->parent->OnIOTick();
|
||||
this->pParent->OnIOTick();
|
||||
}
|
||||
|
||||
void IOSimpleEventListener::Tick_FrameEpilogue()
|
||||
@ -43,21 +43,21 @@ namespace Aurora::IO
|
||||
|
||||
void IOSimpleEventListener::OnFailureCompletion()
|
||||
{
|
||||
this->parent->OnIOFailure();
|
||||
this->pParent->OnIOFailure();
|
||||
}
|
||||
|
||||
void IOSimpleEventListener::OnNominalCompletion()
|
||||
{
|
||||
this->parent->OnIOComplete();
|
||||
this->pParent->OnIOComplete();
|
||||
}
|
||||
|
||||
AuSPtr<IIOEventListener> DesimplifyIOEventListenerAdapter(const AuSPtr<IIOSimpleEventListener> &interface)
|
||||
AuSPtr<IIOEventListener> DesimplifyIOEventListenerAdapter(const AuSPtr<IIOSimpleEventListener> &pInterface)
|
||||
{
|
||||
if (!interface)
|
||||
if (!pInterface)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return AuMakeShared<IOSimpleEventListener>(interface);
|
||||
return AuMakeShared<IOSimpleEventListener>(pInterface);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Aurora::IO
|
||||
{
|
||||
struct IOSimpleEventListener : IIOEventListener
|
||||
{
|
||||
IOSimpleEventListener(const AuSPtr<IIOSimpleEventListener> &parent);
|
||||
IOSimpleEventListener(const AuSPtr<IIOSimpleEventListener> &pParent);
|
||||
|
||||
void Tick_RunOnTick() override;
|
||||
void Tick_OtherIOEvent() override;
|
||||
@ -21,6 +21,6 @@ namespace Aurora::IO
|
||||
void OnFailureCompletion() override;
|
||||
void OnNominalCompletion() override;
|
||||
|
||||
AuSPtr<IIOSimpleEventListener> parent;
|
||||
AuSPtr<IIOSimpleEventListener> pParent;
|
||||
};
|
||||
}
|
@ -77,12 +77,12 @@ namespace Aurora::IO::Net
|
||||
auto sharedThis = AuSPtr<SocketChannelInput>(this->pParent_->SharedFromThis(), this);
|
||||
|
||||
AuIO::IOPipeRequestAIO req;
|
||||
req.output.handleBufferedStream.onData = AuUnsafeRaiiToShared(this);
|
||||
req.output.handleBufferedStream.pOnData = AuUnsafeRaiiToShared(this);
|
||||
req.output.type = EPipeCallbackType::eTryHandleBufferedPart;
|
||||
req.asyncTransaction = this->pNetReadTransaction;
|
||||
req.isStream = true;
|
||||
req.listener = sharedThis;
|
||||
req.bufferLengthOrZero = AuStaticCast<SocketChannel>(this->pParent_->ToChannel())->uBytesInputBuffer;
|
||||
req.pAsyncTransaction = this->pNetReadTransaction;
|
||||
req.bIsStream = true;
|
||||
req.pListener = sharedThis;
|
||||
req.uBufferLengthOrZero = AuStaticCast<SocketChannel>(this->pParent_->ToChannel())->uBytesInputBuffer;
|
||||
this->pNetReader = this->pParent_->ToWorker()->ToProcessor()->ToPipeProcessor()->NewAIOPipe(req);
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ namespace Aurora::IO::Net
|
||||
this->pParent_->SendErrorNoStream({});
|
||||
return;
|
||||
}
|
||||
|
||||
this->pNetReadTransaction->SetCallback(sharedThis);//; AuSPtr<IAsyncFinishedSubscriber>(this->pParent_->SharedFromThis(), this));
|
||||
IncrementWorker();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user