ladybird/Userland/Libraries/LibWeb/Worker/WebWorkerClient.cpp
Andrew Kaster 6d4ba21832 LibIPC+Userland: Make IPC::File always own its file descriptor
Add factory functions to distinguish between when the owner of the File
wants to transfer ownership to the new IPC object (adopt) or to send a
copy of the same fd to the IPC peer (clone).

This behavior is more intuitive than the previous behavior. Previously,
an IPC::File would default to a shallow clone of the file descriptor,
only *actually* calling dup(2) for the fd when encoding or it into an
IPC MessageBuffer. Now the dup(2) for the fd is explicit in the clone_fd
factory function.
2024-04-19 06:34:07 -04:00

30 lines
741 B
C++

/*
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/System.h>
#include <LibWeb/Worker/WebWorkerClient.h>
namespace Web::HTML {
void WebWorkerClient::die()
{
// FIXME: Notify WorkerAgent that the worker is ded
}
WebWorkerClient::WebWorkerClient(NonnullOwnPtr<Core::LocalSocket> socket)
: IPC::ConnectionToServer<WebWorkerClientEndpoint, WebWorkerServerEndpoint>(*this, move(socket))
{
}
WebView::SocketPair WebWorkerClient::dup_sockets()
{
WebView::SocketPair pair;
pair.socket = MUST(IPC::File::clone_fd(socket().fd().value()));
pair.fd_passing_socket = MUST(IPC::File::clone_fd(fd_passing_socket().fd().value()));
return pair;
}
}