Index: src/libchcore/OverlappedCallbacks.cpp =================================================================== diff -u -rbef894e38e5c1486824787cf8c47a87a0828b228 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/OverlappedCallbacks.cpp (.../OverlappedCallbacks.cpp) (revision bef894e38e5c1486824787cf8c47a87a0828b228) +++ src/libchcore/OverlappedCallbacks.cpp (.../OverlappedCallbacks.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -28,7 +28,7 @@ VOID CALLBACK OverlappedReadCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) { TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; - TOverlappedReaderWriter* pQueue = (TOverlappedReaderWriter*)pBuffer->GetParam(); + TOverlappedReader* pQueue = (TOverlappedReader*)pBuffer->GetParam(); // determine if this is the last packet bool bEof = (dwErrorCode == ERROR_HANDLE_EOF || @@ -50,20 +50,20 @@ if (pBuffer->HasError()) pQueue->AddFailedReadBuffer(pBuffer); else - pQueue->AddFinishedReadBuffer(pBuffer); + pQueue->AddFullBuffer(pBuffer); } VOID CALLBACK OverlappedWriteCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) { TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; - TOverlappedReaderWriter* pQueue = (TOverlappedReaderWriter*)pBuffer->GetParam(); + TOverlappedWriter* pQueue = (TOverlappedWriter*)pBuffer->GetParam(); pBuffer->SetErrorCode(dwErrorCode); pBuffer->SetBytesTransferred(dwNumberOfBytesTransfered); if (pBuffer->HasError()) pQueue->AddFailedWriteBuffer(pBuffer); else - pQueue->AddFinishedWriteBuffer(pBuffer); + pQueue->AddFinishedBuffer(pBuffer); } } Index: src/libchcore/TBufferList.h =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TBufferList.h (.../TBufferList.h) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TBufferList.h (.../TBufferList.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -39,7 +39,7 @@ size_t GetCount() const; bool IsEmpty() const; - void SetExpectedBuffers(size_t stExpectedBuffers) { m_stExpectedBuffers = stExpectedBuffers; } + void SetExpectedBuffersCount(size_t stExpectedBuffers) { m_stExpectedBuffers = stExpectedBuffers; } HANDLE GetAllBuffersAccountedForEvent() const { return m_eventAllBuffersAccountedFor.Handle(); } boost::signals2::signal& GetNotifier(); Index: src/libchcore/TOrderedBufferQueue.cpp =================================================================== diff -u -rc4cbf6cd567821f9a981586ab5d8294a26f873be -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOrderedBufferQueue.cpp (.../TOrderedBufferQueue.cpp) (revision c4cbf6cd567821f9a981586ab5d8294a26f873be) +++ src/libchcore/TOrderedBufferQueue.cpp (.../TOrderedBufferQueue.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -100,6 +100,11 @@ return m_setBuffers.empty(); } + bool TOrderedBufferQueue::HasPoppableBuffer() const + { + return !m_setBuffers.empty() && (*m_setBuffers.begin())->GetFilePosition() == m_ullExpectedBufferPosition; + } + HANDLE TOrderedBufferQueue::GetHasBuffersEvent() const { return m_eventHasBuffers.Handle(); @@ -132,13 +137,24 @@ void TOrderedBufferQueue::UpdateHasBuffers() { if(!m_setBuffers.empty() && (m_ullExpectedBufferPosition == NoPosition || (*m_setBuffers.begin())->GetFilePosition() == m_ullExpectedBufferPosition)) + { m_eventHasBuffers.SetEvent(); + m_notifier(true); + } else + { m_eventHasBuffers.ResetEvent(); + m_notifier(false); + } } void TOrderedBufferQueue::UpdateHasErrors() { m_eventHasError.SetEvent(m_pFirstErrorBuffer != nullptr); } + + boost::signals2::signal& TOrderedBufferQueue::GetNotifier() + { + return m_notifier; + } } Index: src/libchcore/TOrderedBufferQueue.h =================================================================== diff -u -r0882b2104d6868193cac6c57ba5d9be3ce9ffdec -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOrderedBufferQueue.h (.../TOrderedBufferQueue.h) (revision 0882b2104d6868193cac6c57ba5d9be3ce9ffdec) +++ src/libchcore/TOrderedBufferQueue.h (.../TOrderedBufferQueue.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -46,14 +46,16 @@ const TOverlappedDataBuffer* const Peek() const; size_t GetCount() const; - bool IsEmpty() const; + bool HasPoppableBuffer() const; HANDLE GetHasBuffersEvent() const; HANDLE GetHasErrorEvent() const; void ReleaseBuffers(const TBufferListPtr& spBuffers); + boost::signals2::signal& GetNotifier(); + private: bool IsBufferReady() const; void UpdateHasBuffers(); @@ -70,6 +72,8 @@ TEvent m_eventHasError; unsigned long long m_ullExpectedBufferPosition = 0; + + boost::signals2::signal m_notifier; }; template Index: src/libchcore/TOverlappedDataBuffer.h =================================================================== diff -u -r3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedDataBuffer.h (.../TOverlappedDataBuffer.h) (revision 3ccbdb8d3eac3427e6d3354854476e57fdc7ceb9) +++ src/libchcore/TOverlappedDataBuffer.h (.../TOverlappedDataBuffer.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -27,10 +27,10 @@ { class TOverlappedDataBuffer; - struct CompareBufferPositions - { - bool operator()(const TOverlappedDataBuffer* rBufferA, const TOverlappedDataBuffer* rBufferB) const; - }; + struct CompareBufferPositions + { + bool operator()(const TOverlappedDataBuffer* rBufferA, const TOverlappedDataBuffer* rBufferB) const; + }; class TOverlappedDataBuffer : public OVERLAPPED { Index: src/libchcore/TOverlappedMemoryPool.cpp =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedMemoryPool.cpp (.../TOverlappedMemoryPool.cpp) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedMemoryPool.cpp (.../TOverlappedMemoryPool.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -54,7 +54,7 @@ // buffer sizes increased - clear current buffers and proceed with creating new ones m_listAllBuffers.clear(); m_spQueueBuffers->Clear(); - m_spQueueBuffers->SetExpectedBuffers(0); + m_spQueueBuffers->SetExpectedBuffersCount(0); } else if (stCount == m_listAllBuffers.size()) return; // nothing really changed @@ -73,7 +73,7 @@ m_spQueueBuffers->Push(upElement.get()); } - m_spQueueBuffers->SetExpectedBuffers(m_listAllBuffers.size()); + m_spQueueBuffers->SetExpectedBuffersCount(m_listAllBuffers.size()); return; } @@ -85,7 +85,7 @@ m_listAllBuffers.push_back(std::move(upBuffer)); } - m_spQueueBuffers->SetExpectedBuffers(m_listAllBuffers.size()); + m_spQueueBuffers->SetExpectedBuffersCount(m_listAllBuffers.size()); } size_t TOverlappedMemoryPool::GetTotalBufferCount() const Index: src/libchcore/TOverlappedMemoryPool.h =================================================================== diff -u -r6c41e7b3cf7711c6f5027c0c0154013f50f08e7b -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedMemoryPool.h (.../TOverlappedMemoryPool.h) (revision 6c41e7b3cf7711c6f5027c0c0154013f50f08e7b) +++ src/libchcore/TOverlappedMemoryPool.h (.../TOverlappedMemoryPool.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -19,7 +19,6 @@ #ifndef __TOVERLAPPEDDATABUFFERQUEUE_H__ #define __TOVERLAPPEDDATABUFFERQUEUE_H__ -#include "TEvent.h" #include "TBufferList.h" namespace chcore Index: src/libchcore/TOverlappedReader.cpp =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -48,7 +48,10 @@ if(m_bReleaseMode) return nullptr; - return m_tInputBuffers.Pop(); + TOverlappedDataBuffer* pBuffer = m_tInputBuffers.Pop(); + if (pBuffer) + pBuffer->SetParam(this); + return pBuffer; } void TOverlappedReader::AddEmptyBuffer(TOverlappedDataBuffer* pBuffer, bool bKeepPosition) @@ -60,7 +63,14 @@ m_tInputBuffers.Push(pBuffer, false); else { - LOG_TRACE(m_spLog) << L"Releasing empty buffer; buffer-order: " << pBuffer->GetFilePosition(); + LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as empty; buffer-order: " << pBuffer->GetFilePosition() << + L", requested-data-size: " << pBuffer->GetRequestedDataSize() << + L", real-data-size: " << pBuffer->GetRealDataSize() << + L", file-position: " << pBuffer->GetFilePosition() << + L", error-code: " << pBuffer->GetErrorCode() << + L", status-code: " << pBuffer->GetStatusCode() << + L", is-last-part: " << pBuffer->IsLastPart(); + m_tInputBuffers.Push(pBuffer, bKeepPosition); } } @@ -74,7 +84,14 @@ m_tInputBuffers.Push(pBuffer, false); else { - LOG_TRACE(m_spLog) << L"Queuing buffer for re-read; buffer-order: " << pBuffer->GetFilePosition(); + LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as failed-read; buffer-order: " << pBuffer->GetFilePosition() << + L", requested-data-size: " << pBuffer->GetRequestedDataSize() << + L", real-data-size: " << pBuffer->GetRealDataSize() << + L", file-position: " << pBuffer->GetFilePosition() << + L", error-code: " << pBuffer->GetErrorCode() << + L", status-code: " << pBuffer->GetStatusCode() << + L", is-last-part: " << pBuffer->IsLastPart(); + m_spFullBuffers->PushError(pBuffer, m_tInputBuffers); } } @@ -84,7 +101,11 @@ if(m_bReleaseMode) return nullptr; - return m_spFullBuffers->PopError(); + TOverlappedDataBuffer* pBuffer = m_spFullBuffers->PopError(); + if (pBuffer) + pBuffer->SetParam(this); + + return pBuffer; } void TOverlappedReader::AddFullBuffer(TOverlappedDataBuffer* pBuffer) @@ -98,7 +119,7 @@ } else { - LOG_TRACE(m_spLog) << L"Queuing buffer as full; buffer-order: " << pBuffer->GetFilePosition() << + LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as finished-read; buffer-order: " << pBuffer->GetFilePosition() << L", requested-data-size: " << pBuffer->GetRequestedDataSize() << L", real-data-size: " << pBuffer->GetRealDataSize() << L", file-position: " << pBuffer->GetFilePosition() << Index: src/libchcore/TOverlappedReader.h =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedReader.h (.../TOverlappedReader.h) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedReader.h (.../TOverlappedReader.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -28,9 +28,6 @@ { class TOverlappedReader { - private: - static const unsigned long long NoIoError = 0xffffffffffffffff; - public: explicit TOverlappedReader(const logger::TLogFileDataPtr& spLogFileData, const TBufferListPtr& spEmptyBuffers, unsigned long long ullFilePos, DWORD dwChunkSize); @@ -70,6 +67,8 @@ bool m_bReleaseMode = false; // when set, all incoming buffers will go to empty buffers }; + + using TOverlappedReaderPtr = std::shared_ptr; } #endif Index: src/libchcore/TOverlappedReaderWriter.cpp =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedReaderWriter.cpp (.../TOverlappedReaderWriter.cpp) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedReaderWriter.cpp (.../TOverlappedReaderWriter.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -30,9 +30,8 @@ unsigned long long ullFilePos, DWORD dwChunkSize) : m_spLog(logger::MakeLogger(spLogFileData, L"DataBuffer")), m_spMemoryPool(spMemoryPool), - m_tReader(spLogFileData, spMemoryPool->GetBufferList(), ullFilePos, dwChunkSize), - m_tWriter(spLogFileData, m_tReader.GetFinishedQueue(), ullFilePos, spMemoryPool->GetBufferList()), - m_eventAllBuffersAccountedFor(true, true) + m_spReader(std::make_shared(spLogFileData, spMemoryPool->GetBufferList(), ullFilePos, dwChunkSize)), + m_spWriter(std::make_shared(spLogFileData, m_spReader->GetFinishedQueue(), ullFilePos, spMemoryPool->GetBufferList())) { if(!spMemoryPool) throw TCoreException(eErr_InvalidArgument, L"spMemoryPool", LOCATION); @@ -42,141 +41,10 @@ { } - TOverlappedDataBuffer* TOverlappedReaderWriter::GetEmptyBuffer() - { - TOverlappedDataBuffer* pBuffer = m_tReader.GetEmptyBuffer(); - if(pBuffer) - pBuffer->SetParam(this); - - return pBuffer; - } - - void TOverlappedReaderWriter::AddEmptyBuffer(TOverlappedDataBuffer* pBuffer, bool bKeepPosition) - { - if(!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as empty; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - - m_tReader.AddEmptyBuffer(pBuffer, bKeepPosition); - } - - TOverlappedDataBuffer* TOverlappedReaderWriter::GetFailedReadBuffer() - { - return m_tReader.GetFailedReadBuffer(); - } - - void TOverlappedReaderWriter::AddFailedReadBuffer(TOverlappedDataBuffer* pBuffer) - { - if(!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as failed-read; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - - m_tReader.AddFailedReadBuffer(pBuffer); - } - - TOverlappedDataBuffer* TOverlappedReaderWriter::GetWriteBuffer() - { - TOverlappedDataBuffer* pBuffer = m_tWriter.GetWriteBuffer(); - - if(pBuffer) - pBuffer->SetParam(this); - - return pBuffer; - } - - void TOverlappedReaderWriter::AddFinishedReadBuffer(TOverlappedDataBuffer* pBuffer) - { - if(!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as finished-read; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - m_tReader.AddFullBuffer(pBuffer); - } - - TOverlappedDataBuffer* TOverlappedReaderWriter::GetFailedWriteBuffer() - { - return m_tWriter.GetFailedWriteBuffer(); - } - - void TOverlappedReaderWriter::AddFailedWriteBuffer(TOverlappedDataBuffer* pBuffer) - { - if(!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as failed-write; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - - // overwrite error code (to avoid treating the buffer as failed read) - pBuffer->SetErrorCode(ERROR_SUCCESS); - m_tWriter.AddFailedWriteBuffer(pBuffer); - } - - TOverlappedDataBuffer* TOverlappedReaderWriter::GetFinishedWriteBuffer() - { - return m_tWriter.GetFinishedBuffer(); - } - - void TOverlappedReaderWriter::AddFinishedWriteBuffer(TOverlappedDataBuffer* pBuffer) - { - if (!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as finished-write; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - - m_tWriter.AddFinishedBuffer(pBuffer); - } - - void TOverlappedReaderWriter::MarkFinishedBufferAsComplete(TOverlappedDataBuffer* pBuffer) - { - if(!pBuffer) - throw TCoreException(eErr_InvalidPointer, L"pBuffer", LOCATION); - - LOG_TRACE(m_spLog) << L"Marking buffer " << pBuffer << L" as finalized-write; buffer-order: " << pBuffer->GetFilePosition() << - L", requested-data-size: " << pBuffer->GetRequestedDataSize() << - L", real-data-size: " << pBuffer->GetRealDataSize() << - L", file-position: " << pBuffer->GetFilePosition() << - L", error-code: " << pBuffer->GetErrorCode() << - L", status-code: " << pBuffer->GetStatusCode() << - L", is-last-part: " << pBuffer->IsLastPart(); - - m_tWriter.MarkAsFinalized(pBuffer); - } - void TOverlappedReaderWriter::WaitForMissingBuffersAndResetState(HANDLE hKillEvent) { - m_tReader.ReleaseBuffers(); - m_tWriter.ReleaseBuffers(); + m_spReader->ReleaseBuffers(); + m_spWriter->ReleaseBuffers(); enum { eKillThread = 0, eAllBuffersReturned, eHandleCount }; std::array arrHandles = { hKillEvent, m_spMemoryPool->GetBufferList()->GetAllBuffersAccountedForEvent() }; Index: src/libchcore/TOverlappedReaderWriter.h =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedReaderWriter.h (.../TOverlappedReaderWriter.h) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedReaderWriter.h (.../TOverlappedReaderWriter.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -19,7 +19,6 @@ #ifndef __TOVERLAPPEDREADERWRITER_H__ #define __TOVERLAPPEDREADERWRITER_H__ -#include "TEvent.h" #include "../liblogger/TLogFileData.h" #include "../liblogger/TLogger.h" #include "TOverlappedMemoryPool.h" @@ -30,9 +29,6 @@ { class TOverlappedReaderWriter { - private: - static const unsigned long long NoIoError = 0xffffffffffffffff; - public: explicit TOverlappedReaderWriter(const logger::TLogFileDataPtr& spLogFileData, const TOverlappedMemoryPoolPtr& spBuffers, unsigned long long ullFilePos, DWORD dwChunkSize); @@ -41,49 +37,19 @@ TOverlappedReaderWriter& operator=(const TOverlappedReaderWriter&) = delete; - // buffer management - reader - TOverlappedDataBuffer* GetEmptyBuffer(); - void AddEmptyBuffer(TOverlappedDataBuffer* pBuffer, bool bKeepPosition); + // reader/writer + TOverlappedReaderPtr GetReader() const { return m_spReader; } + TOverlappedWriterPtr GetWriter() const { return m_spWriter; } - TOverlappedDataBuffer* GetFailedReadBuffer(); - void AddFailedReadBuffer(TOverlappedDataBuffer* pBuffer); - - void AddFinishedReadBuffer(TOverlappedDataBuffer* pBuffer); - - // buffer management - writer - TOverlappedDataBuffer* GetWriteBuffer(); - - TOverlappedDataBuffer* GetFailedWriteBuffer(); - void AddFailedWriteBuffer(TOverlappedDataBuffer* pBuffer); - - void AddFinishedWriteBuffer(TOverlappedDataBuffer* pBuffer); - TOverlappedDataBuffer* GetFinishedWriteBuffer(); - - void MarkFinishedBufferAsComplete(TOverlappedDataBuffer* pBuffer); - - // processing info - bool IsDataSourceFinished() const { return m_tReader.IsDataSourceFinished(); } - // event access - HANDLE GetEventReadPossibleHandle() const { return m_tReader.GetEventReadPossibleHandle(); } - HANDLE GetEventReadFailedHandle() const { return m_tReader.GetEventReadFailedHandle(); } - HANDLE GetEventWritePossibleHandle() const { return m_tReader.GetEventReadFinishedHandle(); } - - HANDLE GetEventWriteFailedHandle() const { return m_tWriter.GetEventWriteFailedHandle(); } - HANDLE GetEventWriteFinishedHandle() const { return m_tWriter.GetEventWriteFinishedHandle(); } - - HANDLE GetEventAllBuffersAccountedFor() const { return m_eventAllBuffersAccountedFor.Handle(); } - void WaitForMissingBuffersAndResetState(HANDLE hKillEvent); private: logger::TLoggerPtr m_spLog; TOverlappedMemoryPoolPtr m_spMemoryPool; - TOverlappedReader m_tReader; - TOverlappedWriter m_tWriter; - - TEvent m_eventAllBuffersAccountedFor; + TOverlappedReaderPtr m_spReader; + TOverlappedWriterPtr m_spWriter; }; } Index: src/libchcore/TOverlappedWriter.cpp =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedWriter.cpp (.../TOverlappedWriter.cpp) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedWriter.cpp (.../TOverlappedWriter.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -49,7 +49,11 @@ if(m_bReleaseMode) return nullptr; - return m_tBuffersToWrite.Pop(); + TOverlappedDataBuffer* pBuffer = m_tBuffersToWrite.Pop(); + if (pBuffer) + pBuffer->SetParam(this); + + return pBuffer; } void TOverlappedWriter::AddFailedWriteBuffer(TOverlappedDataBuffer* pBuffer) @@ -61,7 +65,7 @@ m_spEmptyBuffers->Push(pBuffer); else { - LOG_TRACE(m_spLog) << L"Queuing buffer as full (failed); buffer-order: " << pBuffer->GetFilePosition() << + LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as failed-write; buffer-order: " << pBuffer->GetFilePosition() << L", requested-data-size: " << pBuffer->GetRequestedDataSize() << L", real-data-size: " << pBuffer->GetRealDataSize() << L", file-position: " << pBuffer->GetFilePosition() << @@ -81,7 +85,11 @@ if(m_bReleaseMode) return nullptr; - return m_tFinishedBuffers.PopError(); + TOverlappedDataBuffer* pBuffer = m_tFinishedBuffers.PopError(); + if (pBuffer) + pBuffer->SetParam(this); + + return pBuffer; } TOverlappedDataBuffer* TOverlappedWriter::GetFinishedBuffer() @@ -91,11 +99,16 @@ TOverlappedDataBuffer* pBuffer = m_tFinishedBuffers.Pop(); - if (pBuffer && pBuffer->IsLastPart()) + if (pBuffer) { - if (m_pLastPartBuffer != nullptr) - throw TCoreException(eErr_InternalProblem, L"Encountered another 'last-part' finished buffer", LOCATION); - m_pLastPartBuffer = pBuffer; + if(pBuffer->IsLastPart()) + { + if (m_pLastPartBuffer != nullptr) + throw TCoreException(eErr_InternalProblem, L"Encountered another 'last-part' finished buffer", LOCATION); + m_pLastPartBuffer = pBuffer; + } + + pBuffer->SetParam(this); } return pBuffer; @@ -112,6 +125,14 @@ if (pBuffer != m_pLastPartBuffer) throw TCoreException(eErr_InvalidArgument, L"Trying to mark different buffer as finalized", LOCATION); + LOG_TRACE(m_spLog) << L"Marking buffer " << pBuffer << L" as finalized-write; buffer-order: " << pBuffer->GetFilePosition() << + L", requested-data-size: " << pBuffer->GetRequestedDataSize() << + L", real-data-size: " << pBuffer->GetRealDataSize() << + L", file-position: " << pBuffer->GetFilePosition() << + L", error-code: " << pBuffer->GetErrorCode() << + L", status-code: " << pBuffer->GetStatusCode() << + L", is-last-part: " << pBuffer->IsLastPart(); + m_pLastPartBuffer = nullptr; } @@ -124,7 +145,7 @@ m_spEmptyBuffers->Push(pBuffer); else { - LOG_TRACE(m_spLog) << L"Queuing buffer as finished; buffer-order: " << pBuffer->GetFilePosition() << + LOG_TRACE(m_spLog) << L"Queuing buffer " << pBuffer << L" as finished-write; buffer-order: " << pBuffer->GetFilePosition() << L", requested-data-size: " << pBuffer->GetRequestedDataSize() << L", real-data-size: " << pBuffer->GetRealDataSize() << L", file-position: " << pBuffer->GetFilePosition() << Index: src/libchcore/TOverlappedWriter.h =================================================================== diff -u -r593ca68706f3a3c7c2a3820b02a56fc24d5bea11 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TOverlappedWriter.h (.../TOverlappedWriter.h) (revision 593ca68706f3a3c7c2a3820b02a56fc24d5bea11) +++ src/libchcore/TOverlappedWriter.h (.../TOverlappedWriter.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -29,9 +29,6 @@ { class TOverlappedWriter { - private: - static const unsigned long long NoIoError = 0xffffffffffffffff; - public: explicit TOverlappedWriter(const logger::TLogFileDataPtr& spLogFileData, const TOrderedBufferQueuePtr& spBuffersToWrite, unsigned long long ullFilePos, const TBufferListPtr& spEmptyBuffers); @@ -71,6 +68,8 @@ bool m_bReleaseMode = false; }; + + using TOverlappedWriterPtr = std::shared_ptr; } #endif Index: src/libchcore/TSubTaskCopyMove.cpp =================================================================== diff -u -r6c41e7b3cf7711c6f5027c0c0154013f50f08e7b -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 6c41e7b3cf7711c6f5027c0c0154013f50f08e7b) +++ src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -391,11 +391,11 @@ }; std::array arrHandles = { rThreadController.GetKillThreadHandle(), - tReaderWriter.GetEventWriteFinishedHandle(), - tReaderWriter.GetEventWriteFailedHandle(), - tReaderWriter.GetEventWritePossibleHandle(), - tReaderWriter.GetEventReadFailedHandle(), - tReaderWriter.GetEventReadPossibleHandle() + tReaderWriter.GetWriter()->GetEventWriteFinishedHandle(), + tReaderWriter.GetWriter()->GetEventWriteFailedHandle(), + tReaderWriter.GetWriter()->GetEventWritePossibleHandle(), + tReaderWriter.GetReader()->GetEventReadFailedHandle(), + tReaderWriter.GetReader()->GetEventReadPossibleHandle() }; bool bStopProcessing = false; @@ -410,11 +410,8 @@ case WAIT_OBJECT_0 + eKillThread: { // log - TString strFormat; - strFormat = _T("Kill request while main copying file %srcpath -> %dstpath"); - strFormat.Replace(_T("%srcpath"), pData->spSrcFile->GetFullFilePath().ToString()); - strFormat.Replace(_T("%dstpath"), pData->pathDstFile.ToString()); - LOG_INFO(m_spLog) << strFormat.c_str(); + LOG_INFO(m_spLog) << L"Kill request while main copying file " << pData->spSrcFile->GetFullFilePath().ToString() << + L" -> " << pData->pathDstFile.ToString(); eResult = TSubTaskBase::eSubResult_KillRequest; bStopProcessing = true; @@ -423,19 +420,19 @@ case WAIT_OBJECT_0 + eReadPossible: { - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetEmptyBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); if (!pBuffer) throw TCoreException(eErr_InternalProblem, L"Read was possible, but no buffer is available", LOCATION); eResult = srcFileWrapper.ReadFileFB(*pBuffer, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); bStopProcessing = true; } else if(bSkip) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -446,22 +443,22 @@ } case WAIT_OBJECT_0 + eReadFailed: { - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetFailedReadBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetFailedReadBuffer(); if (!pBuffer) throw TCoreException(eErr_InternalProblem, L"Cannot retrieve failed read buffer", LOCATION); // read error encountered - handle it eResult = HandleReadError(spFeedbackHandler, *pBuffer, pData->spSrcFile->GetFullFilePath(), bSkip); if(eResult == TSubTaskBase::eSubResult_Retry) - tReaderWriter.AddEmptyBuffer(pBuffer, true); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, true); else if(eResult != TSubTaskBase::eSubResult_Continue) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); bStopProcessing = true; } else if(bSkip) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -473,19 +470,19 @@ } case WAIT_OBJECT_0 + eWritePossible: { - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriteBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriter()->GetWriteBuffer(); if (!pBuffer) throw TCoreException(eErr_InternalProblem, L"Write was possible, but no buffer is available", LOCATION); eResult = dstFileWrapper.WriteFileFB(*pBuffer, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); bStopProcessing = true; } else if(bSkip) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -498,21 +495,21 @@ case WAIT_OBJECT_0 + eWriteFailed: { - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetFailedWriteBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriter()->GetFailedWriteBuffer(); if (!pBuffer) throw TCoreException(eErr_InternalProblem, L"Failed to retrieve write failed buffer", LOCATION); eResult = HandleWriteError(spFeedbackHandler, *pBuffer, pData->pathDstFile, bSkip); if(eResult == TSubTaskBase::eSubResult_Retry) - tReaderWriter.AddFailedWriteBuffer(pBuffer); + tReaderWriter.GetWriter()->AddFailedWriteBuffer(pBuffer); else if(eResult != TSubTaskBase::eSubResult_Continue) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); bStopProcessing = true; } else if(bSkip) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -525,7 +522,7 @@ case WAIT_OBJECT_0 + eWriteFinished: { - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetFinishedWriteBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); if (!pBuffer) throw TCoreException(eErr_InternalProblem, L"Write finished was possible, but no buffer is available", LOCATION); @@ -534,13 +531,13 @@ eResult = dstFileWrapper.FinalizeFileFB(*pBuffer, bSkip); if (eResult != TSubTaskBase::eSubResult_Continue) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); bStopProcessing = true; break; } else if (bSkip) { - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -559,7 +556,7 @@ bStopProcessing = pBuffer->IsLastPart(); if(bStopProcessing) { - tReaderWriter.MarkFinishedBufferAsComplete(pBuffer); + tReaderWriter.GetWriter()->MarkAsFinalized(pBuffer); // this is the end of copying of src file - in case it is smaller than expected fix the stats so that difference is accounted for AdjustFinalSize(pData->spSrcFile, fileSrc); @@ -568,7 +565,7 @@ m_tSubTaskStats.ResetCurrentItemProcessedSize(); } - tReaderWriter.AddEmptyBuffer(pBuffer, false); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffer, false); break; } Index: src/libchcore/TWriteBufferQueueWrapper.cpp =================================================================== diff -u -rda7737de7046ba0ecd255240fb36b4a46584ebf2 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TWriteBufferQueueWrapper.cpp (.../TWriteBufferQueueWrapper.cpp) (revision da7737de7046ba0ecd255240fb36b4a46584ebf2) +++ src/libchcore/TWriteBufferQueueWrapper.cpp (.../TWriteBufferQueueWrapper.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -31,8 +31,15 @@ throw TCoreException(eErr_InvalidArgument, L"spQueue is NULL", LOCATION); UpdateHasBuffers(); + + m_emptyBuffersQueueConnector = m_spDataQueue->GetNotifier().connect(boost::bind(&TWriteBufferQueueWrapper::UpdateHasBuffers, this, _1)); } + TWriteBufferQueueWrapper::~TWriteBufferQueueWrapper() + { + m_emptyBuffersQueueConnector.disconnect(); + } + void TWriteBufferQueueWrapper::Push(TOverlappedDataBuffer* pBuffer) { if (!pBuffer) @@ -72,7 +79,7 @@ bool TWriteBufferQueueWrapper::IsBufferReady() const { - return !m_tClaimedQueue.empty() || !m_spDataQueue->IsEmpty(); + return !m_tClaimedQueue.empty() || m_spDataQueue->HasPoppableBuffer(); } size_t TWriteBufferQueueWrapper::GetCount() const Index: src/libchcore/TWriteBufferQueueWrapper.h =================================================================== diff -u -rda7737de7046ba0ecd255240fb36b4a46584ebf2 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/TWriteBufferQueueWrapper.h (.../TWriteBufferQueueWrapper.h) (revision da7737de7046ba0ecd255240fb36b4a46584ebf2) +++ src/libchcore/TWriteBufferQueueWrapper.h (.../TWriteBufferQueueWrapper.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -32,6 +32,7 @@ { public: TWriteBufferQueueWrapper(const TOrderedBufferQueuePtr& spQueue); + ~TWriteBufferQueueWrapper(); void Push(TOverlappedDataBuffer* pBuffer, bool /*bKeepPosition*/) { Push(pBuffer); } void Push(TOverlappedDataBuffer* pBuffer); @@ -46,10 +47,13 @@ private: bool IsBufferReady() const; void UpdateHasBuffers(); + void UpdateHasBuffers(bool /*bAdded*/) { UpdateHasBuffers(); } TOverlappedDataBuffer* InternalPop(); private: TOrderedBufferQueuePtr m_spDataQueue; // external queue of buffers to use + boost::signals2::connection m_emptyBuffersQueueConnector; + TSimpleOrderedBufferQueue m_tClaimedQueue; // internal queue of claimed buffers TEvent m_eventHasBuffers; Index: src/libchcore/Tests/OverlappedCallbacksTests.cpp =================================================================== diff -u -rbef894e38e5c1486824787cf8c47a87a0828b228 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/Tests/OverlappedCallbacksTests.cpp (.../OverlappedCallbacksTests.cpp) (revision bef894e38e5c1486824787cf8c47a87a0828b228) +++ src/libchcore/Tests/OverlappedCallbacksTests.cpp (.../OverlappedCallbacksTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -13,28 +13,27 @@ logger::TLogFileDataPtr spLogData(std::make_shared()); TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); - TOverlappedReaderWriter queue(spLogData, spBuffers, 0, 4096); + TOverlappedReader queue(spLogData, spBuffers->GetBufferList(), 0, 4096); TOverlappedDataBuffer buffer(16384, &queue); buffer.InitForRead(0, 1024); buffer.SetStatusCode(0); buffer.SetBytesTransferred(234); + buffer.SetParam(&queue); OverlappedReadCompleted(ERROR_SUCCESS, 234, &buffer); EXPECT_TRUE(buffer.IsLastPart()); EXPECT_EQ(ERROR_SUCCESS, buffer.GetErrorCode()); EXPECT_EQ(234, buffer.GetRealDataSize()); - - EXPECT_EQ(queue.GetWriteBuffer(), &buffer); } TEST(OverlappedCallbackTests, OverlappedReadCompleted_Failure) { logger::TLogFileDataPtr spLogData(std::make_shared()); TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); - TOverlappedReaderWriter queue(spLogData, spBuffers, 0, 4096); + TOverlappedReader queue(spLogData, spBuffers->GetBufferList(), 0, 4096); TOverlappedDataBuffer buffer(16384, &queue); buffer.InitForRead(0, 1024); @@ -55,7 +54,8 @@ logger::TLogFileDataPtr spLogData(std::make_shared()); TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); - TOverlappedReaderWriter queue(spLogData, spBuffers, 0, 4096); + TOrderedBufferQueuePtr spBuffersToWrite(std::make_shared(0)); + TOverlappedWriter queue(spLogData, spBuffersToWrite, 0, spBuffers->GetBufferList()); TOverlappedDataBuffer buffer(16384, &queue); buffer.InitForRead(0, 1024); @@ -67,5 +67,5 @@ OverlappedWriteCompleted(ERROR_SUCCESS, 234, &buffer); EXPECT_EQ(ERROR_SUCCESS, buffer.GetErrorCode()); - EXPECT_EQ(queue.GetFinishedWriteBuffer(), &buffer); + EXPECT_EQ(queue.GetFinishedBuffer(), &buffer); } Index: src/libchcore/Tests/TOrderedBufferQueueTests.cpp =================================================================== diff -u -rc4cbf6cd567821f9a981586ab5d8294a26f873be -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/Tests/TOrderedBufferQueueTests.cpp (.../TOrderedBufferQueueTests.cpp) (revision c4cbf6cd567821f9a981586ab5d8294a26f873be) +++ src/libchcore/Tests/TOrderedBufferQueueTests.cpp (.../TOrderedBufferQueueTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -207,22 +207,6 @@ EXPECT_THROW(queue.PushError(&buffer1, collection), TCoreException); } -TEST(TOrderedBufferQueueTests, PushBuffer_WithSamePosition) -{ - TOrderedBufferQueue queue(0); - TOverlappedDataBuffer buffer1(4096, nullptr); - TOverlappedDataBuffer buffer2(4096, nullptr); - buffer1.SetFilePosition(1000); - buffer1.SetErrorCode(123); - buffer2.SetFilePosition(1000); - buffer2.SetErrorCode(234); - - FallbackCollection collection; - - queue.PushError(&buffer1, collection); - EXPECT_THROW(queue.PushError(&buffer2, collection), TCoreException); -} - ///////////////////////////////////////////////////////////////////////////////////////// // Pop tests Index: src/libchcore/Tests/TOverlappedReaderWriterTests.cpp =================================================================== diff -u -rbef894e38e5c1486824787cf8c47a87a0828b228 -rb941384e121190b6107f1c99b3233667e3daf4ce --- src/libchcore/Tests/TOverlappedReaderWriterTests.cpp (.../TOverlappedReaderWriterTests.cpp) (revision bef894e38e5c1486824787cf8c47a87a0828b228) +++ src/libchcore/Tests/TOverlappedReaderWriterTests.cpp (.../TOverlappedReaderWriterTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) @@ -9,27 +9,26 @@ using namespace chcore; - TEST(TOverlappedReaderWriterTests, DefaultConstructor_SanityTest) { logger::TLogFileDataPtr spLogData(std::make_shared()); TOverlappedMemoryPoolPtr spBuffers(std::make_shared()); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_EQ(nullptr, tReaderWriter.GetEmptyBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriteBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetFinishedWriteBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - EXPECT_NE(nullptr, tReaderWriter.GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEventWritePossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEventWriteFinishedHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetEventReadPossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetEventWriteFinishedHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - EXPECT_FALSE(tReaderWriter.IsDataSourceFinished()); + EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); // EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); EXPECT_EQ(0, spBuffers->GetTotalBufferCount()); @@ -43,19 +42,19 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_NE(nullptr, tReaderWriter.GetEmptyBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetWriteBuffer()); - EXPECT_EQ(nullptr, tReaderWriter.GetFinishedWriteBuffer()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - EXPECT_NE(nullptr, tReaderWriter.GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEventWritePossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEventWriteFinishedHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); - EXPECT_TIMEOUT(tReaderWriter.GetEventWriteFinishedHandle()); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - EXPECT_FALSE(tReaderWriter.IsDataSourceFinished()); + EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); // EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); } @@ -65,7 +64,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); @@ -83,7 +82,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - tReaderWriter.GetEmptyBuffer(); + tReaderWriter.GetReader()->GetEmptyBuffer(); EXPECT_THROW(spBuffers->ReinitializeBuffers(3, 65536), TCoreException); } @@ -106,7 +105,7 @@ TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); spBuffers->ReinitializeBuffers(3, 32768); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); @@ -124,7 +123,7 @@ TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); spBuffers->ReinitializeBuffers(3, 65536); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); EXPECT_EQ(65536, spBuffers->GetSingleBufferSize()); @@ -142,7 +141,7 @@ TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); spBuffers->ReinitializeBuffers(3, 32768); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); @@ -163,7 +162,7 @@ EXPECT_EQ(5, spBuffers->GetTotalBufferCount()); EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - TOverlappedDataBuffer* pBuffers[5] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[5] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); @@ -183,7 +182,7 @@ EXPECT_EQ(3, spBuffers->GetTotalBufferCount()); EXPECT_EQ(32768, spBuffers->GetSingleBufferSize()); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; EXPECT_EQ(32768, pBuffers[0]->GetBufferSize()); EXPECT_EQ(32768, pBuffers[1]->GetBufferSize()); @@ -198,18 +197,18 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEmptyBuffer()); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEmptyBuffer()); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_NE(nullptr, tReaderWriter.GetEmptyBuffer()); - EXPECT_TIMEOUT(tReaderWriter.GetEventReadPossibleHandle()); + EXPECT_NE(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); + EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - EXPECT_EQ(nullptr, tReaderWriter.GetEmptyBuffer()); + EXPECT_EQ(nullptr, tReaderWriter.GetReader()->GetEmptyBuffer()); } TEST(TOverlappedReaderWriterTests, AddEmptyBuffer) @@ -219,18 +218,18 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - EXPECT_TIMEOUT(tReaderWriter.GetEventReadPossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - tReaderWriter.AddEmptyBuffer(pBuffers[0], false); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[0], false); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - tReaderWriter.AddEmptyBuffer(pBuffers[1], false); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[1], false); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); - tReaderWriter.AddEmptyBuffer(pBuffers[2], false); - EXPECT_SIGNALED(tReaderWriter.GetEventReadPossibleHandle()); + tReaderWriter.GetReader()->AddEmptyBuffer(pBuffers[2], false); + EXPECT_SIGNALED(tReaderWriter.GetReader()->GetEventReadPossibleHandle()); } TEST(TOverlappedReaderWriterTests, AddEmptyBuffer_Null) @@ -240,7 +239,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_THROW(tReaderWriter.AddEmptyBuffer(nullptr, false), TCoreException); + EXPECT_THROW(tReaderWriter.GetReader()->AddEmptyBuffer(nullptr, false), TCoreException); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -250,13 +249,13 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetEmptyBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); - tReaderWriter.AddFinishedReadBuffer(pBuffer); - EXPECT_SIGNALED(tReaderWriter.GetEventWritePossibleHandle()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffer); + EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - tReaderWriter.GetWriteBuffer(); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); + tReaderWriter.GetWriter()->GetWriteBuffer(); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); } TEST(TOverlappedReaderWriterTests, GetFullBuffer_WrongOrder) @@ -265,16 +264,16 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; - tReaderWriter.AddFinishedReadBuffer(pBuffers[1]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriteBuffer()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[2]); - EXPECT_EQ(nullptr, tReaderWriter.GetWriteBuffer()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[0]); - EXPECT_NE(nullptr, tReaderWriter.GetWriteBuffer()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetWriteBuffer()); } TEST(TOverlappedReaderWriterTests, AddFullBuffer_HandlingSrcEof) @@ -283,15 +282,15 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[1]->SetLastPart(true); - tReaderWriter.AddFinishedReadBuffer(pBuffers[0]); - EXPECT_FALSE(tReaderWriter.IsDataSourceFinished()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); + EXPECT_FALSE(tReaderWriter.GetReader()->IsDataSourceFinished()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[1]); - EXPECT_TRUE(tReaderWriter.IsDataSourceFinished()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); + EXPECT_TRUE(tReaderWriter.GetReader()->IsDataSourceFinished()); } TEST(TOverlappedReaderWriterTests, AddFullBuffer_HandlingDstEof) @@ -300,22 +299,22 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[2]->SetLastPart(true); - tReaderWriter.AddFinishedReadBuffer(pBuffers[0]); - tReaderWriter.AddFinishedReadBuffer(pBuffers[1]); - tReaderWriter.AddFinishedReadBuffer(pBuffers[2]); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); - tReaderWriter.GetWriteBuffer(); + tReaderWriter.GetWriter()->GetWriteBuffer(); // EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); - tReaderWriter.GetWriteBuffer(); + tReaderWriter.GetWriter()->GetWriteBuffer(); // EXPECT_FALSE(tReaderWriter.IsDataWritingFinished()); // getting the last buffer (marked as eof) causes setting the data-writing-finished flag - tReaderWriter.GetWriteBuffer(); + tReaderWriter.GetWriter()->GetWriteBuffer(); // EXPECT_TRUE(tReaderWriter.IsDataWritingFinished()); } @@ -326,7 +325,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_THROW(tReaderWriter.AddFinishedReadBuffer(nullptr), TCoreException); + EXPECT_THROW(tReaderWriter.GetReader()->AddFullBuffer(nullptr), TCoreException); } TEST(TOverlappedReaderWriterTests, AddFullBuffer_SameBufferTwice) @@ -335,14 +334,14 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetEmptyBuffer(); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); pBuffer->InitForRead(0, 1280); pBuffer->SetBytesTransferred(1230); pBuffer->SetStatusCode(0); - tReaderWriter.AddFinishedReadBuffer(pBuffer); - EXPECT_THROW(tReaderWriter.AddFinishedReadBuffer(pBuffer), TCoreException); + tReaderWriter.GetReader()->AddFullBuffer(pBuffer); + EXPECT_THROW(tReaderWriter.GetReader()->AddFullBuffer(pBuffer), TCoreException); } TEST(TOverlappedReaderWriterTests, GetFullBuffer_AddFullBuffer_OutOfOrder) @@ -351,7 +350,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[0]->InitForRead(0, 1000); pBuffers[0]->SetBytesTransferred(1000); @@ -366,16 +365,16 @@ pBuffers[2]->SetStatusCode(0); pBuffers[2]->SetLastPart(true); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[1]); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[1]); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[2]); - EXPECT_TIMEOUT(tReaderWriter.GetEventWritePossibleHandle()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[2]); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); - tReaderWriter.AddFinishedReadBuffer(pBuffers[0]); - EXPECT_SIGNALED(tReaderWriter.GetEventWritePossibleHandle()); + tReaderWriter.GetReader()->AddFullBuffer(pBuffers[0]); + EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWritePossibleHandle()); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -385,7 +384,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[0]->InitForRead(0, 1000); pBuffers[0]->SetBytesTransferred(1000); @@ -400,12 +399,12 @@ pBuffers[2]->SetStatusCode(0); pBuffers[2]->SetLastPart(true); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[1]); - EXPECT_TIMEOUT(tReaderWriter.GetEventWriteFinishedHandle()); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[2]); - EXPECT_TIMEOUT(tReaderWriter.GetEventWriteFinishedHandle()); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[0]); - EXPECT_SIGNALED(tReaderWriter.GetEventWriteFinishedHandle()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); + EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); } TEST(TOverlappedReaderWriterTests, GetFinishedBuffer_Signals) @@ -414,7 +413,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[0]->InitForRead(0, 4096); pBuffers[0]->SetBytesTransferred(4096); @@ -429,18 +428,18 @@ pBuffers[2]->SetStatusCode(0); pBuffers[2]->SetLastPart(true); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[1]); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[2]); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[0]); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetFinishedWriteBuffer(); - EXPECT_SIGNALED(tReaderWriter.GetEventWriteFinishedHandle()); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); + EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - pBuffer = tReaderWriter.GetFinishedWriteBuffer(); - EXPECT_SIGNALED(tReaderWriter.GetEventWriteFinishedHandle()); + pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); + EXPECT_SIGNALED(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); - pBuffer = tReaderWriter.GetFinishedWriteBuffer(); - EXPECT_TIMEOUT(tReaderWriter.GetEventWriteFinishedHandle()); + pBuffer = tReaderWriter.GetWriter()->GetFinishedBuffer(); + EXPECT_TIMEOUT(tReaderWriter.GetWriter()->GetEventWriteFinishedHandle()); } TEST(TOverlappedReaderWriterTests, GetFinishedBuffer_WrongOrder) @@ -449,7 +448,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer(), tReaderWriter.GetEmptyBuffer() }; + TOverlappedDataBuffer* pBuffers[3] = { tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer(), tReaderWriter.GetReader()->GetEmptyBuffer() }; pBuffers[0]->InitForRead(0, 1000); pBuffers[0]->SetBytesTransferred(1000); @@ -464,14 +463,14 @@ pBuffers[2]->SetStatusCode(0); pBuffers[2]->SetLastPart(true); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[1]); - EXPECT_EQ(nullptr, tReaderWriter.GetFinishedWriteBuffer()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[1]); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[2]); - EXPECT_EQ(nullptr, tReaderWriter.GetFinishedWriteBuffer()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[2]); + EXPECT_EQ(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); - tReaderWriter.AddFinishedWriteBuffer(pBuffers[0]); - EXPECT_NE(nullptr, tReaderWriter.GetFinishedWriteBuffer()); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffers[0]); + EXPECT_NE(nullptr, tReaderWriter.GetWriter()->GetFinishedBuffer()); } TEST(TOverlappedReaderWriterTests, AddFinishedBuffer_Null) @@ -481,7 +480,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - EXPECT_THROW(tReaderWriter.AddFinishedWriteBuffer(nullptr), TCoreException); + EXPECT_THROW(tReaderWriter.GetWriter()->AddFinishedBuffer(nullptr), TCoreException); } TEST(TOverlappedReaderWriterTests, AddFinishedBuffer_SameBufferTwice) @@ -490,7 +489,7 @@ TOverlappedMemoryPoolPtr spBuffers(std::make_shared(3, 32768)); TOverlappedReaderWriter tReaderWriter(spLogData, spBuffers, 0, 4096); - TOverlappedDataBuffer* pBuffer = tReaderWriter.GetEmptyBuffer(); - tReaderWriter.AddFinishedWriteBuffer(pBuffer); - EXPECT_THROW(tReaderWriter.AddFinishedWriteBuffer(pBuffer), TCoreException); + TOverlappedDataBuffer* pBuffer = tReaderWriter.GetReader()->GetEmptyBuffer(); + tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffer); + EXPECT_THROW(tReaderWriter.GetWriter()->AddFinishedBuffer(pBuffer), TCoreException); }