@@ -223,17 +223,17 @@ void NodeBIO::TryMoveReadHead() {
223223 // inside the buffer, respectively. When they're equal - its safe to reset
224224 // them, because both reader and writer will continue doing their stuff
225225 // from new (zero) positions.
226- if (read_head_->read_pos_ != read_head_->write_pos_ )
227- return ;
228-
229- // Reset positions
230- read_head_->read_pos_ = 0 ;
231- read_head_->write_pos_ = 0 ;
226+ while (read_head_->read_pos_ != 0 &&
227+ read_head_->read_pos_ == read_head_->write_pos_ ) {
228+ // Reset positions
229+ read_head_->read_pos_ = 0 ;
230+ read_head_->write_pos_ = 0 ;
232231
233- // Move read_head_ forward, just in case if there're still some data to
234- // read in the next buffer.
235- if (read_head_ != write_head_)
236- read_head_ = read_head_->next_ ;
232+ // Move read_head_ forward, just in case if there're still some data to
233+ // read in the next buffer.
234+ if (read_head_ != write_head_)
235+ read_head_ = read_head_->next_ ;
236+ }
237237}
238238
239239
@@ -397,8 +397,13 @@ void NodeBIO::Commit(size_t size) {
397397 // Allocate new buffer if write head is full,
398398 // and there're no other place to go
399399 TryAllocateForWrite ();
400- if (write_head_->write_pos_ == kBufferLength )
400+ if (write_head_->write_pos_ == kBufferLength ) {
401401 write_head_ = write_head_->next_ ;
402+
403+ // Additionally, since we're moved to the next buffer, read head
404+ // may be moved as well.
405+ TryMoveReadHead ();
406+ }
402407}
403408
404409
0 commit comments