mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
Net: Add LocalSocket::socket_path()
This is a little utility function to safely extract the path without manually dealing with sun_path and null-termination.
This commit is contained in:
parent
8a975ff630
commit
a30930465e
Notes:
sideshowbarker
2024-07-19 12:44:42 +09:00
Author: https://github.com/bugaevc
Commit: a30930465e
Pull-request: https://github.com/SerenityOS/serenity/pull/434
Reviewed-by: https://github.com/awesomekling
2 changed files with 8 additions and 0 deletions
|
@ -227,3 +227,9 @@ ssize_t LocalSocket::recvfrom(FileDescription& description, void* buffer, size_t
|
||||||
}
|
}
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringView LocalSocket::socket_path() const
|
||||||
|
{
|
||||||
|
int len = strnlen(m_address.sun_path, sizeof(m_address.sun_path));
|
||||||
|
return { m_address.sun_path, len };
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ public:
|
||||||
static NonnullRefPtr<LocalSocket> create(int type);
|
static NonnullRefPtr<LocalSocket> create(int type);
|
||||||
virtual ~LocalSocket() override;
|
virtual ~LocalSocket() override;
|
||||||
|
|
||||||
|
|
||||||
|
StringView socket_path() const;
|
||||||
// ^Socket
|
// ^Socket
|
||||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||||
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue