diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp index b24b56514f..f0dbe57938 100644 --- a/Userland/Libraries/LibCore/Stream.cpp +++ b/Userland/Libraries/LibCore/Stream.cpp @@ -536,6 +536,18 @@ ErrorOr> LocalSocket::connect(String const& path) return socket; } +ErrorOr> 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 LocalSocket::receive_fd(int flags) { #ifdef __serenity__ diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h index d3820ab379..17d59ee408 100644 --- a/Userland/Libraries/LibCore/Stream.h +++ b/Userland/Libraries/LibCore/Stream.h @@ -379,6 +379,7 @@ private: class LocalSocket final : public Socket { public: static ErrorOr> connect(String const& path); + static ErrorOr> adopt_fd(int fd); LocalSocket(LocalSocket&& other) : Socket(static_cast(other))