Skip to content

Commit

Permalink
[AdaptiveStream] Removed goto statement
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Jul 23, 2023
1 parent c219ee5 commit 8eb38cb
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/common/AdaptiveStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,36 +967,35 @@ uint32_t AdaptiveStream::read(void* buffer, uint32_t bytesToRead)

std::unique_lock<std::mutex> lckrw(thread_data_->mutex_rw_);

NEXTSEGMENT:
if (ensureSegment() && bytesToRead)
while (ensureSegment() && bytesToRead > 0)
{
while (true)
size_t avail = segment_buffers_[0]->buffer.size() - segment_read_pos_;
// Wait until we have all data
while (avail < bytesToRead && worker_processing_)
{
size_t avail = segment_buffers_[0]->buffer.size() - segment_read_pos_;

if (avail < bytesToRead && worker_processing_)
{
thread_data_->signal_rw_.wait(lckrw);
continue;
}
thread_data_->signal_rw_.wait(lckrw);
avail = segment_buffers_[0]->buffer.size() - segment_read_pos_;
}

if (avail > bytesToRead)
avail = bytesToRead;
if (avail > bytesToRead)
avail = bytesToRead;

segment_read_pos_ += avail;
absolute_position_ += avail;
segment_read_pos_ += avail;
absolute_position_ += avail;

if (avail == bytesToRead)
{
memcpy(buffer, segment_buffers_[0]->buffer.data() + (segment_read_pos_ - avail), avail);
return static_cast<uint32_t>(avail);
}
// If we call read after the last chunk was read but before worker finishes download, we end up here.
if (!avail)
goto NEXTSEGMENT;
return 0;
if (avail == bytesToRead)
{
std::memcpy(buffer, segment_buffers_[0]->buffer.data() + (segment_read_pos_ - avail), avail);
return static_cast<uint32_t>(avail);
}

// If we call read after the last chunk was read but before worker finishes download, we end up here.
if (avail == 0)
continue;

break;
}

return 0;
}

Expand Down

0 comments on commit 8eb38cb

Please sign in to comment.