net/SocketAddress: add std::span cast operator
This commit is contained in:
parent
5fb97b81d1
commit
774024a41b
@ -33,6 +33,7 @@
|
|||||||
#include "Features.hxx"
|
#include "Features.hxx"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <span>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <winsock2.h> // IWYU pragma: export
|
#include <winsock2.h> // IWYU pragma: export
|
||||||
@ -69,6 +70,10 @@ 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;
|
||||||
}
|
}
|
||||||
@ -154,6 +159,14 @@ public:
|
|||||||
unsigned GetPort() const noexcept;
|
unsigned GetPort() const noexcept;
|
||||||
#endif
|
#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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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