net/AllocatedSocketAddress: add SetLocal() overload with std::string_view
This commit is contained in:
parent
4ba288501d
commit
6830cf9dcf
@ -62,6 +62,27 @@ AllocatedSocketAddress::SetLocal(const char *path) noexcept
|
|||||||
sun->sun_path[0] = 0;
|
sun->sun_path[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AllocatedSocketAddress::SetLocal(std::string_view path) noexcept
|
||||||
|
{
|
||||||
|
const bool is_abstract = path.starts_with('@');
|
||||||
|
|
||||||
|
/* sun_path must be null-terminated unless it's an abstract
|
||||||
|
socket */
|
||||||
|
const size_t path_length = path.size() + !is_abstract;
|
||||||
|
|
||||||
|
struct sockaddr_un *sun;
|
||||||
|
SetSize(sizeof(*sun) - sizeof(sun->sun_path) + path_length);
|
||||||
|
sun = (struct sockaddr_un *)address;
|
||||||
|
sun->sun_family = AF_LOCAL;
|
||||||
|
|
||||||
|
auto out = std::copy(path.begin(), path.end(), sun->sun_path);
|
||||||
|
if (is_abstract)
|
||||||
|
sun->sun_path[0] = 0;
|
||||||
|
else
|
||||||
|
*out = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TCP
|
#ifdef HAVE_TCP
|
||||||
|
@ -141,6 +141,7 @@ public:
|
|||||||
* address.
|
* address.
|
||||||
*/
|
*/
|
||||||
void SetLocal(const char *path) noexcept;
|
void SetLocal(const char *path) noexcept;
|
||||||
|
void SetLocal(std::string_view path) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_TCP
|
#ifdef HAVE_TCP
|
||||||
|
Loading…
Reference in New Issue
Block a user