refactor: decouple tr_announcer_udp (#4002)

This commit is contained in:
Charles Kerr
2022-10-21 13:15:14 -05:00
committed by GitHub
parent 6187cfd67b
commit d191a04228
16 changed files with 1313 additions and 701 deletions

View File

@@ -56,6 +56,16 @@ public:
return Iterator(buf_, offset_ + n_bytes);
}
[[nodiscard]] Iterator operator-(int n_bytes)
{
return Iterator(buf_, offset_ - n_bytes);
}
[[nodiscard]] constexpr auto operator-(Iterator const& that) const noexcept
{
return offset_ - that.offset_;
}
Iterator& operator++() noexcept
{
if (iov_.iov_len > 1)
@@ -71,6 +81,19 @@ public:
return *this;
}
Iterator& operator+=(int n_bytes)
{
setOffset(offset_ + n_bytes);
return *this;
}
Iterator& operator--() noexcept
{
// TODO(ckerr) inefficient; calls evbuffer_ptr_peek() every time
setOffset(offset_ - 1);
return *this;
}
[[nodiscard]] constexpr bool operator==(Iterator const& that) const noexcept
{
return offset_ == that.offset_;
@@ -90,7 +113,7 @@ public:
evbuffer_peek(buf_, std::numeric_limits<ev_ssize_t>::max(), &ptr, &iov_, 1);
}
evbuffer* const buf_;
evbuffer* buf_;
Iovec iov_ = {};
size_t offset_ = 0;
};