net/SocketAddress: add #ifdefs for std::span
This commit is contained in:
@@ -30,7 +30,6 @@
|
|||||||
#include "AllocatedSocketAddress.hxx"
|
#include "AllocatedSocketAddress.hxx"
|
||||||
#include "IPv4Address.hxx"
|
#include "IPv4Address.hxx"
|
||||||
#include "IPv6Address.hxx"
|
#include "IPv6Address.hxx"
|
||||||
#include "util/StringView.hxx"
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@@ -131,6 +131,8 @@ SocketAddress::GetPort() const noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_span
|
||||||
|
|
||||||
static std::span<const std::byte>
|
static std::span<const std::byte>
|
||||||
GetSteadyPart(const struct sockaddr_in &address) noexcept
|
GetSteadyPart(const struct sockaddr_in &address) noexcept
|
||||||
{
|
{
|
||||||
@@ -149,7 +151,11 @@ GetSteadyPart(const struct sockaddr_in6 &address) noexcept
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // __cpp_lib_span
|
||||||
|
|
||||||
|
#endif // HAVE_TCP
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_span
|
||||||
|
|
||||||
std::span<const std::byte>
|
std::span<const std::byte>
|
||||||
SocketAddress::GetSteadyPart() const noexcept
|
SocketAddress::GetSteadyPart() const noexcept
|
||||||
@@ -175,3 +181,5 @@ SocketAddress::GetSteadyPart() const noexcept
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@@ -39,7 +39,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
|
#if __cplusplus >= 202002 || (defined(__GNUC__) && __GNUC__ >= 10)
|
||||||
|
#include <version>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_span
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UN
|
#ifdef HAVE_UN
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -72,10 +79,6 @@ public:
|
|||||||
size_type _size) noexcept
|
size_type _size) noexcept
|
||||||
:address(_address), size(_size) {}
|
:address(_address), size(_size) {}
|
||||||
|
|
||||||
explicit SocketAddress(std::span<const std::byte> src) noexcept
|
|
||||||
:address((const struct sockaddr *)(const void *)src.data()),
|
|
||||||
size(src.size()) {}
|
|
||||||
|
|
||||||
static constexpr SocketAddress Null() noexcept {
|
static constexpr SocketAddress Null() noexcept {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -161,14 +164,7 @@ public:
|
|||||||
unsigned GetPort() const noexcept;
|
unsigned GetPort() const noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
operator std::span<const std::byte>() const noexcept {
|
#ifdef __cpp_lib_span
|
||||||
const void *q = reinterpret_cast<const void *>(address);
|
|
||||||
return {
|
|
||||||
(const std::byte *)q,
|
|
||||||
(std::size_t)size,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a buffer pointing to the "steady" portion of the
|
* Return a buffer pointing to the "steady" portion of the
|
||||||
* address, i.e. without volatile parts like the port number.
|
* address, i.e. without volatile parts like the port number.
|
||||||
@@ -178,6 +174,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
std::span<const std::byte> GetSteadyPart() const noexcept;
|
std::span<const std::byte> GetSteadyPart() const noexcept;
|
||||||
|
#endif
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool operator==(const SocketAddress other) const noexcept;
|
bool operator==(const SocketAddress other) const noexcept;
|
||||||
|
Reference in New Issue
Block a user