Index: src/libchcore/TOrderedBufferQueue.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TOrderedBufferQueue.cpp (.../TOrderedBufferQueue.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TOrderedBufferQueue.cpp (.../TOrderedBufferQueue.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -32,6 +32,8 @@ void TOrderedBufferQueue::Push(TOverlappedDataBuffer* pBuffer) { + if(!pBuffer) + throw TCoreException(eErr_InvalidArgument, L"pBuffer is NULL", LOCATION); if(pBuffer->HasError()) throw TCoreException(eErr_InvalidArgument, L"Cannot push buffer with error", LOCATION); @@ -52,14 +54,13 @@ TOverlappedDataBuffer* TOrderedBufferQueue::Pop() { - if(!IsBufferReady()) + if(!HasPoppableBuffer()) return nullptr; TOverlappedDataBuffer* pBuffer = *m_setBuffers.begin(); m_setBuffers.erase(m_setBuffers.begin()); - if(!pBuffer->HasError() && m_ullExpectedBufferPosition != NoPosition) - m_ullExpectedBufferPosition += pBuffer->GetRequestedDataSize(); + m_ullExpectedBufferPosition += pBuffer->GetRequestedDataSize(); UpdateHasBuffers(); @@ -85,11 +86,6 @@ return nullptr; } - bool TOrderedBufferQueue::IsBufferReady() const - { - return (!m_setBuffers.empty() && (m_ullExpectedBufferPosition == NoPosition || (*m_setBuffers.begin())->GetFilePosition() == m_ullExpectedBufferPosition)); - } - size_t TOrderedBufferQueue::GetCount() const { return m_setBuffers.size() + (m_pFirstErrorBuffer ? 1 : 0); @@ -102,7 +98,11 @@ bool TOrderedBufferQueue::HasPoppableBuffer() const { - return !m_setBuffers.empty() && (*m_setBuffers.begin())->GetFilePosition() == m_ullExpectedBufferPosition; + if(m_setBuffers.empty()) + return false; + + TOverlappedDataBuffer* pBuffer = *m_setBuffers.begin(); + return pBuffer->GetFilePosition() == m_ullExpectedBufferPosition; } HANDLE TOrderedBufferQueue::GetHasBuffersEvent() const @@ -117,6 +117,9 @@ void TOrderedBufferQueue::ReleaseBuffers(const TBufferListPtr& spBuffers) { + if(!spBuffers) + throw TCoreException(eErr_InvalidArgument, L"spBuffers is NULL", LOCATION); + for(TOverlappedDataBuffer* pBuffer : m_setBuffers) { spBuffers->Push(pBuffer); @@ -136,7 +139,7 @@ void TOrderedBufferQueue::UpdateHasBuffers() { - if(!m_setBuffers.empty() && (m_ullExpectedBufferPosition == NoPosition || (*m_setBuffers.begin())->GetFilePosition() == m_ullExpectedBufferPosition)) + if(HasPoppableBuffer()) { m_eventHasBuffers.SetEvent(); m_notifier(true); Index: src/libchcore/TOrderedBufferQueue.h =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TOrderedBufferQueue.h (.../TOrderedBufferQueue.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TOrderedBufferQueue.h (.../TOrderedBufferQueue.h) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -57,7 +57,6 @@ boost::signals2::signal& GetNotifier(); private: - bool IsBufferReady() const; void UpdateHasBuffers(); void UpdateHasErrors(); @@ -79,6 +78,8 @@ template void TOrderedBufferQueue::PushError(TOverlappedDataBuffer* pBuffer, T& rRetryQueue) { + if(!pBuffer) + throw TCoreException(eErr_InvalidArgument, L"pBuffer is NULL", LOCATION); if(!pBuffer->HasError()) throw TCoreException(eErr_InvalidArgument, L"Cannot push successful buffer to failed queue", LOCATION); @@ -92,13 +93,22 @@ if(pBuffer->GetFilePosition() < m_ullErrorPosition) { - rRetryQueue.Push(m_pFirstErrorBuffer, true); + if(m_pFirstErrorBuffer) + { + // if there is no ptr set then it is being processed somewhere and will be handled separately + m_pFirstErrorBuffer->SetErrorCode(ERROR_SUCCESS); + rRetryQueue.Push(m_pFirstErrorBuffer, true); + } m_pFirstErrorBuffer = pBuffer; m_ullErrorPosition = pBuffer->GetFilePosition(); } else if(pBuffer->GetFilePosition() > m_ullErrorPosition) + { + pBuffer->SetErrorCode(ERROR_SUCCESS); rRetryQueue.Push(pBuffer, true); - // else encountered error at the same position as before + } + else if(!m_pFirstErrorBuffer) + m_pFirstErrorBuffer = pBuffer; // restore the buffer UpdateHasErrors(); } Index: src/libchcore/TOverlappedDataBuffer.cpp =================================================================== diff -u -rbef894e38e5c1486824787cf8c47a87a0828b228 -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TOverlappedDataBuffer.cpp (.../TOverlappedDataBuffer.cpp) (revision bef894e38e5c1486824787cf8c47a87a0828b228) +++ src/libchcore/TOverlappedDataBuffer.cpp (.../TOverlappedDataBuffer.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -27,16 +27,16 @@ namespace chcore { - bool CompareBufferPositions::operator()(const TOverlappedDataBuffer* pBufferA, const TOverlappedDataBuffer* pBufferB) const - { - if(!pBufferA) - throw TCoreException(eErr_InvalidArgument, L"pBufferA", LOCATION); - if(!pBufferB) - throw TCoreException(eErr_InvalidArgument, L"pBufferB", LOCATION); - - return pBufferA->GetFilePosition() < pBufferB->GetFilePosition(); - } - + bool CompareBufferPositions::operator()(const TOverlappedDataBuffer* pBufferA, const TOverlappedDataBuffer* pBufferB) const + { + if(!pBufferA) + throw TCoreException(eErr_InvalidArgument, L"pBufferA", LOCATION); + if(!pBufferB) + throw TCoreException(eErr_InvalidArgument, L"pBufferB", LOCATION); + + return pBufferA->GetFilePosition() < pBufferB->GetFilePosition(); + } + TOverlappedDataBuffer::TOverlappedDataBuffer(size_t stBufferSize, void* pParam) : m_pParam(pParam) { Index: src/libchcore/TOverlappedReader.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TOverlappedReader.cpp (.../TOverlappedReader.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -35,8 +35,6 @@ throw TCoreException(eErr_InvalidArgument, L"spLogFileData is NULL", LOCATION); if(!spEmptyBuffers) throw TCoreException(eErr_InvalidArgument, L"spMemoryPool", LOCATION); - if(dwChunkSize == 0) - throw TCoreException(eErr_InvalidArgument, L"dwChunkSize", LOCATION); } TOverlappedReader::~TOverlappedReader() Index: src/libchcore/TReadBufferQueueWrapper.cpp =================================================================== diff -u -r6c41e7b3cf7711c6f5027c0c0154013f50f08e7b -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TReadBufferQueueWrapper.cpp (.../TReadBufferQueueWrapper.cpp) (revision 6c41e7b3cf7711c6f5027c0c0154013f50f08e7b) +++ src/libchcore/TReadBufferQueueWrapper.cpp (.../TReadBufferQueueWrapper.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -116,6 +116,8 @@ void TReadBufferQueueWrapper::SetDataSourceFinished(TOverlappedDataBuffer* pBuffer) { + if(!pBuffer) + throw TCoreException(eErr_InvalidArgument, L"pBuffer is NULL", LOCATION); if(!pBuffer->IsLastPart()) throw TCoreException(eErr_InvalidArgument, L"Trying to set the end of data using unfinished buffer", LOCATION); Index: src/libchcore/TSimpleOrderedBufferQueue.h =================================================================== diff -u -rc4cbf6cd567821f9a981586ab5d8294a26f873be -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TSimpleOrderedBufferQueue.h (.../TSimpleOrderedBufferQueue.h) (revision c4cbf6cd567821f9a981586ab5d8294a26f873be) +++ src/libchcore/TSimpleOrderedBufferQueue.h (.../TSimpleOrderedBufferQueue.h) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -56,6 +56,9 @@ void ReleaseBuffers(const TBufferListPtr& spBuffers) { + if(!spBuffers) + throw TCoreException(eErr_InvalidArgument, L"spBuffers is NULL", LOCATION); + for (TOverlappedDataBuffer* pBuffer : *this) { spBuffers->Push(pBuffer); Index: src/libchcore/TWriteBufferQueueWrapper.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TWriteBufferQueueWrapper.cpp (.../TWriteBufferQueueWrapper.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TWriteBufferQueueWrapper.cpp (.../TWriteBufferQueueWrapper.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -87,11 +87,6 @@ return m_spDataQueue->GetCount(); } - bool TWriteBufferQueueWrapper::IsEmpty() const - { - return m_spDataQueue->IsEmpty(); - } - HANDLE TWriteBufferQueueWrapper::GetHasBuffersEvent() const { return m_eventHasBuffers.Handle(); @@ -104,6 +99,8 @@ void TWriteBufferQueueWrapper::ReleaseBuffers(const TBufferListPtr& spBuffers) { + if(!spBuffers) + throw TCoreException(eErr_InvalidArgument, L"spBuffers is NULL", LOCATION); m_spDataQueue->ReleaseBuffers(spBuffers); m_tClaimedQueue.ReleaseBuffers(spBuffers); } Index: src/libchcore/TWriteBufferQueueWrapper.h =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/TWriteBufferQueueWrapper.h (.../TWriteBufferQueueWrapper.h) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/TWriteBufferQueueWrapper.h (.../TWriteBufferQueueWrapper.h) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -39,7 +39,6 @@ TOverlappedDataBuffer* Pop(); size_t GetCount() const; - bool IsEmpty() const; HANDLE GetHasBuffersEvent() const; void ReleaseBuffers(const TBufferListPtr& spBuffers); Index: src/libchcore/Tests/TOrderedBufferQueueTests.cpp =================================================================== diff -u -rb941384e121190b6107f1c99b3233667e3daf4ce -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/Tests/TOrderedBufferQueueTests.cpp (.../TOrderedBufferQueueTests.cpp) (revision b941384e121190b6107f1c99b3233667e3daf4ce) +++ src/libchcore/Tests/TOrderedBufferQueueTests.cpp (.../TOrderedBufferQueueTests.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -169,7 +169,7 @@ EXPECT_EQ(1, collection.size()); EXPECT_EQ(&buffer2, collection.front()); EXPECT_EQ(1000, collection.front()->GetFilePosition()); - EXPECT_EQ(234, collection.front()->GetErrorCode()); + EXPECT_EQ(0, collection.front()->GetErrorCode()); } TEST(TOrderedBufferQueueTests, PushBuffer_TwoFailuresOutOfOrder) @@ -192,7 +192,7 @@ EXPECT_EQ(1, collection.size()); EXPECT_EQ(&buffer2, collection.front()); EXPECT_EQ(1000, collection.front()->GetFilePosition()); - EXPECT_EQ(234, collection.front()->GetErrorCode()); + EXPECT_EQ(0, collection.front()->GetErrorCode()); } TEST(TOrderedBufferQueueTests, PushBuffer_ThrowOnNonErrorBuffer) Index: src/libchcore/Tests/TWriteBufferQueueWrapperTests.cpp =================================================================== diff -u -rda7737de7046ba0ecd255240fb36b4a46584ebf2 -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/Tests/TWriteBufferQueueWrapperTests.cpp (.../TWriteBufferQueueWrapperTests.cpp) (revision da7737de7046ba0ecd255240fb36b4a46584ebf2) +++ src/libchcore/Tests/TWriteBufferQueueWrapperTests.cpp (.../TWriteBufferQueueWrapperTests.cpp) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -19,7 +19,6 @@ TWriteBufferQueueWrapper queue(spQueue); EXPECT_EQ(0, queue.GetCount()); - EXPECT_EQ(true, queue.IsEmpty()); EXPECT_TIMEOUT(queue.GetHasBuffersEvent()); } Index: src/libchcore/libchcore.vc140.vcxproj =================================================================== diff -u -rc4cbf6cd567821f9a981586ab5d8294a26f873be -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision c4cbf6cd567821f9a981586ab5d8294a26f873be) +++ src/libchcore/libchcore.vc140.vcxproj (.../libchcore.vc140.vcxproj) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -521,6 +521,7 @@ + Index: src/libchcore/libchcore.vc140.vcxproj.filters =================================================================== diff -u -rc4cbf6cd567821f9a981586ab5d8294a26f873be -r685d0da3259dd94327ee8d644a88c155585b8249 --- src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision c4cbf6cd567821f9a981586ab5d8294a26f873be) +++ src/libchcore/libchcore.vc140.vcxproj.filters (.../libchcore.vc140.vcxproj.filters) (revision 685d0da3259dd94327ee8d644a88c155585b8249) @@ -494,6 +494,9 @@ Tests + + Source Files\Tools\Data Buffer\Queues +