Skip to content

Commit

Permalink
net/StaticSocketAddress: add constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 15, 2024
1 parent 723932a commit 18060b0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/net/StaticSocketAddress.hxx
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"
Expand All @@ -24,7 +23,7 @@ private:
struct sockaddr_storage address;

public:
StaticSocketAddress() = default;
constexpr StaticSocketAddress() noexcept = default;

explicit StaticSocketAddress(SocketAddress src) noexcept {
*this = src;
Expand Down Expand Up @@ -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));

Expand All @@ -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;
}
Expand Down Expand Up @@ -130,5 +129,3 @@ public:
return !(*this == other);
}
};

#endif

0 comments on commit 18060b0

Please sign in to comment.