net/SocketAddress: add method GetLocalPath()
This commit is contained in:
parent
1a516cf3c0
commit
864c87e6c0
@ -146,6 +146,14 @@ public:
|
||||
gcc_pure
|
||||
StringView GetLocalRaw() const noexcept;
|
||||
|
||||
/**
|
||||
* @see SocketAddress::GetLocalPath()
|
||||
*/
|
||||
gcc_pure
|
||||
const char *GetLocalPath() const noexcept {
|
||||
return ((SocketAddress)*this).GetLocalPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this a "local" address (UNIX domain socket). If the path
|
||||
* begins with a '@', then the rest specifies an "abstract" local
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -73,6 +73,21 @@ SocketAddress::GetLocalRaw() const noexcept
|
||||
return {path, size - header_size};
|
||||
}
|
||||
|
||||
const char *
|
||||
SocketAddress::GetLocalPath() const noexcept
|
||||
{
|
||||
const auto raw = GetLocalRaw();
|
||||
return !raw.empty() &&
|
||||
/* must be an absolute path */
|
||||
raw.front() == '/' &&
|
||||
/* must be null-terminated */
|
||||
raw.back() == 0 &&
|
||||
/* there must not be any other null byte */
|
||||
memchr(raw.data, 0, raw.size - 1) == nullptr
|
||||
? raw.data
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TCP
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 Max Kellermann <max.kellermann@gmail.com>
|
||||
* Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -106,6 +106,13 @@ public:
|
||||
*/
|
||||
gcc_pure
|
||||
StringView GetLocalRaw() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the local socket path or nullptr if not applicable
|
||||
* (or if the path is corrupt).
|
||||
*/
|
||||
gcc_pure
|
||||
const char *GetLocalPath() const noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TCP
|
||||
|
Loading…
Reference in New Issue
Block a user