-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/StaticSocketAddress: add
constexpr
- Loading branch information
1 parent
723932a
commit 18060b0
Showing
1 changed file
with
8 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#ifndef STATIC_SOCKET_ADDRESS_HXX | ||
#define STATIC_SOCKET_ADDRESS_HXX | ||
#pragma once | ||
|
||
#include "SocketAddress.hxx" // IWYU pragma: export | ||
#include "Features.hxx" | ||
|
@@ -24,7 +23,7 @@ private: | |
struct sockaddr_storage address; | ||
|
||
public: | ||
StaticSocketAddress() = default; | ||
constexpr StaticSocketAddress() noexcept = default; | ||
|
||
explicit StaticSocketAddress(SocketAddress src) noexcept { | ||
*this = src; | ||
|
@@ -61,11 +60,11 @@ public: | |
return sizeof(address); | ||
} | ||
|
||
size_type GetSize() const noexcept { | ||
constexpr size_type GetSize() const noexcept { | ||
return size; | ||
} | ||
|
||
void SetSize(size_type _size) noexcept { | ||
constexpr void SetSize(size_type _size) noexcept { | ||
assert(_size > 0); | ||
assert(size_t(_size) <= sizeof(address)); | ||
|
||
|
@@ -75,19 +74,19 @@ public: | |
/** | ||
* Set the size to the maximum value for this class. | ||
*/ | ||
void SetMaxSize() { | ||
constexpr void SetMaxSize() { | ||
SetSize(GetCapacity()); | ||
} | ||
|
||
int GetFamily() const noexcept { | ||
constexpr int GetFamily() const noexcept { | ||
return address.ss_family; | ||
} | ||
|
||
bool IsDefined() const noexcept { | ||
constexpr bool IsDefined() const noexcept { | ||
return GetFamily() != AF_UNSPEC; | ||
} | ||
|
||
void Clear() noexcept { | ||
constexpr void Clear() noexcept { | ||
size = sizeof(address.ss_family); | ||
address.ss_family = AF_UNSPEC; | ||
} | ||
|
@@ -130,5 +129,3 @@ public: | |
return !(*this == other); | ||
} | ||
}; | ||
|
||
#endif |