LibCore: Implement LocalSocket::adopt_fd
Similar to File::adopt_fd, this function creates a new LocalSocket with an existing fd. The main use of this function is to create LocalSocket objects from fds that have been passed to us by SystemServer to take over.
This commit is contained in:
parent
27b49a60d0
commit
92be52fd9f
Notes:
sideshowbarker
2024-07-17 20:52:27 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/92be52fd9f0 Pull-request: https://github.com/SerenityOS/serenity/pull/11890
2 changed files with 13 additions and 0 deletions
Userland/Libraries/LibCore
|
@ -536,6 +536,18 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalSocket::connect(String const& path)
|
|||
return socket;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<LocalSocket>> LocalSocket::adopt_fd(int fd)
|
||||
{
|
||||
if (fd < 0) {
|
||||
return Error::from_errno(EBADF);
|
||||
}
|
||||
|
||||
auto socket = TRY(adopt_nonnull_own_or_enomem(new (nothrow) LocalSocket()));
|
||||
socket->m_helper.set_fd(fd);
|
||||
socket->setup_notifier();
|
||||
return socket;
|
||||
}
|
||||
|
||||
ErrorOr<int> LocalSocket::receive_fd(int flags)
|
||||
{
|
||||
#ifdef __serenity__
|
||||
|
|
|
@ -379,6 +379,7 @@ private:
|
|||
class LocalSocket final : public Socket {
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<LocalSocket>> connect(String const& path);
|
||||
static ErrorOr<NonnullOwnPtr<LocalSocket>> adopt_fd(int fd);
|
||||
|
||||
LocalSocket(LocalSocket&& other)
|
||||
: Socket(static_cast<Socket&&>(other))
|
||||
|
|
Loading…
Add table
Reference in a new issue