trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpe...@apache.org
Subject git commit: TS-1911: make MIOBufferAccessor members private
Date Mon, 20 May 2013 14:24:36 GMT
Updated Branches:
  refs/heads/master fe5d32cd8 -> ff2fd580a


TS-1911: make MIOBufferAccessor members private

We already have sensibly-named accessors for the MIOBufferAccessor
members, so there's no need to access the internals directly. Make
the members private and use the accessors wherever necessary. This
exposes some places that don't use the proper APIs, so fix those
too.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/ff2fd580
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/ff2fd580
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/ff2fd580

Branch: refs/heads/master
Commit: ff2fd580a9a0f49f7fe5e16cb79147b355655b71
Parents: fe5d32c
Author: James Peach <jpeach@apache.org>
Authored: Tue May 14 19:17:55 2013 -0700
Committer: James Peach <jpeach@apache.org>
Committed: Mon May 20 10:23:57 2013 -0400

----------------------------------------------------------------------
 CHANGES                              |    2 +
 iocore/cache/CacheRead.cc            |    6 ++--
 iocore/cluster/ClusterHandler.cc     |    6 ++--
 iocore/cluster/ClusterVConnection.cc |    4 +-
 iocore/eventsystem/I_IOBuffer.h      |   35 +++++++++++++---------------
 iocore/eventsystem/P_IOBuffer.h      |   13 ++--------
 iocore/net/SSLNetVConnection.cc      |   10 +++++---
 iocore/net/UnixNetVConnection.cc     |    9 +++++--
 iocore/utils/OneWayTunnel.cc         |   18 ++++++++++-----
 9 files changed, 53 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 650ba18..05a5149 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
   Changes with Apache Traffic Server 3.3.3
 
 
+  *) [TS-1911] Enforce MIOBufferAccessor accessor API.
+
   *) [TS-1909] Remove duplicate listen socket conditioning.
 
   *) [TS-1896] Cleanup of unused defines, sometimes duplicated.

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/cache/CacheRead.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 534e51d..47d97d9 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -496,7 +496,7 @@ CacheVC::openReadFromWriterMain(int event, Event * e)
   }
   b = iobufferblock_clone(writer_buf, writer_offset, bytes);
   writer_buf = iobufferblock_skip(writer_buf, &writer_offset, &length, bytes);
-  vio.buffer.mbuf->append_block(b);
+  vio.buffer.writer()->append_block(b);
   vio.ndone += bytes;
   if (vio.ntodo() <= 0)
     return calluser(VC_EVENT_READ_COMPLETE);
@@ -694,7 +694,7 @@ CacheVC::openReadMain(int event, Event * e)
   }
   if (ntodo <= 0)
     return EVENT_CONT;
-  if (vio.buffer.mbuf->max_read_avail() > vio.buffer.writer()->water_mark &&
vio.ndone) // initiate read of first block
+  if (vio.buffer.writer()->max_read_avail() > vio.buffer.writer()->water_mark &&
vio.ndone) // initiate read of first block
     return EVENT_CONT;
   if ((bytes <= 0) && vio.ntodo() >= 0)
     goto Lread;
@@ -702,7 +702,7 @@ CacheVC::openReadMain(int event, Event * e)
     bytes = vio.ntodo();
   b = new_IOBufferBlock(buf, bytes, doc_pos);
   b->_buf_end = b->_end;
-  vio.buffer.mbuf->append_block(b);
+  vio.buffer.writer()->append_block(b);
   vio.ndone += bytes;
   doc_pos += bytes;
   if (vio.ntodo() <= 0)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/cluster/ClusterHandler.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterHandler.cc b/iocore/cluster/ClusterHandler.cc
index 770aa89..34eb29e 100644
--- a/iocore/cluster/ClusterHandler.cc
+++ b/iocore/cluster/ClusterHandler.cc
@@ -349,13 +349,13 @@ ClusterHandler::vc_ok_write(ClusterVConnection * vc)
 {
   return (((vc->closed > 0)
            && (vc->write_list || vc->write_bytes_in_transit)) ||
-          (!vc->closed && vc->write.enabled && vc->write.vio.op
== VIO::WRITE && vc->write.vio.buffer.mbuf));
+          (!vc->closed && vc->write.enabled && vc->write.vio.op
== VIO::WRITE && vc->write.vio.buffer.writer()));
 }
 
 inline bool
 ClusterHandler::vc_ok_read(ClusterVConnection * vc)
 {
-  return (!vc->closed && vc->read.vio.op == VIO::READ && vc->read.vio.buffer.mbuf);
+  return (!vc->closed && vc->read.vio.op == VIO::READ && vc->read.vio.buffer.writer());
 }
 
 void
@@ -1539,7 +1539,7 @@ ClusterHandler::update_channels_written(bool bump_unhandled_channels)
       ink_assert(!((ProxyMutex *) vc->write_locked));
       MUTEX_TRY_LOCK_SPIN(lock, vc->write.vio.mutex, thread, WRITE_LOCK_SPIN_COUNT);
       if (lock) {
-        n = vc->write.vio.buffer.mbuf ? vc->write.vio.buffer.reader()->block_read_avail()
: 0;
+        n = vc->write.vio.buffer.writer() ? vc->write.vio.buffer.reader()->block_read_avail()
: 0;
       } else {
         n = 0;
       }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/cluster/ClusterVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterVConnection.cc b/iocore/cluster/ClusterVConnection.cc
index 74d387e..0a80e02 100644
--- a/iocore/cluster/ClusterVConnection.cc
+++ b/iocore/cluster/ClusterVConnection.cc
@@ -165,13 +165,13 @@ ClusterVConnectionBase::reenable(VIO * vio)
   if (vio == &read.vio) {
     read.enabled = 1;
 #ifdef DEBUG
-    if (enable_debug_trace && (vio->buffer.mbuf && !vio->buffer.writer()->write_avail()))
+    if (enable_debug_trace && (vio->buffer.writer() && !vio->buffer.writer()->write_avail()))
       printf("NetVConnection re-enabled for read when full\n");
 #endif
   } else if (vio == &write.vio) {
     write.enabled = 1;
 #ifdef DEBUG
-    if (enable_debug_trace && (vio->buffer.mbuf && !vio->buffer.reader()->read_avail()))
+    if (enable_debug_trace && (vio->buffer.writer() && !vio->buffer.reader()->read_avail()))
       printf("NetVConnection re-enabled for write when empty\n");
 #endif
   } else {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/eventsystem/I_IOBuffer.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/I_IOBuffer.h b/iocore/eventsystem/I_IOBuffer.h
index 3a8ab08..5b44e17 100644
--- a/iocore/eventsystem/I_IOBuffer.h
+++ b/iocore/eventsystem/I_IOBuffer.h
@@ -1155,21 +1155,19 @@ public:
 */
 struct MIOBufferAccessor
 {
-  IOBufferReader *reader()
-  {
+  IOBufferReader * reader() {
     return entry;
   }
-  MIOBuffer *writer()
-  {
+
+  MIOBuffer * writer() {
     return mbuf;
   }
 
-  int64_t block_size()
-  {
+  int64_t block_size() const {
     return mbuf->block_size();
   }
-  int64_t total_size()
-  {
+
+  int64_t total_size() const {
     return block_size();
   }
 
@@ -1177,33 +1175,32 @@ struct MIOBufferAccessor
   void reader_for(MIOBuffer * abuf);
   void writer_for(MIOBuffer * abuf);
 
-  void clear();
-  void reset()
-  {
+  void clear() {
     mbuf = NULL;
     entry = NULL;
   }
 
-// private:
-
-  MIOBuffer *mbuf;
-  IOBufferReader *entry;
-
-MIOBufferAccessor():mbuf(NULL), entry(NULL)
+  MIOBufferAccessor():
 #ifdef DEBUG
-    , name(NULL)
+    name(NULL),
 #endif
+    mbuf(NULL), entry(NULL)
   {
   }
+
   ~MIOBufferAccessor();
 
 #ifdef DEBUG
-  const char *name;
+  const char * name;
 #endif
 
 private:
   MIOBufferAccessor(const MIOBufferAccessor &);
   MIOBufferAccessor & operator =(const MIOBufferAccessor &);
+
+  MIOBuffer *mbuf;
+  IOBufferReader *entry;
+
 };
 
 extern MIOBuffer * new_MIOBuffer_internal(

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/eventsystem/P_IOBuffer.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
index 8f9189a..98bdda2 100644
--- a/iocore/eventsystem/P_IOBuffer.h
+++ b/iocore/eventsystem/P_IOBuffer.h
@@ -1114,9 +1114,9 @@ TS_INLINE void
 MIOBuffer::dealloc_reader(IOBufferReader * e)
 {
   if (e->accessor) {
-    ink_assert(e->accessor->mbuf == this);
-    ink_assert(e->accessor->entry == e);
-    e->accessor->reset();
+    ink_assert(e->accessor->writer() == this);
+    ink_assert(e->accessor->reader() == e);
+    e->accessor->clear();
   }
   e->clear();
 }
@@ -1174,13 +1174,6 @@ MIOBufferAccessor::writer_for(MIOBuffer * abuf)
   entry = NULL;
 }
 
-TS_INLINE void
-MIOBufferAccessor::clear()
-{
-  entry = NULL;
-  mbuf = NULL;
-}
-
 TS_INLINE
 MIOBufferAccessor::~
 MIOBufferAccessor()

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/net/SSLNetVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc
index ed30201..e114895 100644
--- a/iocore/net/SSLNetVConnection.cc
+++ b/iocore/net/SSLNetVConnection.cc
@@ -80,7 +80,7 @@ ssl_read_from_net(UnixNetVConnection * vc, EThread * lthread, int64_t &ret)
   NetState *s = &vc->read;
   SSLNetVConnection *sslvc = (SSLNetVConnection *) vc;
   MIOBufferAccessor & buf = s->vio.buffer;
-  IOBufferBlock *b = buf.mbuf->_writer;
+  IOBufferBlock *b = buf.writer()->first_write_block();
   int event = SSL_READ_ERROR_NONE;
   int64_t bytes_read;
   int64_t block_write_avail;
@@ -282,7 +282,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread)
         writeReschedule(nh);
       return;
     }
-    // reset the tigger and remove from the ready queue
+    // reset the trigger and remove from the ready queue
     // we will need to be retriggered to read from this socket again
     read.triggered = 0;
     nh->read_ready_list.remove(this);
@@ -327,8 +327,10 @@ SSLNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted,
i
   ProxyMutex *mutex = this_ethread()->mutex;
   int64_t r = 0;
   int64_t l = 0;
-  int64_t offset = buf.entry->start_offset;
-  IOBufferBlock *b = buf.entry->block;
+
+  // XXX Rather than dealing with the block directly, we should use the IOBufferReader API.
+  int64_t offset = buf.reader()->start_offset;
+  IOBufferBlock *b = buf.reader()->block;
 
   do {
     // check if we have done this block

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/net/UnixNetVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc
index d975a41..007f341 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -240,7 +240,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread)
   int niov = 0;
   IOVec tiovec[NET_MAX_IOV];
   if (toread) {
-    IOBufferBlock *b = buf.mbuf->_writer;
+    IOBufferBlock *b = buf.writer()->first_write_block();
     do {
       niov = 0;
       rattempted = 0;
@@ -825,8 +825,11 @@ int64_t
 UnixNetVConnection::load_buffer_and_write(int64_t towrite, int64_t &wattempted, int64_t
&total_wrote, MIOBufferAccessor & buf)
 {
   int64_t r = 0;
-  int64_t offset = buf.entry->start_offset;
-  IOBufferBlock *b = buf.entry->block;
+
+  // XXX Rather than dealing with the block directly, we should use the IOBufferReader API.
+  int64_t offset = buf.reader()->start_offset;
+  IOBufferBlock *b = buf.reader()->block;
+
   do {
     IOVec tiovec[NET_MAX_IOV];
     int niov = 0;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ff2fd580/iocore/utils/OneWayTunnel.cc
----------------------------------------------------------------------
diff --git a/iocore/utils/OneWayTunnel.cc b/iocore/utils/OneWayTunnel.cc
index afac1db..efe5011 100644
--- a/iocore/utils/OneWayTunnel.cc
+++ b/iocore/utils/OneWayTunnel.cc
@@ -326,10 +326,13 @@ OneWayTunnel::close_source_vio(int result)
 {
 
   if (vioSource) {
-    if (last_connection() || !single_buffer)
-      free_MIOBuffer(vioSource->buffer.mbuf);
-    if (close_source && free_vcs)
+    if (last_connection() || !single_buffer) {
+      free_MIOBuffer(vioSource->buffer.writer());
+      vioSource->buffer.clear();
+    }
+    if (close_source && free_vcs) {
       vioSource->vc_server->do_io_close(result ? lerrno : -1);
+    }
     vioSource = NULL;
     n_connections--;
   }
@@ -341,10 +344,13 @@ OneWayTunnel::close_target_vio(int result, VIO * vio)
 
   (void) vio;
   if (vioTarget) {
-    if (last_connection() || !single_buffer)
-      free_MIOBuffer(vioTarget->buffer.mbuf);
-    if (close_target && free_vcs)
+    if (last_connection() || !single_buffer) {
+      free_MIOBuffer(vioTarget->buffer.writer());
+      vioTarget->buffer.clear();
+    }
+    if (close_target && free_vcs) {
       vioTarget->vc_server->do_io_close(result ? lerrno : -1);
+    }
     vioTarget = NULL;
     n_connections--;
   }


Mime
View raw message