Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions iocore/eventsystem/IOBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,23 @@ init_buffer_allocators(int iobuffer_advice)
auto
make_buffer_size_parser()
{
return [l = swoc::Lexicon<int>{
{{0, {"128"}},
{1, {"256"}},
{2, {"512"}},
{3, {"1k", "1024"}},
{4, {"2k", "2048"}},
{5, {"4k", "4096"}},
{6, {"8k", "8192"}},
{7, {"16k"}},
{8, {"32k"}},
{9, {"64k"}},
{10, {"128k"}},
{11, {"256k"}},
{12, {"512k"}},
{13, {"1M", "1024k"}},
{14, {"2M", "2048k"}}},
using L = swoc::Lexicon<int>;
return [l = L{
L::with_multi{{0, {"128"}},
{1, {"256"}},
{2, {"512"}},
{3, {"1k", "1024"}},
{4, {"2k", "2048"}},
{5, {"4k", "4096"}},
{6, {"8k", "8192"}},
{7, {"16k"}},
{8, {"32k"}},
{9, {"64k"}},
{10, {"128k"}},
{11, {"256k"}},
{12, {"512k"}},
{13, {"1M", "1024k"}},
{14, {"2M", "2048k"}}},
-1
}](swoc::TextView esize) -> std::optional<int> {
int result = l[esize];
Expand Down
2 changes: 1 addition & 1 deletion lib/swoc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)

project(Lib-SWOC CXX)
set(LIBSWOC_VERSION "1.4.9")
set(LIBSWOC_VERSION "1.4.10")
set(CMAKE_CXX_STANDARD 17)
cmake_policy(SET CMP0087 NEW)
# override "lib64" to be "lib" unless the user explicitly sets it.
Expand Down
2 changes: 1 addition & 1 deletion lib/swoc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ library_includedir=$(includedir)/swoc

AM_CPPFLAGS += @SWOC_INCLUDES@

libtsswoc_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -release 1.4.9
libtsswoc_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -release 1.4.10
libtsswoc_la_SOURCES = \
src/ArenaWriter.cc src/bw_format.cc src/bw_ip_format.cc src/Errata.cc src/MemArena.cc src/RBTree.cc src/swoc_file.cc src/swoc_ip.cc src/TextView.cc src/string_view_util.cc

Expand Down
10 changes: 1 addition & 9 deletions lib/swoc/include/swoc/BufferWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,9 @@
#include "swoc/swoc_version.h"
#include "swoc/TextView.h"
#include "swoc/MemSpan.h"
#include "swoc/bwf_fwd.h"

namespace swoc { inline namespace SWOC_VERSION_NS {
namespace bwf {
struct Spec;

class Format;

class NameBinding;

class ArgPack;
} // namespace bwf

/** Wrapper for operations on a buffer.
*
Expand Down
26 changes: 18 additions & 8 deletions lib/swoc/include/swoc/IPAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ class IP6Addr {
/// Number of bits per word.
static constexpr size_t WORD_WIDTH = std::numeric_limits<uint8_t>::digits * WORD_SIZE;

/// Mask the size of a word.
static constexpr word_type WORD_MASK = ~word_type(0);

/// Number of words used for basic address storage.
static constexpr size_t N_STORE = SIZE / WORD_SIZE;

Expand Down Expand Up @@ -1085,22 +1088,27 @@ IP6Addr::copy_to(sockaddr *sa) const {

inline IP6Addr &
IP6Addr::operator&=(IPMask const &mask) {
if (mask._cidr < WORD_WIDTH) {
_addr._store[MSW] &= (~word_type{0} << (WORD_WIDTH - mask._cidr));
if (0 == mask._cidr) {
_addr._store[LSW] = _addr._store[MSW] = 0;
} else if (mask._cidr < WORD_WIDTH) {
_addr._store[MSW] &= (WORD_MASK << (WORD_WIDTH - mask._cidr));
_addr._store[LSW] = 0;
} else if (mask._cidr < WIDTH) {
_addr._store[LSW] &= (~word_type{0} << (2 * WORD_WIDTH - mask._cidr));
_addr._store[LSW] &= (WORD_MASK << (2 * WORD_WIDTH - mask._cidr));
}
return *this;
}

inline IP6Addr &
IP6Addr::operator|=(IPMask const &mask) {
if (mask._cidr < WORD_WIDTH) {
_addr._store[MSW] |= (~word_type{0} >> mask._cidr);
_addr._store[LSW] = ~word_type{0};
if (0 == mask._cidr) { // do nothing in this case.
} else if (0 < mask._cidr && mask._cidr < WORD_WIDTH) {
_addr._store[MSW] |= (WORD_MASK >> mask._cidr);
_addr._store[LSW] = WORD_MASK;
} else if (mask._cidr < WIDTH) {
_addr._store[LSW] |= (~word_type{0} >> (mask._cidr - WORD_WIDTH));
_addr._store[LSW] |= (WORD_MASK >> (mask._cidr - WORD_WIDTH));
} else {
_addr._store[LSW] = _addr._store[MSW] = WORD_MASK;
}
return *this;
}
Expand Down Expand Up @@ -1138,7 +1146,9 @@ inline IP4Addr
IPMask::as_ip4() const {
static constexpr auto MASK = ~in_addr_t{0};
in_addr_t addr = MASK;
if (_cidr < IP4Addr::WIDTH) {
if (0 == _cidr) {
addr = in_addr_t(0);
} else if (_cidr < IP4Addr::WIDTH) {
addr <<= IP4Addr::WIDTH - _cidr;
}
return IP4Addr{addr};
Expand Down
72 changes: 53 additions & 19 deletions lib/swoc/include/swoc/IPRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,17 @@ class IP4Net {
/// @return @c true if the network is valid, @c false if not.
bool is_valid() const;

/// @return THh smallest address in the network.
IP4Addr lower_bound() const;
/// @return Network address - smallest address in the network.
IP4Addr min() const;

/// @return The largest address in the network.
IP4Addr max() const;

/// @return Network address.
[[deprecated]] IP4Addr lower_bound() const;

/// @return The largest address in the network.
IP4Addr upper_bound() const;
[[deprecated]] IP4Addr upper_bound() const;

/// @return The mask for the network.
IPMask const &mask() const;
Expand Down Expand Up @@ -628,11 +634,17 @@ class IP6Net {
/// @return @c true if the network is valid, @c false if not.
bool is_valid() const;

/// @return Network address - smallest address in the network.
IP6Addr min() const;

/// @return Largest address in the network.
IP6Addr max() const;

/// @return THh smallest address in the network.
IP6Addr lower_bound() const;
[[deprecated]] IP6Addr lower_bound() const;

/// @return The largest address in the network.
IP6Addr upper_bound() const;
[[deprecated]] IP6Addr upper_bound() const;

/// @return The mask for the network.
IPMask const &mask() const;
Expand Down Expand Up @@ -698,11 +710,17 @@ class IPNet {
/// @return @c true if the network is valid, @c false if not.
bool is_valid() const;

/// @return Network address - smallest address in the network.
IPAddr min() const;

/// @return Largest address in the network.
IPAddr max() const;

/// @return THh smallest address in the network.
IPAddr lower_bound() const;
[[deprecated]] IPAddr lower_bound() const;

/// @return The largest address in the network.
IPAddr upper_bound() const;
[[deprecated]] IPAddr upper_bound() const;

IPMask::raw_type width() const;

Expand Down Expand Up @@ -1589,18 +1607,28 @@ IP4Net::is_valid() const {
}

inline IP4Addr
IP4Net::lower_bound() const {
IP4Net::min() const {
return _addr;
}

inline IP4Addr
IP4Net::upper_bound() const {
IP4Net::max() const {
return _addr | _mask;
}

inline IP4Addr
IP4Net::lower_bound() const {
return this->min();
}

inline IP4Addr
IP4Net::upper_bound() const {
return this->max();
}

inline IP4Range
IP4Net::as_range() const {
return {this->lower_bound(), this->upper_bound()};
return {this->min(), this->max()};
}

inline bool
Expand Down Expand Up @@ -1633,18 +1661,21 @@ IP6Net::is_valid() const {
}

inline IP6Addr
IP6Net::lower_bound() const {
IP6Net::min() const {
return _addr;
}

inline IP6Addr
IP6Net::upper_bound() const {
IP6Net::max() const {
return _addr | _mask;
}

inline IP6Addr IP6Net::lower_bound() const { return this->min(); }
inline IP6Addr IP6Net::upper_bound() const { return this->max(); }

inline IP6Range
IP6Net::as_range() const {
return {this->lower_bound(), this->upper_bound()};
return {this->min(), this->max()};
}

inline bool
Expand Down Expand Up @@ -1676,15 +1707,18 @@ IPNet::is_valid() const {
}

inline IPAddr
IPNet::lower_bound() const {
IPNet::min() const {
return _addr;
}

inline IPAddr
IPNet::upper_bound() const {
IPNet::max() const {
return _addr | _mask;
}

inline IPAddr IPNet::lower_bound() const { return this->min(); }
inline IPAddr IPNet::upper_bound() const { return this->max(); }

inline IPMask::raw_type
IPNet::width() const {
return _mask.width();
Expand All @@ -1697,7 +1731,7 @@ IPNet::mask() const {

inline IPRange
IPNet::as_range() const {
return {this->lower_bound(), this->upper_bound()};
return {this->min(), this->max()};
}

inline IPNet::self_type &
Expand Down Expand Up @@ -2222,7 +2256,7 @@ template <size_t IDX>
typename std::tuple_element<IDX, IP4Net>::type
get(swoc::IP4Net const &net) {
if constexpr (IDX == 0) {
return net.lower_bound();
return net.min();
} else if constexpr (IDX == 1) {
return net.mask();
}
Expand All @@ -2232,7 +2266,7 @@ template <size_t IDX>
typename std::tuple_element<IDX, IP6Net>::type
get(swoc::IP6Net const &net) {
if constexpr (IDX == 0) {
return net.lower_bound();
return net.min();
} else if constexpr (IDX == 1) {
return net.mask();
}
Expand All @@ -2242,7 +2276,7 @@ template <size_t IDX>
typename std::tuple_element<IDX, IPNet>::type
get(swoc::IPNet const &net) {
if constexpr (IDX == 0) {
return net.lower_bound();
return net.min();
} else if constexpr (IDX == 1) {
return net.mask();
}
Expand Down
Loading