1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

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:
sin-ack 2022-01-14 13:24:01 +00:00 committed by Ali Mohammad Pur
parent 27b49a60d0
commit 92be52fd9f
2 changed files with 13 additions and 0 deletions

View file

@ -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__