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