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

amc 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 fc92d96a44 WCCP: remove ts::Buffer (#9824)
fc92d96a44 is described below

commit fc92d96a448337d81e0e24e3aa4cc6a8197a6261
Author: Alan M. Carroll <[email protected]>
AuthorDate: Thu Jun 15 15:35:38 2023 -0500

    WCCP: remove ts::Buffer (#9824)
---
 include/wccp/Wccp.h      | 10 +++---
 src/wccp/Makefile.am     |  2 +-
 src/wccp/WccpEndPoint.cc | 22 ++++++------
 src/wccp/WccpLocal.h     | 90 ++++++++++++++++++++++--------------------------
 src/wccp/WccpMsg.cc      |  8 ++---
 5 files changed, 63 insertions(+), 69 deletions(-)

diff --git a/include/wccp/Wccp.h b/include/wccp/Wccp.h
index 17a7e8eeb6..ffba07bad8 100644
--- a/include/wccp/Wccp.h
+++ b/include/wccp/Wccp.h
@@ -25,18 +25,18 @@
 #include <memory.h>
 #include <string_view>
 
-#include "tscore/TsBuffer.h"
-#include "tscore/Errata.h"
+// INADDR_ANY
+#include <netinet/in.h>
+
 #include "tscore/ink_defs.h"
 #include "tscore/ink_memory.h"
+#include "tscore/IntrusivePtr.h"
+#include "tscore/Errata.h"
 
 // Nasty, defining this with no prefix. The value is still available
 // in TS_VERSION_STRING.
 #undef VERSION
 
-// INADDR_ANY
-#include <netinet/in.h>
-
 /// WCCP Support.
 namespace wccp
 {
diff --git a/src/wccp/Makefile.am b/src/wccp/Makefile.am
index 704e76aa91..25151ae160 100644
--- a/src/wccp/Makefile.am
+++ b/src/wccp/Makefile.am
@@ -24,7 +24,7 @@ AM_CPPFLAGS += \
        -I$(abs_top_srcdir)/lib \
        -I$(abs_top_srcdir)/proxy \
        $(TS_INCLUDES) \
-       @YAMLCPP_INCLUDES@
+       @SWOC_INCLUDES@ @YAMLCPP_INCLUDES@
 
 noinst_LIBRARIES = libwccp.a
 
diff --git a/src/wccp/WccpEndPoint.cc b/src/wccp/WccpEndPoint.cc
index e56bb45761..4bf3b6da85 100644
--- a/src/wccp/WccpEndPoint.cc
+++ b/src/wccp/WccpEndPoint.cc
@@ -228,10 +228,10 @@ Impl::handleMessage()
 
   // Check to see if there is a valid header.
   MsgHeaderComp header;
-  MsgBuffer msg_buffer(buffer, n);
+  MsgBuffer msg_buffer(buffer_type(buffer, n));
   if (PARSE_SUCCESS == header.parse(msg_buffer)) {
     message_type_t msg_type = header.getType();
-    ts::Buffer chunk(buffer, n);
+    buffer_type chunk(buffer, n);
 
     switch (msg_type) {
     case HERE_I_AM:
@@ -257,22 +257,22 @@ Impl::handleMessage()
 }
 
 ts::Errata
-Impl::handleHereIAm(IpHeader const &, ts::Buffer const &)
+Impl::handleHereIAm(IpHeader const &, buffer_type const &)
 {
   return log(LVL_INFO, "Unanticipated WCCP2_HERE_I_AM message ignored");
 }
 ts::Errata
-Impl::handleISeeYou(IpHeader const &, ts::Buffer const & /* data ATS_UNUSED */)
+Impl::handleISeeYou(IpHeader const &, buffer_type const & /* data ATS_UNUSED 
*/)
 {
   return log(LVL_INFO, "Unanticipated WCCP2_I_SEE_YOU message ignored.");
 }
 ts::Errata
-Impl::handleRedirectAssign(IpHeader const &, ts::Buffer const & /* data 
ATS_UNUSED */)
+Impl::handleRedirectAssign(IpHeader const &, buffer_type const & /* data 
ATS_UNUSED */)
 {
   return log(LVL_INFO, "Unanticipated WCCP2_REDIRECT_ASSIGN message ignored.");
 }
 ts::Errata
-Impl::handleRemovalQuery(IpHeader const &, ts::Buffer const & /* data 
ATS_UNUSED */)
+Impl::handleRemovalQuery(IpHeader const &, buffer_type const & /* data 
ATS_UNUSED */)
 {
   return log(LVL_INFO, "Unanticipated WCCP2_REMOVAL_QUERY message ignored.");
 }
@@ -604,7 +604,7 @@ CacheImpl::housekeeping()
   static size_t const BUFFER_SIZE = 4096;
   MsgBuffer msg_buffer;
   char msg_data[BUFFER_SIZE];
-  msg_buffer.set(msg_data, BUFFER_SIZE);
+  msg_buffer.assign({msg_data, BUFFER_SIZE});
 
   // Set up everything except the IP address.
   memset(&dst_addr, 0, sizeof(dst_addr));
@@ -690,7 +690,7 @@ CacheImpl::housekeeping()
 }
 
 ts::Errata
-CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr ATS_UNUSED */, ts::Buffer 
const &chunk)
+CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr ATS_UNUSED */, buffer_type 
const &chunk)
 {
   ts::Errata zret;
   ISeeYouMsg msg;
@@ -849,7 +849,7 @@ CacheImpl::handleISeeYou(IpHeader const & /* ip_hdr 
ATS_UNUSED */, ts::Buffer co
 }
 
 ts::Errata
-CacheImpl::handleRemovalQuery(IpHeader const & /* ip_hdr ATS_UNUSED */, 
ts::Buffer const &chunk)
+CacheImpl::handleRemovalQuery(IpHeader const & /* ip_hdr ATS_UNUSED */, 
buffer_type const &chunk)
 {
   ts::Errata zret;
   RemovalQueryMsg msg;
@@ -937,7 +937,7 @@ RouterImpl::GroupData::resizeRouterSources()
 }
 
 ts::Errata
-RouterImpl::handleHereIAm(IpHeader const &ip_hdr, ts::Buffer const &chunk)
+RouterImpl::handleHereIAm(IpHeader const &ip_hdr, buffer_type const &chunk)
 {
   ts::Errata zret;
   HereIAmMsg msg;
@@ -1058,7 +1058,7 @@ RouterImpl::xmitISeeYou()
   memset(&dst_addr, 0, sizeof(dst_addr));
   dst_addr.sin_family = AF_INET;
   dst_addr.sin_port   = htons(DEFAULT_PORT);
-  buffer.set(data, BUFFER_SIZE);
+  buffer.assign({data, BUFFER_SIZE});
 
   // Send out messages for each service group.
   for (GroupMap::iterator svc_spot = m_groups.begin(), svc_limit = 
m_groups.end(); svc_spot != svc_limit; ++svc_spot) {
diff --git a/src/wccp/WccpLocal.h b/src/wccp/WccpLocal.h
index e3a46d760a..7c0322dc73 100644
--- a/src/wccp/WccpLocal.h
+++ b/src/wccp/WccpLocal.h
@@ -22,16 +22,18 @@
 
 #pragma once
 
-#include "wccp/Wccp.h"
-#include "WccpUtil.h"
-#include "ts/apidefs.h"
-#include "tscore/Errata.h"
 // Needed for template use of byte ordering functions.
 #include <netinet/in.h>
 #include <memory.h>
 #include <map>
 #include <string_view>
 
+#include "swoc/MemSpan.h"
+
+#include "wccp/Wccp.h"
+#include "WccpUtil.h"
+#include "ts/apidefs.h"
+
 namespace YAML
 {
 class Node;
@@ -39,6 +41,9 @@ class Node;
 
 namespace wccp
 {
+
+using buffer_type = swoc::MemSpan<char>;
+
 // Forward declares
 namespace detail
 {
@@ -97,24 +102,16 @@ static int const PARSE_DATA_OVERRUN = 10;
     Takes the basic ATS buffer and adds a count field to track
     the amount of buffer in use.
 */
-class MsgBuffer : protected ts::Buffer
+class MsgBuffer
 {
 public:
-  using self_type  = MsgBuffer;  ///< Self reference type.
-  using super_type = ts::Buffer; ///< Parent type.
+  using self_type = MsgBuffer; ///< Self reference type.
 
   MsgBuffer(); ///< Default construct empty buffer.
-  /// Construct from ATS buffer.
-  MsgBuffer(super_type const &that ///< Instance to copy.
-  );
-  /// Construct from pointer and size.
-  MsgBuffer(void *ptr, ///< Pointer to buffer.
-            size_t n   ///< Size of buffer.
-  );
+  /// Construct from span.
+  MsgBuffer(buffer_type const &span);
   /// Assign a buffer.
-  MsgBuffer &set(void *ptr, ///< Pointer to buffer.
-                 size_t n   ///< Size of buffer.
-  );
+  MsgBuffer &assign(buffer_type const &span);
 
   /// Get the buffer size.
   size_t getSize() const;
@@ -137,7 +134,8 @@ public:
   /// Reset and zero the buffer.
   self_type &zero();
 
-  size_t _count; ///< Number of bytes in use.
+  buffer_type _base;   ///< Original pointer.
+  buffer_type _active; ///< Unprocessed data, always a suffix of @a _base.
 };
 
 /// Sect 4.4: Cache assignment method.
@@ -2063,8 +2061,7 @@ public:
   void fill_caps(detail::cache::RouterData const &router ///< Target router.
   );
   /// Parse message data, presumed to be of this type.
-  int parse(ts::Buffer const &buffer ///< Raw message data.
-  );
+  int parse(swoc::MemSpan<char> const &buffer);
 
   CacheIdComp m_cache_id;     ///< Web cache identity info.
   CacheViewComp m_cache_view; ///< Web cache view.
@@ -2090,7 +2087,7 @@ public:
   );
 
   /// Parse message data, presumed to be of this type.
-  int parse(ts::Buffer const &buffer ///< Raw message data.
+  int parse(buffer_type const &buffer ///< Raw message data.
   );
 
   RouterIdComp m_router_id;     ///< Router ID.
@@ -2123,7 +2120,7 @@ public:
   );
 
   /// Parse message data, presumed to be of this type.
-  int parse(ts::Buffer const &buffer ///< Raw message data.
+  int parse(buffer_type const &buffer ///< Raw message data.
   );
 
   // Only one of these should be present in an instance.
@@ -2153,7 +2150,7 @@ public:
   );
 
   /// Parse message data, presumed to be of this type.
-  int parse(ts::Buffer const &buffer ///< Raw message data.
+  int parse(buffer_type const &buffer ///< Raw message data.
   );
 
   QueryComp m_query; ///< Router Removal Query component.
@@ -2235,19 +2232,19 @@ public:
   */
   /// Process HERE_I_AM message.
   virtual ts::Errata handleHereIAm(IpHeader const &header, ///< IP packet data.
-                                   ts::Buffer const &data  ///< Buffer with 
message data.
+                                   buffer_type const &data ///< Buffer with 
message data.
   );
   /// Process I_SEE_YOU message.
   virtual ts::Errata handleISeeYou(IpHeader const &header, ///< IP packet data.
-                                   ts::Buffer const &data  ///< Buffer with 
message data.
+                                   buffer_type const &data ///< Buffer with 
message data.
   );
   /// Process REDIRECT_ASSIGN message.
   virtual ts::Errata handleRedirectAssign(IpHeader const &header, ///< IP 
packet data.
-                                          ts::Buffer const &data  ///< Buffer 
with message data.
+                                          buffer_type const &data ///< Buffer 
with message data.
   );
   /// Process REMOVAL_QUERY message.
   virtual ts::Errata handleRemovalQuery(IpHeader const &header, ///< IP packet 
data.
-                                        ts::Buffer const &data  ///< Buffer 
with message data.
+                                        buffer_type const &data ///< Buffer 
with message data.
   );
 
 protected:
@@ -2520,11 +2517,11 @@ protected:
   );
   /// Process HERE_I_AM message.
   ts::Errata handleISeeYou(IpHeader const &header, ///< IP packet data.
-                           ts::Buffer const &data  ///< Buffer with message 
data.
+                           buffer_type const &data ///< Buffer with message 
data.
                            ) override;
   /// Process REMOVAL_QUERY message.
   ts::Errata handleRemovalQuery(IpHeader const &header, ///< IP packet data.
-                                ts::Buffer const &data  ///< Message data.
+                                buffer_type const &data ///< Message data.
                                 ) override;
 
   /// Map Service Group ID to Service Group Data.
@@ -2632,7 +2629,7 @@ public:
 
   /// Process HERE_I_AM message.
   ts::Errata handleHereIAm(IpHeader const &header, ///< IP packet data.
-                           ts::Buffer const &data  ///< Buffer with message 
data.
+                           buffer_type const &data ///< Buffer with message 
data.
                            ) override;
   /// Perform all scheduled housekeeping functions.
   int housekeeping() override;
@@ -3208,68 +3205,65 @@ detail::Assignment::getMask() const
   return *m_mask_assign;
 }
 
-inline MsgBuffer::MsgBuffer() : super_type(), _count(0) {}
-inline MsgBuffer::MsgBuffer(super_type const &that) : super_type(that), 
_count(0) {}
-inline MsgBuffer::MsgBuffer(void *p, size_t n) : super_type(static_cast<char 
*>(p), n), _count(0) {}
+inline MsgBuffer::MsgBuffer() {}
+inline MsgBuffer::MsgBuffer(buffer_type const &span) : _base(span), 
_active(span) {}
 
 inline size_t
 MsgBuffer::getSize() const
 {
-  return _size;
+  return _base.size();
 }
 inline size_t
 MsgBuffer::getCount() const
 {
-  return _count;
+  return _active.size();
 }
 inline char *
 MsgBuffer::getBase()
 {
-  return _ptr;
+  return _base.data();
 }
 inline const char *
 MsgBuffer::getBase() const
 {
-  return _ptr;
+  return _base.data();
 }
 inline char *
 MsgBuffer::getTail()
 {
-  return _ptr + _count;
+  return _active.data();
 }
 inline size_t
 MsgBuffer::getSpace() const
 {
-  return _size - _count;
+  return _active.size();
 }
 inline MsgBuffer &
 MsgBuffer::reset()
 {
-  _count = 0;
+  _active = _base;
   return *this;
 }
 
 inline MsgBuffer &
-MsgBuffer::set(void *ptr, size_t n)
+MsgBuffer::assign(buffer_type const &span)
 {
-  _ptr   = static_cast<char *>(ptr);
-  _size  = n;
-  _count = 0;
+  _base = _active = span;
   return *this;
 }
 
 inline MsgBuffer &
 MsgBuffer::use(size_t n)
 {
-  _count += std::min(n, this->getSpace());
+  _active.remove_prefix(n);
   return *this;
 }
 
 inline MsgBuffer &
 MsgBuffer::zero()
 {
-  memset(_ptr, 0, _size);
-  _count = 0;
+  memset(_base, 0);
+  _active = _base;
   return *this;
 }
 
@@ -3619,7 +3613,7 @@ inline detail::cache::SeedRouter::SeedRouter() {}
 
 inline detail::cache::SeedRouter::SeedRouter(uint32_t addr) : m_addr(addr), 
m_count(0), m_xmit(0) {}
 
-inline BaseMsg::BaseMsg() : m_buffer(0, 0) {}
+inline BaseMsg::BaseMsg() {}
 inline MsgBuffer const &
 BaseMsg::buffer() const
 {
diff --git a/src/wccp/WccpMsg.cc b/src/wccp/WccpMsg.cc
index 40ffbf7348..9fd215c51d 100644
--- a/src/wccp/WccpMsg.cc
+++ b/src/wccp/WccpMsg.cc
@@ -1587,7 +1587,7 @@ detail::Assignment::fill(cache::GroupData &group, 
uint32_t addr)
 
   if (m_buffer.getSize() < size) {
     ats_free(m_buffer.getBase());
-    m_buffer.set(ats_malloc(size), size);
+    m_buffer.assign(swoc::MemSpan<void>(ats_malloc(size), 
size).rebind<char>());
   }
   m_buffer.reset();
 
@@ -1690,7 +1690,7 @@ HereIAmMsg::fill_caps(detail::cache::RouterData const 
&router)
 }
 
 int
-HereIAmMsg::parse(ts::Buffer const &buffer)
+HereIAmMsg::parse(swoc::MemSpan<char> const &buffer)
 {
   int zret;
   this->setBuffer(buffer);
@@ -1760,7 +1760,7 @@ ISeeYouMsg::fill(detail::router::GroupData const &group, 
SecurityOption sec_opt,
 }
 
 int
-ISeeYouMsg::parse(ts::Buffer const &buffer)
+ISeeYouMsg::parse(buffer_type const &buffer)
 {
   int zret;
   this->setBuffer(buffer);
@@ -1814,7 +1814,7 @@ ISeeYouMsg::parse(ts::Buffer const &buffer)
 }
 // ------------------------------------------------------
 int
-RemovalQueryMsg::parse(ts::Buffer const &buffer)
+RemovalQueryMsg::parse(buffer_type const &buffer)
 {
   int zret;
   this->setBuffer(buffer);

Reply via email to