This is an automated email from the ASF dual-hosted git repository.

jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 67daf6b6c7 Use VIO reader and writer APIs (#11582)
67daf6b6c7 is described below

commit 67daf6b6c7c02b44a30e9a63914731161c97c077
Author: JosiahWI <[email protected]>
AuthorDate: Fri Jul 19 11:56:50 2024 -0500

    Use VIO reader and writer APIs (#11582)
    
    These APIs are already provided and make the code more succinct. This 
updates the code everywhere to consistently use these convenience APIs. The 
continuation API usage is not changed because `VIO::set_continuation` has some 
additional behavior, so the usage is not as straightforward.
---
 src/api/InkVConnInternal.cc                |  6 +++---
 src/iocore/cache/CacheRead.cc              |  8 ++++----
 src/iocore/cache/CacheVC.cc                | 10 +++++-----
 src/iocore/cache/CacheWrite.cc             | 12 ++++++------
 src/iocore/net/SSLNetVConnection.cc        |  4 ++--
 src/iocore/net/UnixNetVConnection.cc       |  4 ++--
 src/iocore/net/quic/QUICStreamVCAdapter.cc |  4 ++--
 src/proxy/PluginVC.cc                      |  4 ++--
 src/proxy/Transform.cc                     |  8 ++++----
 src/proxy/http2/Http2Stream.cc             | 10 +++++-----
 src/proxy/http3/Http3Transaction.cc        |  4 ++--
 11 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/src/api/InkVConnInternal.cc b/src/api/InkVConnInternal.cc
index 00b4e80be4..ffec1e0f17 100644
--- a/src/api/InkVConnInternal.cc
+++ b/src/api/InkVConnInternal.cc
@@ -70,7 +70,7 @@ INKVConnInternal::destroy()
 VIO *
 INKVConnInternal::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
 {
-  m_read_vio.buffer.writer_for(buf);
+  m_read_vio.set_writer(buf);
   m_read_vio.op = VIO::READ;
   m_read_vio.set_continuation(c);
   m_read_vio.nbytes    = nbytes;
@@ -89,14 +89,14 @@ VIO *
 INKVConnInternal::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader 
*buf, bool owner)
 {
   ink_assert(!owner);
-  m_write_vio.buffer.reader_for(buf);
+  m_write_vio.set_reader(buf);
   m_write_vio.op = VIO::WRITE;
   m_write_vio.set_continuation(c);
   m_write_vio.nbytes    = nbytes;
   m_write_vio.ndone     = 0;
   m_write_vio.vc_server = this;
 
-  if (m_write_vio.buffer.reader()->read_avail() > 0) {
+  if (m_write_vio.get_reader()->read_avail() > 0) {
     if (ink_atomic_increment((int *)&m_event_count, 1) < 0) {
       ink_assert(!"not reached");
     }
diff --git a/src/iocore/cache/CacheRead.cc b/src/iocore/cache/CacheRead.cc
index e71b4ff6b2..5fdbf5e125 100644
--- a/src/iocore/cache/CacheRead.cc
+++ b/src/iocore/cache/CacheRead.cc
@@ -535,7 +535,7 @@ CacheVC::openReadFromWriterMain(int /* event ATS_UNUSED */, 
Event * /* e ATS_UNU
   }
   b          = iobufferblock_clone(writer_buf.get(), writer_offset, bytes);
   writer_buf = iobufferblock_skip(writer_buf.get(), &writer_offset, &length, 
bytes);
-  vio.buffer.writer()->append_block(b);
+  vio.get_writer()->append_block(b);
   vio.ndone += bytes;
   if (vio.ntodo() <= 0) {
     return calluser(VC_EVENT_READ_COMPLETE);
@@ -790,7 +790,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * 
/* e ATS_UNUSED */)
   if (ntodo <= 0) {
     return EVENT_CONT;
   }
-  if (vio.buffer.writer()->max_read_avail() > vio.buffer.writer()->water_mark 
&& vio.ndone) { // initiate read of first block
+  if (vio.get_writer()->max_read_avail() > vio.get_writer()->water_mark && 
vio.ndone) { // initiate read of first block
     return EVENT_CONT;
   }
   if ((bytes <= 0) && vio.ntodo() >= 0) {
@@ -801,7 +801,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * 
/* e ATS_UNUSED */)
   }
   b           = new_IOBufferBlock(buf, bytes, doc_pos);
   b->_buf_end = b->_end;
-  vio.buffer.writer()->append_block(b);
+  vio.get_writer()->append_block(b);
   vio.ndone += bytes;
   doc_pos   += bytes;
   if (vio.ntodo() <= 0) {
@@ -812,7 +812,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * 
/* e ATS_UNUSED */)
     }
     // we have to keep reading until we give the user all the
     // bytes it wanted or we hit the watermark.
-    if (vio.ntodo() > 0 && !vio.buffer.writer()->high_water()) {
+    if (vio.ntodo() > 0 && !vio.get_writer()->high_water()) {
       goto Lread;
     }
     return EVENT_CONT;
diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc
index b0fde6ef5c..7c2041f092 100644
--- a/src/iocore/cache/CacheVC.cc
+++ b/src/iocore/cache/CacheVC.cc
@@ -170,7 +170,7 @@ VIO *
 CacheVC::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *abuf)
 {
   ink_assert(vio.op == VIO::READ);
-  vio.buffer.writer_for(abuf);
+  vio.set_writer(abuf);
   vio.set_continuation(c);
   vio.ndone     = 0;
   vio.nbytes    = nbytes;
@@ -188,7 +188,7 @@ VIO *
 CacheVC::do_io_pread(Continuation *c, int64_t nbytes, MIOBuffer *abuf, int64_t 
offset)
 {
   ink_assert(vio.op == VIO::READ);
-  vio.buffer.writer_for(abuf);
+  vio.set_writer(abuf);
   vio.set_continuation(c);
   vio.ndone     = 0;
   vio.nbytes    = nbytes;
@@ -208,7 +208,7 @@ CacheVC::do_io_write(Continuation *c, int64_t nbytes, 
IOBufferReader *abuf, bool
 {
   ink_assert(vio.op == VIO::WRITE);
   ink_assert(!owner);
-  vio.buffer.reader_for(abuf);
+  vio.set_reader(abuf);
   vio.set_continuation(c);
   vio.ndone     = 0;
   vio.nbytes    = nbytes;
@@ -245,9 +245,9 @@ CacheVC::reenable(VIO *avio)
   if (!trigger) {
 #ifndef USELESS_REENABLES
     if (vio.op == VIO::READ) {
-      if (vio.buffer.mbuf->max_read_avail() > vio.buffer.writer()->water_mark)
+      if (vio.buffer.mbuf->max_read_avail() > vio.get_writer->water_mark)
         ink_assert(!"useless reenable of cache read");
-    } else if (!vio.buffer.reader()->read_avail())
+    } else if (!vio.get_reader()->read_avail())
       ink_assert(!"useless reenable of cache write");
 #endif
     trigger = avio->mutex->thread_holding->schedule_imm_local(this);
diff --git a/src/iocore/cache/CacheWrite.cc b/src/iocore/cache/CacheWrite.cc
index a965a2e786..032ed1092d 100644
--- a/src/iocore/cache/CacheWrite.cc
+++ b/src/iocore/cache/CacheWrite.cc
@@ -1113,11 +1113,11 @@ CacheVC::openWriteMain(int /* event ATS_UNUSED */, 
Event * /* e ATS_UNUSED */)
   int called_user = 0;
   ink_assert(!is_io_in_progress());
 Lagain:
-  if (!vio.buffer.writer()) {
+  if (!vio.get_writer()) {
     if (calluser(VC_EVENT_WRITE_READY) == EVENT_DONE) {
       return EVENT_DONE;
     }
-    if (!vio.buffer.writer()) {
+    if (!vio.get_writer()) {
       return EVENT_CONT;
     }
   }
@@ -1132,7 +1132,7 @@ Lagain:
     }
   }
   int64_t ntodo       = static_cast<int64_t>(vio.ntodo() + length);
-  int64_t total_avail = vio.buffer.reader()->read_avail();
+  int64_t total_avail = vio.get_reader()->read_avail();
   int64_t avail       = total_avail;
   int64_t towrite     = avail + length;
   if (towrite > ntodo) {
@@ -1144,11 +1144,11 @@ Lagain:
     towrite  = MAX_FRAG_SIZE;
   }
   if (!blocks && towrite) {
-    blocks = vio.buffer.reader()->block;
-    offset = vio.buffer.reader()->start_offset;
+    blocks = vio.get_reader()->block;
+    offset = vio.get_reader()->start_offset;
   }
   if (avail > 0) {
-    vio.buffer.reader()->consume(avail);
+    vio.get_reader()->consume(avail);
     vio.ndone += avail;
     total_len += avail;
   }
diff --git a/src/iocore/net/SSLNetVConnection.cc 
b/src/iocore/net/SSLNetVConnection.cc
index 5ebb705f0e..323cb16b06 100644
--- a/src/iocore/net/SSLNetVConnection.cc
+++ b/src/iocore/net/SSLNetVConnection.cc
@@ -1556,7 +1556,7 @@ SSLNetVConnection::sslClientHandShakeEvent(int &err)
       // Outbound PROXY Protocol
       VIO    &vio     = this->write.vio;
       int64_t ntodo   = vio.ntodo();
-      int64_t towrite = vio.buffer.reader()->read_avail();
+      int64_t towrite = vio.get_reader()->read_avail();
 
       if (ntodo > 0 && towrite > 0) {
         MIOBufferAccessor &buf           = vio.buffer;
@@ -2240,7 +2240,7 @@ 
SSLNetVConnection::_propagateHandShakeBuffer(UnixNetVConnection *target, EThread
   // Take ownership of the handShake buffer
   this->sslHandshakeStatus = SSLHandshakeStatus::SSL_HANDSHAKE_DONE;
   NetState *s              = &target->read;
-  s->vio.buffer.writer_for(this->handShakeBuffer);
+  s->vio.set_writer(this->handShakeBuffer);
   s->vio.set_reader(this->handShakeHolder);
   this->handShakeHolder = nullptr;
   this->handShakeBuffer = nullptr;
diff --git a/src/iocore/net/UnixNetVConnection.cc 
b/src/iocore/net/UnixNetVConnection.cc
index 4790016546..31f7b52e30 100644
--- a/src/iocore/net/UnixNetVConnection.cc
+++ b/src/iocore/net/UnixNetVConnection.cc
@@ -615,7 +615,7 @@ UnixNetVConnection::do_io_read(Continuation *c, int64_t 
nbytes, MIOBuffer *buf)
   read.vio.ndone     = 0;
   read.vio.vc_server = (VConnection *)this;
   if (buf) {
-    read.vio.buffer.writer_for(buf);
+    read.vio.set_writer(buf);
     if (!read.enabled) {
       read.vio.reenable();
     }
@@ -641,7 +641,7 @@ UnixNetVConnection::do_io_write(Continuation *c, int64_t 
nbytes, IOBufferReader
   write.vio.vc_server = (VConnection *)this;
   if (reader) {
     ink_assert(!owner);
-    write.vio.buffer.reader_for(reader);
+    write.vio.set_reader(reader);
     if (nbytes && !write.enabled) {
       write.vio.reenable();
     }
diff --git a/src/iocore/net/quic/QUICStreamVCAdapter.cc 
b/src/iocore/net/quic/QUICStreamVCAdapter.cc
index ca7bd94063..d79abe51db 100644
--- a/src/iocore/net/quic/QUICStreamVCAdapter.cc
+++ b/src/iocore/net/quic/QUICStreamVCAdapter.cc
@@ -261,7 +261,7 @@ VIO *
 QUICStreamVCAdapter::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer 
*buf)
 {
   if (buf) {
-    this->_read_vio.buffer.writer_for(buf);
+    this->_read_vio.set_writer(buf);
   } else {
     this->_read_vio.buffer.clear();
   }
@@ -280,7 +280,7 @@ VIO *
 QUICStreamVCAdapter::do_io_write(Continuation *c, int64_t nbytes, 
IOBufferReader *buf, bool /* owner ATS_UNUSED */)
 {
   if (buf) {
-    this->_write_vio.buffer.reader_for(buf);
+    this->_write_vio.set_reader(buf);
   } else {
     this->_write_vio.buffer.clear();
   }
diff --git a/src/proxy/PluginVC.cc b/src/proxy/PluginVC.cc
index f801895cd2..b9ca711a4e 100644
--- a/src/proxy/PluginVC.cc
+++ b/src/proxy/PluginVC.cc
@@ -255,7 +255,7 @@ PluginVC::do_io_read(Continuation *c, int64_t nbytes, 
MIOBuffer *buf)
   ink_assert(magic == PLUGIN_VC_MAGIC_ALIVE);
 
   if (buf) {
-    read_state.vio.buffer.writer_for(buf);
+    read_state.vio.set_writer(buf);
   } else {
     read_state.vio.buffer.clear();
   }
@@ -287,7 +287,7 @@ PluginVC::do_io_write(Continuation *c, int64_t nbytes, 
IOBufferReader *abuffer,
 
   if (abuffer) {
     ink_assert(!owner);
-    write_state.vio.buffer.reader_for(abuffer);
+    write_state.vio.set_reader(abuffer);
   } else {
     write_state.vio.buffer.clear();
   }
diff --git a/src/proxy/Transform.cc b/src/proxy/Transform.cc
index 60af2983a1..a19517135f 100644
--- a/src/proxy/Transform.cc
+++ b/src/proxy/Transform.cc
@@ -275,7 +275,7 @@ TransformTerminus::handle_event(int event, void * /* edata 
ATS_UNUSED */)
 VIO *
 TransformTerminus::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
 {
-  m_read_vio.buffer.writer_for(buf);
+  m_read_vio.set_writer(buf);
   m_read_vio.op = VIO::READ;
   m_read_vio.set_continuation(c);
   m_read_vio.nbytes    = nbytes;
@@ -300,7 +300,7 @@ TransformTerminus::do_io_write(Continuation *c, int64_t 
nbytes, IOBufferReader *
 {
   // In the process of eliminating 'owner' mode so asserting against it
   ink_assert(!owner);
-  m_write_vio.buffer.reader_for(buf);
+  m_write_vio.set_reader(buf);
   m_write_vio.op = VIO::WRITE;
   m_write_vio.set_continuation(c);
   m_write_vio.nbytes    = nbytes;
@@ -506,7 +506,7 @@ TransformVConnection::backlog(uint64_t limit)
   MIOBuffer   *w;
   while (raw_vc && raw_vc != &m_terminus) {
     INKVConnInternal *vc = static_cast<INKVConnInternal *>(raw_vc);
-    if (nullptr != (w = vc->m_read_vio.buffer.writer())) {
+    if (nullptr != (w = vc->m_read_vio.get_writer())) {
       b += w->max_read_avail();
     }
     if (b >= limit) {
@@ -514,7 +514,7 @@ TransformVConnection::backlog(uint64_t limit)
     }
     raw_vc = vc->m_output_vc;
   }
-  if (nullptr != (w = m_terminus.m_read_vio.buffer.writer())) {
+  if (nullptr != (w = m_terminus.m_read_vio.get_writer())) {
     b += w->max_read_avail();
   }
   if (b >= limit) {
diff --git a/src/proxy/http2/Http2Stream.cc b/src/proxy/http2/Http2Stream.cc
index 12c770b100..d7ef103fd9 100644
--- a/src/proxy/http2/Http2Stream.cc
+++ b/src/proxy/http2/Http2Stream.cc
@@ -501,7 +501,7 @@ VIO *
 Http2Stream::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
 {
   if (buf) {
-    read_vio.buffer.writer_for(buf);
+    read_vio.set_writer(buf);
   } else {
     read_vio.buffer.clear();
   }
@@ -522,7 +522,7 @@ VIO *
 Http2Stream::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader 
*abuffer, bool /* owner ATS_UNUSED */)
 {
   if (abuffer) {
-    write_vio.buffer.reader_for(abuffer);
+    write_vio.set_reader(abuffer);
   } else {
     write_vio.buffer.clear();
   }
@@ -658,13 +658,13 @@ Http2Stream::initiating_close()
       }
 
       if (!sent_write_complete) {
-        if (write_vio.cont && write_vio.buffer.writer() &&
+        if (write_vio.cont && write_vio.get_writer() &&
             (!is_outbound_connection() || get_state() == 
Http2StreamState::HTTP2_STREAM_STATE_OPEN ||
              get_state() == 
Http2StreamState::HTTP2_STREAM_STATE_HALF_CLOSED_LOCAL)) {
           SCOPED_MUTEX_LOCK(lock, write_vio.mutex, this_ethread());
           Http2StreamDebug("Send tracked event VC_EVENT_EOS on write_vio. 
sm_id: %" PRId64, _sm->sm_id);
           write_event = send_tracked_event(write_event, VC_EVENT_EOS, 
&write_vio);
-        } else if (read_vio.cont && read_vio.buffer.writer()) {
+        } else if (read_vio.cont && read_vio.get_writer()) {
           SCOPED_MUTEX_LOCK(lock, read_vio.mutex, this_ethread());
           Http2StreamDebug("Send tracked event VC_EVENT_EOS on read_vio. 
sm_id: %" PRId64, _sm->sm_id);
           read_event = send_tracked_event(read_event, VC_EVENT_EOS, &read_vio);
@@ -738,7 +738,7 @@ Http2Stream::update_read_request(bool call_update)
     send_event = VC_EVENT_READ_COMPLETE;
   }
 
-  int64_t read_avail = this->read_vio.buffer.writer()->max_read_avail();
+  int64_t read_avail = this->read_vio.get_writer()->max_read_avail();
   if (read_avail > 0 || send_event == VC_EVENT_READ_COMPLETE) {
     if (call_update) { // Safe to call vio handler directly
       _timeout.update_inactivity();
diff --git a/src/proxy/http3/Http3Transaction.cc 
b/src/proxy/http3/Http3Transaction.cc
index 6ab2041590..960a8995ea 100644
--- a/src/proxy/http3/Http3Transaction.cc
+++ b/src/proxy/http3/Http3Transaction.cc
@@ -118,7 +118,7 @@ VIO *
 HQTransaction::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf)
 {
   if (buf) {
-    this->_read_vio.buffer.writer_for(buf);
+    this->_read_vio.set_writer(buf);
   } else {
     this->_read_vio.buffer.clear();
   }
@@ -142,7 +142,7 @@ VIO *
 HQTransaction::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader 
*buf, bool /* owner ATS_UNUSED */)
 {
   if (buf) {
-    this->_write_vio.buffer.reader_for(buf);
+    this->_write_vio.set_reader(buf);
   } else {
     this->_write_vio.buffer.clear();
   }

Reply via email to