diff --git a/include/wccp/Wccp.h b/include/wccp/Wccp.h index 17a7e8eeb61..ffba07bad81 100644 --- a/include/wccp/Wccp.h +++ b/include/wccp/Wccp.h @@ -25,18 +25,18 @@ #include #include -#include "tscore/TsBuffer.h" -#include "tscore/Errata.h" +// INADDR_ANY +#include + #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 - /// WCCP Support. namespace wccp { diff --git a/src/wccp/Makefile.am b/src/wccp/Makefile.am index 704e76aa91d..25151ae1608 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 e56bb45761c..4bf3b6da85b 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 e3a46d760aa..7c0322dc73a 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 #include #include #include +#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; + // 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 @@ class MsgBuffer : protected ts::Buffer /// 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 @@ class HereIAmMsg : public BaseMsg 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 const &buffer); CacheIdComp m_cache_id; ///< Web cache identity info. CacheViewComp m_cache_view; ///< Web cache view. @@ -2090,7 +2087,7 @@ class ISeeYouMsg : public BaseMsg ); /// 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 @@ class RedirectAssignMsg : public BaseMsg ); /// 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 @@ class RemovalQueryMsg : public BaseMsg ); /// 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 @@ class Impl : public ts::IntrusivePtrCounter */ /// 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 @@ class CacheImpl : public Impl ); /// 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 @@ class RouterImpl : public Impl /// 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(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(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 40ffbf73482..9fd215c51d8 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(ats_malloc(size), size).rebind()); } 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 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);