gms/inet_address: mark methods noexcept

Based on the corresponding net::inet_address calls.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
This commit is contained in:
Benny Halevy
2020-10-06 08:36:42 +03:00
parent 1734205315
commit 232fc19525
2 changed files with 16 additions and 11 deletions

View File

@@ -47,6 +47,10 @@
using namespace seastar;
static_assert(std::is_nothrow_default_constructible_v<gms::inet_address>);
static_assert(std::is_nothrow_copy_constructible_v<gms::inet_address>);
static_assert(std::is_nothrow_move_constructible_v<gms::inet_address>);
future<gms::inet_address> gms::inet_address::lookup(sstring name, opt_family family, opt_family preferred) {
return seastar::net::dns::get_host_by_name(name, family).then([preferred](seastar::net::hostent&& h) {
for (auto& addr : h.addr_list) {

View File

@@ -38,26 +38,27 @@ private:
net::inet_address _addr;
public:
inet_address() = default;
inet_address(int32_t ip)
inet_address(int32_t ip) noexcept
: inet_address(uint32_t(ip)) {
}
explicit inet_address(uint32_t ip)
explicit inet_address(uint32_t ip) noexcept
: _addr(net::ipv4_address(ip)) {
}
inet_address(const net::inet_address& addr) : _addr(addr) {}
inet_address(const socket_address& sa)
inet_address(const net::inet_address& addr) noexcept : _addr(addr) {}
inet_address(const socket_address& sa) noexcept
: inet_address(sa.addr())
{}
const net::inet_address& addr() const {
const net::inet_address& addr() const noexcept {
return _addr;
}
inet_address(const inet_address&) = default;
operator const seastar::net::inet_address&() const {
operator const seastar::net::inet_address&() const noexcept {
return _addr;
}
// throws std::invalid_argument if sstring is invalid
inet_address(const sstring& addr) {
// FIXME: We need a real DNS resolver
if (addr == "localhost") {
@@ -66,7 +67,7 @@ public:
_addr = net::inet_address(addr);
}
}
bytes_view bytes() const {
bytes_view bytes() const noexcept {
return bytes_view(reinterpret_cast<const int8_t*>(_addr.data()), _addr.size());
}
// TODO remove
@@ -76,14 +77,14 @@ public:
sstring to_sstring() const {
return format("{}", *this);
}
friend inline bool operator==(const inet_address& x, const inet_address& y) {
friend inline bool operator==(const inet_address& x, const inet_address& y) noexcept {
return x._addr == y._addr;
}
friend inline bool operator!=(const inet_address& x, const inet_address& y) {
friend inline bool operator!=(const inet_address& x, const inet_address& y) noexcept {
using namespace std::rel_ops;
return x._addr != y._addr;
}
friend inline bool operator<(const inet_address& x, const inet_address& y) {
friend inline bool operator<(const inet_address& x, const inet_address& y) noexcept {
return x.bytes() < y.bytes();
}
friend struct std::hash<inet_address>;
@@ -100,6 +101,6 @@ std::ostream& operator<<(std::ostream& os, const inet_address& x);
namespace std {
template<>
struct hash<gms::inet_address> {
size_t operator()(gms::inet_address a) const { return std::hash<net::inet_address>()(a._addr); }
size_t operator()(gms::inet_address a) const noexcept { return std::hash<net::inet_address>()(a._addr); }
};
}