diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2018-05-09 00:07:47 +0200 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2018-05-09 00:07:47 +0200 |
commit | 48c8efc58c9eb41da96b053806deb395d2e66443 (patch) | |
tree | a6da12e987ad778bafe6da7069c7fa8b1e761c68 /wx+/http.cpp | |
parent | 9.6 (diff) | |
download | FreeFileSync-48c8efc58c9eb41da96b053806deb395d2e66443.tar.gz FreeFileSync-48c8efc58c9eb41da96b053806deb395d2e66443.tar.bz2 FreeFileSync-48c8efc58c9eb41da96b053806deb395d2e66443.zip |
9.7
Diffstat (limited to 'wx+/http.cpp')
-rwxr-xr-x | wx+/http.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/wx+/http.cpp b/wx+/http.cpp index dd3cb3bc..fa88bb1d 100755 --- a/wx+/http.cpp +++ b/wx+/http.cpp @@ -77,22 +77,24 @@ public: size_t read(void* buffer, size_t bytesToRead) //throw SysError, X; return "bytesToRead" bytes unless end of stream! { const size_t blockSize = getBlockSize(); - assert(memBuf_.size() <= blockSize); + assert(memBuf_.size() >= blockSize); + assert(bufPos_ <= bufPosEnd_ && bufPosEnd_ <= memBuf_.size()); + char* it = static_cast<char*>(buffer); char* const itEnd = it + bytesToRead; for (;;) { - const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), memBuf_.size()); - std::copy (memBuf_.begin(), memBuf_.begin() + junkSize, it); - memBuf_.erase(memBuf_.begin(), memBuf_.begin() + junkSize); - it += junkSize; + const size_t junkSize = std::min(static_cast<size_t>(itEnd - it), bufPosEnd_ - bufPos_); + std::memcpy(it, &memBuf_[0] + bufPos_, junkSize); + bufPos_ += junkSize; + it += junkSize; if (it == itEnd) break; //-------------------------------------------------------------------- - memBuf_.resize(blockSize); const size_t bytesRead = tryRead(&memBuf_[0], blockSize); //throw SysError; may return short, only 0 means EOF! => CONTRACT: bytesToRead > 0 - memBuf_.resize(bytesRead); + bufPos_ = 0; + bufPosEnd_ = bytesRead; if (notifyUnbufferedIO_) notifyUnbufferedIO_(bytesRead); //throw X @@ -137,8 +139,11 @@ private: wxHTTP webAccess_; std::unique_ptr<wxInputStream> httpStream_; //must be deleted BEFORE webAccess is closed - std::vector<char> memBuf_; const IOCallback notifyUnbufferedIO_; //throw X + + std::vector<char> memBuf_ = std::vector<char>(getBlockSize()); + size_t bufPos_ = 0; //buffered I/O; see file_io.cpp + size_t bufPosEnd_ = 0; // }; |