net/StaticSocketAddress: add constexpr
This commit is contained in:
parent
b15b2125e2
commit
0fd6f83766
@ -1,8 +1,7 @@
|
|||||||
// SPDX-License-Identifier: BSD-2-Clause
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
// author: Max Kellermann <max.kellermann@gmail.com>
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
||||||
|
|
||||||
#ifndef STATIC_SOCKET_ADDRESS_HXX
|
#pragma once
|
||||||
#define STATIC_SOCKET_ADDRESS_HXX
|
|
||||||
|
|
||||||
#include "SocketAddress.hxx" // IWYU pragma: export
|
#include "SocketAddress.hxx" // IWYU pragma: export
|
||||||
#include "Features.hxx"
|
#include "Features.hxx"
|
||||||
@ -24,7 +23,7 @@ private:
|
|||||||
struct sockaddr_storage address;
|
struct sockaddr_storage address;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StaticSocketAddress() = default;
|
constexpr StaticSocketAddress() noexcept = default;
|
||||||
|
|
||||||
explicit StaticSocketAddress(SocketAddress src) noexcept {
|
explicit StaticSocketAddress(SocketAddress src) noexcept {
|
||||||
*this = src;
|
*this = src;
|
||||||
@ -61,11 +60,11 @@ public:
|
|||||||
return sizeof(address);
|
return sizeof(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_type GetSize() const noexcept {
|
constexpr size_type GetSize() const noexcept {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSize(size_type _size) noexcept {
|
constexpr void SetSize(size_type _size) noexcept {
|
||||||
assert(_size > 0);
|
assert(_size > 0);
|
||||||
assert(size_t(_size) <= sizeof(address));
|
assert(size_t(_size) <= sizeof(address));
|
||||||
|
|
||||||
@ -75,19 +74,19 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Set the size to the maximum value for this class.
|
* Set the size to the maximum value for this class.
|
||||||
*/
|
*/
|
||||||
void SetMaxSize() {
|
constexpr void SetMaxSize() {
|
||||||
SetSize(GetCapacity());
|
SetSize(GetCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFamily() const noexcept {
|
constexpr int GetFamily() const noexcept {
|
||||||
return address.ss_family;
|
return address.ss_family;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDefined() const noexcept {
|
constexpr bool IsDefined() const noexcept {
|
||||||
return GetFamily() != AF_UNSPEC;
|
return GetFamily() != AF_UNSPEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() noexcept {
|
constexpr void Clear() noexcept {
|
||||||
size = sizeof(address.ss_family);
|
size = sizeof(address.ss_family);
|
||||||
address.ss_family = AF_UNSPEC;
|
address.ss_family = AF_UNSPEC;
|
||||||
}
|
}
|
||||||
@ -130,5 +129,3 @@ public:
|
|||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user