Return (offset, length) of next chunk to download, or (fileSize, 0) if reach end of file.
| 3 | // Return (offset, length) of next chunk to download, |
| 4 | // or (fileSize, 0) if reach end of file. |
| 5 | Range OffsetMgr::getNextOffset() { |
| 6 | Range ret; |
| 7 | |
| 8 | pthread_mutex_lock(&this->offsetLock); |
| 9 | ret.offset = std::min(this->curPos, this->keySize); |
| 10 | |
| 11 | if (this->curPos + this->chunkSize > this->keySize) { |
| 12 | ret.length = this->keySize - this->curPos; |
| 13 | this->curPos = this->keySize; |
| 14 | } else { |
| 15 | ret.length = this->chunkSize; |
| 16 | this->curPos += this->chunkSize; |
| 17 | } |
| 18 | pthread_mutex_unlock(&this->offsetLock); |
| 19 | |
| 20 | return ret; |
| 21 | } |
| 22 | |
| 23 | ChunkBuffer::ChunkBuffer(const S3Url& s3Url, S3KeyReader& reader, const S3MemoryContext& context) |
| 24 | : s3Url(s3Url), chunkData(context), offsetMgr(reader.getOffsetMgr()), sharedKeyReader(reader) { |