bneradt commented on code in PR #13186:
URL: https://github.com/apache/trafficserver/pull/13186#discussion_r3366372722


##########
src/iocore/net/quic/QUICStreamVCAdapter.cc:
##########
@@ -84,18 +86,40 @@ QUICStreamVCAdapter::_read(size_t len)
     SCOPED_MUTEX_LOCK(lock, this->_write_vio.mutex, this_ethread());
 
     IOBufferReader *reader = this->_write_vio.get_reader();
-    block                  = 
make_ptr<IOBufferBlock>(reader->get_current_block()->clone());
+    if (reader->get_current_block() == nullptr || reader->block_read_avail() 
<= 0) {
+      return block;
+    }
+
+    block = make_ptr<IOBufferBlock>(reader->get_current_block()->clone());
     if (block->size()) {
       block->consume(reader->start_offset);
-      block->_end             = std::min(block->start() + len, 
block->_buf_end);
-      this->_write_vio.ndone += block->size();
+      block->_end = std::min(block->start() + len, block->_buf_end);
+    }
+    if (block->size() == 0) {
+      block = nullptr;
     }
-    reader->consume(block->size());
   }
 
   return block;
 }
 
+void
+QUICStreamVCAdapter::_consume(size_t len)
+{
+  if (len == 0 || this->_write_vio.op != VIO::WRITE) {
+    return;
+  }
+
+  SCOPED_MUTEX_LOCK(lock, this->_write_vio.mutex, this_ethread());
+
+  IOBufferReader *reader      = this->_write_vio.get_reader();
+  const size_t    consume_len = std::min(len, 
static_cast<size_t>(std::max<int64_t>(reader->read_avail(), 0)));
+  if (consume_len > 0) {
+    reader->consume(consume_len);
+    this->_write_vio.ndone += consume_len;
+  }

Review Comment:
   Fixed. _consume() now returns if the write-side reader is null, and I 
hardened unread_len() the same way.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to