Index: src/libchcore/TLocalFilesystemFile.cpp =================================================================== diff -u -rf8fcbbd1d2321cf0c8be79526c449384af654e49 -r7fd37811dbce76d429b80e4703e88925982f5859 --- src/libchcore/TLocalFilesystemFile.cpp (.../TLocalFilesystemFile.cpp) (revision f8fcbbd1d2321cf0c8be79526c449384af654e49) +++ src/libchcore/TLocalFilesystemFile.cpp (.../TLocalFilesystemFile.cpp) (revision 7fd37811dbce76d429b80e4703e88925982f5859) @@ -21,14 +21,13 @@ #include "TBufferSizes.h" #include "TCoreException.h" #include "ErrorCodes.h" -#include #include #include "RoundingFunctions.h" #include "TLocalFilesystem.h" -#include "TCoreWin32Exception.h" #include "TFileException.h" #include "TFileInfo.h" #include "StreamingHelpers.h" +#include "TOverlappedDataBufferQueue.h" namespace chcore { @@ -214,7 +213,9 @@ rBuffer.SetErrorCode(ERROR_SUCCESS); rBuffer.SetLastPart(true); - rBuffer.RequeueAsFull(); // basically the same as OverlappedReadCompleted + TOverlappedDataBufferQueue* pQueue = (TOverlappedDataBufferQueue*)rBuffer.GetParam(); + + pQueue->AddFullBuffer(&rBuffer); // basically the same as OverlappedReadCompleted break; } Index: src/libchcore/TOverlappedDataBuffer.cpp =================================================================== diff -u -rf8fcbbd1d2321cf0c8be79526c449384af654e49 -r7fd37811dbce76d429b80e4703e88925982f5859 --- src/libchcore/TOverlappedDataBuffer.cpp (.../TOverlappedDataBuffer.cpp) (revision f8fcbbd1d2321cf0c8be79526c449384af654e49) +++ src/libchcore/TOverlappedDataBuffer.cpp (.../TOverlappedDataBuffer.cpp) (revision 7fd37811dbce76d429b80e4703e88925982f5859) @@ -24,49 +24,15 @@ #include "TOverlappedDataBuffer.h" #include "TCoreException.h" #include "ErrorCodes.h" -#include "IOverlappedDataBufferQueue.h" -#define STATUS_END_OF_FILE 0xc0000011 - namespace chcore { - /////////////////////////////////////////////////////////////////////////////////// - // class TOverlappedDataBuffer - VOID CALLBACK OverlappedReadCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) + TOverlappedDataBuffer::TOverlappedDataBuffer(size_t stBufferSize, void* pParam) : + m_pParam(pParam) { - TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; + if (!m_pParam) + throw TCoreException(eErr_InvalidPointer, L"m_pParam", LOCATION); - // determine if this is the last packet - bool bEof = (dwErrorCode == ERROR_HANDLE_EOF || - pBuffer->GetStatusCode() == STATUS_END_OF_FILE || - (dwErrorCode == ERROR_SUCCESS && pBuffer->GetBytesTransferred() != pBuffer->GetRequestedDataSize())); - - // reset status code and error code if they pointed out to EOF - if (pBuffer->GetStatusCode() == STATUS_END_OF_FILE) - pBuffer->SetStatusCode(0); - - pBuffer->SetErrorCode(dwErrorCode == ERROR_HANDLE_EOF ? ERROR_SUCCESS : dwErrorCode); - - pBuffer->SetRealDataSize(dwNumberOfBytesTransfered); - pBuffer->SetLastPart(bEof); - - pBuffer->RequeueAsFull(); - } - - VOID CALLBACK OverlappedWriteCompleted(DWORD dwErrorCode, DWORD /*dwNumberOfBytesTransfered*/, LPOVERLAPPED lpOverlapped) - { - TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; - - pBuffer->SetErrorCode(dwErrorCode); - pBuffer->RequeueAsFinished(); - } - - TOverlappedDataBuffer::TOverlappedDataBuffer(size_t stBufferSize, IOverlappedDataBufferQueue* pQueue) : - m_pQueue(pQueue) - { - if (!m_pQueue) - throw TCoreException(eErr_InvalidPointer, L"m_pQueue", LOCATION); - // initialize OVERLAPPED members Internal = 0; InternalHigh = 0; @@ -111,21 +77,6 @@ return m_pBuffer; } - void TOverlappedDataBuffer::RequeueAsEmpty() - { - m_pQueue->AddEmptyBuffer(this); - } - - void TOverlappedDataBuffer::RequeueAsFull() - { - m_pQueue->AddFullBuffer(this); - } - - void TOverlappedDataBuffer::RequeueAsFinished() - { - m_pQueue->AddFinishedBuffer(this); - } - void TOverlappedDataBuffer::InitForRead(unsigned long long ullPosition, DWORD dwRequestedSize) { SetRequestedDataSize(dwRequestedSize); Index: src/libchcore/TOverlappedDataBuffer.h =================================================================== diff -u -r4fe995b304ea342b50293f92d3c1992b43b820f7 -r7fd37811dbce76d429b80e4703e88925982f5859 --- src/libchcore/TOverlappedDataBuffer.h (.../TOverlappedDataBuffer.h) (revision 4fe995b304ea342b50293f92d3c1992b43b820f7) +++ src/libchcore/TOverlappedDataBuffer.h (.../TOverlappedDataBuffer.h) (revision 7fd37811dbce76d429b80e4703e88925982f5859) @@ -34,7 +34,7 @@ { public: // construction/destruction - TOverlappedDataBuffer(size_t stBufferSize, IOverlappedDataBufferQueue* pQueue); + TOverlappedDataBuffer(size_t stBufferSize, void* pParam); TOverlappedDataBuffer(const TOverlappedDataBuffer&) = delete; TOverlappedDataBuffer(TOverlappedDataBuffer&& rSrc) = delete; @@ -77,10 +77,7 @@ unsigned long long GetFilePosition() const { return (unsigned long long)OffsetHigh << 32 | Offset; } void SetFilePosition(unsigned long long ullPosition) { OffsetHigh = (DWORD)(ullPosition >> 32); Offset = (DWORD)ullPosition; } - // queue management - void RequeueAsEmpty(); - void RequeueAsFull(); - void RequeueAsFinished(); + void* GetParam() const { return m_pParam; } // composite initialization void InitForRead(unsigned long long ullPosition, DWORD dwRequestedSize); @@ -99,7 +96,7 @@ bool m_bLastPart = false; // marks the last part of the file unsigned long long m_ullBufferOrder = 0; // marks the order of this buffer - IOverlappedDataBufferQueue* m_pQueue = nullptr; // pointer to the queue where this object resides + void* m_pParam = nullptr; // pointer to the queue where this object resides }; } Index: src/libchcore/TOverlappedDataBufferQueue.cpp =================================================================== diff -u -rf8fcbbd1d2321cf0c8be79526c449384af654e49 -r7fd37811dbce76d429b80e4703e88925982f5859 --- src/libchcore/TOverlappedDataBufferQueue.cpp (.../TOverlappedDataBufferQueue.cpp) (revision f8fcbbd1d2321cf0c8be79526c449384af654e49) +++ src/libchcore/TOverlappedDataBufferQueue.cpp (.../TOverlappedDataBufferQueue.cpp) (revision 7fd37811dbce76d429b80e4703e88925982f5859) @@ -23,8 +23,48 @@ #include "ErrorCodes.h" #include +#define STATUS_END_OF_FILE 0xc0000011 + namespace chcore { + /////////////////////////////////////////////////////////////////////////////////// + // class TOverlappedDataBuffer + VOID CALLBACK OverlappedReadCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) + { + _ASSERTE(dwNumberOfBytesTransfered == lpOverlapped->InternalHigh); + + TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; + TOverlappedDataBufferQueue* pQueue = (TOverlappedDataBufferQueue*)pBuffer->GetParam(); + + // determine if this is the last packet + bool bEof = (dwErrorCode == ERROR_HANDLE_EOF || + pBuffer->GetStatusCode() == STATUS_END_OF_FILE || + (dwErrorCode == ERROR_SUCCESS && dwNumberOfBytesTransfered != pBuffer->GetRequestedDataSize())); + + // reset status code and error code if they pointed out to EOF + if(pBuffer->GetStatusCode() == STATUS_END_OF_FILE) + pBuffer->SetStatusCode(0); + + pBuffer->SetErrorCode(dwErrorCode == ERROR_HANDLE_EOF ? ERROR_SUCCESS : dwErrorCode); + + pBuffer->SetRealDataSize(dwNumberOfBytesTransfered); + pBuffer->SetLastPart(bEof); + + pQueue->AddFullBuffer(pBuffer); + } + + VOID CALLBACK OverlappedWriteCompleted(DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped) + { + _ASSERTE(dwNumberOfBytesTransfered == lpOverlapped->InternalHigh); + + TOverlappedDataBuffer* pBuffer = (TOverlappedDataBuffer*)lpOverlapped; + TOverlappedDataBufferQueue* pQueue = (TOverlappedDataBufferQueue*)pBuffer->GetParam(); + + pBuffer->SetErrorCode(dwErrorCode); + + pQueue->AddFinishedBuffer(pBuffer); + } + bool CompareBufferPositions::operator()(const TOverlappedDataBuffer* pBufferA, const TOverlappedDataBuffer* pBufferB) { return pBufferA->GetBufferOrder() < pBufferB->GetBufferOrder(); @@ -147,7 +187,10 @@ throw TCoreException(eErr_InvalidOverlappedPosition, L"Tried to re-insert same buffer into queue", LOCATION); if (pBuffer->IsLastPart()) + { m_bDataSourceFinished = true; + UpdateReadPossibleEvent(); + } UpdateWritePossibleEvent(); UpdateAllBuffersAccountedFor(); Index: src/libchcore/TSubTaskCopyMove.cpp =================================================================== diff -u -r3c209ebdc14ac0829468249805b7587880761f59 -r7fd37811dbce76d429b80e4703e88925982f5859 --- src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 3c209ebdc14ac0829468249805b7587880761f59) +++ src/libchcore/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 7fd37811dbce76d429b80e4703e88925982f5859) @@ -425,12 +425,12 @@ eResult = tFileFBWrapper.ReadFileFB(fileSrc, *pBuffer, pData->spSrcFile->GetFullFilePath(), bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -456,12 +456,12 @@ eResult = tFileFBWrapper.ReadFileFB(fileSrc, *pBuffer, pData->spSrcFile->GetFullFilePath(), bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -471,12 +471,12 @@ } else if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -491,12 +491,12 @@ eResult = tFileFBWrapper.WriteFileFB(fileDst, *pBuffer, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -522,12 +522,12 @@ eResult = tFileFBWrapper.WriteFileFB(fileDst, *pBuffer, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -537,12 +537,12 @@ } else if(eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if(bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -555,12 +555,12 @@ eResult = tFileFBWrapper.FinalizeFileFB(fileDst, *pBuffer, pData->pathDstFile, bSkip); if (eResult != TSubTaskBase::eSubResult_Continue) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); bStopProcessing = true; } else if (bSkip) { - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); AdjustProcessedSizeForSkip(pData->spSrcFile); @@ -578,7 +578,7 @@ bStopProcessing = pBuffer->IsLastPart(); pData->dbBuffer.MarkFinishedBufferAsComplete(pBuffer); - pBuffer->RequeueAsEmpty(); + pData->dbBuffer.AddEmptyBuffer(pBuffer); if(bStopProcessing) {