net/SocketAddress: add std::span cast operators
This commit is contained in:
parent
81afb47cd0
commit
8aa4227c0c
@ -79,6 +79,12 @@ public:
|
|||||||
size_type _size) noexcept
|
size_type _size) noexcept
|
||||||
:address(_address), size(_size) {}
|
:address(_address), size(_size) {}
|
||||||
|
|
||||||
|
#ifdef __cpp_lib_span
|
||||||
|
explicit SocketAddress(std::span<const std::byte> src) noexcept
|
||||||
|
:address((const struct sockaddr *)(const void *)src.data()),
|
||||||
|
size(src.size()) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
static constexpr SocketAddress Null() noexcept {
|
static constexpr SocketAddress Null() noexcept {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -165,6 +171,14 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cpp_lib_span
|
#ifdef __cpp_lib_span
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
Loading…
Reference in New Issue
Block a user