diff --git a/Libraries/LibIPC/Connection.cpp b/Libraries/LibIPC/Connection.cpp index f623c42b772..cc02f30d85b 100644 --- a/Libraries/LibIPC/Connection.cpp +++ b/Libraries/LibIPC/Connection.cpp @@ -16,14 +16,14 @@ namespace IPC { -ConnectionBase::ConnectionBase(IPC::Stub& local_stub, Transport transport, u32 local_endpoint_magic) +ConnectionBase::ConnectionBase(IPC::Stub& local_stub, NonnullOwnPtr transport, u32 local_endpoint_magic) : m_local_stub(local_stub) , m_transport(move(transport)) , m_local_endpoint_magic(local_endpoint_magic) { m_responsiveness_timer = Core::Timer::create_single_shot(3000, [this] { may_have_become_unresponsive(); }); - m_transport.set_up_read_hook([this] { + m_transport->set_up_read_hook([this] { NonnullRefPtr protect = *this; // FIXME: Do something about errors. (void)drain_messages_from_peer(); @@ -35,7 +35,7 @@ ConnectionBase::~ConnectionBase() = default; bool ConnectionBase::is_open() const { - return m_transport.is_open(); + return m_transport->is_open(); } ErrorOr ConnectionBase::post_message(Message const& message) @@ -47,7 +47,7 @@ ErrorOr ConnectionBase::post_message(u32 endpoint_magic, MessageBuffer buf { // NOTE: If this connection is being shut down, but has not yet been destroyed, // the socket will be closed. Don't try to send more messages. - if (!m_transport.is_open()) + if (!m_transport->is_open()) return Error::from_string_literal("Trying to post_message during IPC shutdown"); if (buffer.data().size() > TransportSocket::SOCKET_BUFFER_SIZE) { @@ -55,7 +55,7 @@ ErrorOr ConnectionBase::post_message(u32 endpoint_magic, MessageBuffer buf buffer = MUST(wrapper->encode()); } - MUST(buffer.transfer_message(m_transport)); + MUST(buffer.transfer_message(*m_transport)); m_responsiveness_timer->start(); return {}; @@ -63,7 +63,7 @@ ErrorOr ConnectionBase::post_message(u32 endpoint_magic, MessageBuffer buf void ConnectionBase::shutdown() { - m_transport.close(); + m_transport->close(); die(); } @@ -95,12 +95,12 @@ void ConnectionBase::handle_messages() void ConnectionBase::wait_for_transport_to_become_readable() { - m_transport.wait_until_readable(); + m_transport->wait_until_readable(); } ErrorOr ConnectionBase::drain_messages_from_peer() { - auto schedule_shutdown = m_transport.read_as_many_messages_as_possible_without_blocking([&](auto&& unparsed_message) { + auto schedule_shutdown = m_transport->read_as_many_messages_as_possible_without_blocking([&](auto&& unparsed_message) { auto const& bytes = unparsed_message.bytes; UnprocessedFileDescriptors unprocessed_fds; unprocessed_fds.return_fds_to_front_of_queue(move(unparsed_message.fds)); diff --git a/Libraries/LibIPC/Connection.h b/Libraries/LibIPC/Connection.h index 7aae27de1e4..0f5b918226f 100644 --- a/Libraries/LibIPC/Connection.h +++ b/Libraries/LibIPC/Connection.h @@ -35,10 +35,10 @@ public: void shutdown(); virtual void die() { } - Transport& transport() { return m_transport; } + Transport& transport() const { return *m_transport; } protected: - explicit ConnectionBase(IPC::Stub&, Transport, u32 local_endpoint_magic); + explicit ConnectionBase(IPC::Stub&, NonnullOwnPtr, u32 local_endpoint_magic); virtual void may_have_become_unresponsive() { } virtual void did_become_responsive() { } @@ -53,7 +53,7 @@ protected: IPC::Stub& m_local_stub; - Transport m_transport; + NonnullOwnPtr m_transport; RefPtr m_responsiveness_timer; @@ -65,7 +65,7 @@ protected: template class Connection : public ConnectionBase { public: - Connection(IPC::Stub& local_stub, Transport transport) + Connection(IPC::Stub& local_stub, NonnullOwnPtr transport) : ConnectionBase(local_stub, move(transport), LocalEndpoint::static_magic()) { } diff --git a/Libraries/LibIPC/ConnectionFromClient.h b/Libraries/LibIPC/ConnectionFromClient.h index dffc6218d41..389c5f7148a 100644 --- a/Libraries/LibIPC/ConnectionFromClient.h +++ b/Libraries/LibIPC/ConnectionFromClient.h @@ -26,7 +26,7 @@ public: using ServerStub = typename ServerEndpoint::Stub; using IPCProxy = typename ClientEndpoint::template Proxy; - ConnectionFromClient(ServerStub& stub, Transport transport, int client_id) + ConnectionFromClient(ServerStub& stub, NonnullOwnPtr transport, int client_id) : IPC::Connection(stub, move(transport)) , ClientEndpoint::template Proxy(*this, {}) , m_client_id(client_id) diff --git a/Libraries/LibIPC/ConnectionToServer.h b/Libraries/LibIPC/ConnectionToServer.h index 9dd4497ae95..f7955d3e5e2 100644 --- a/Libraries/LibIPC/ConnectionToServer.h +++ b/Libraries/LibIPC/ConnectionToServer.h @@ -18,7 +18,7 @@ public: using ClientStub = typename ClientEndpoint::Stub; using IPCProxy = typename ServerEndpoint::template Proxy; - ConnectionToServer(ClientStub& local_endpoint, Transport transport) + ConnectionToServer(ClientStub& local_endpoint, NonnullOwnPtr transport) : Connection(local_endpoint, move(transport)) , ServerEndpoint::template Proxy(*this, {}) { diff --git a/Libraries/LibIPC/MultiServer.h b/Libraries/LibIPC/MultiServer.h index c3a5b93d67b..94861b3073b 100644 --- a/Libraries/LibIPC/MultiServer.h +++ b/Libraries/LibIPC/MultiServer.h @@ -30,7 +30,7 @@ private: m_server->on_accept = [&](auto client_socket) { auto client_id = ++m_next_client_id; - auto client = IPC::new_client_connection(IPC::Transport(move(client_socket)), client_id); + auto client = IPC::new_client_connection(make(move(client_socket)), client_id); if (on_new_client) on_new_client(*client); }; diff --git a/Libraries/LibIPC/SingleServer.h b/Libraries/LibIPC/SingleServer.h index b25289dbad7..a238f00295b 100644 --- a/Libraries/LibIPC/SingleServer.h +++ b/Libraries/LibIPC/SingleServer.h @@ -16,7 +16,7 @@ template ErrorOr> take_over_accepted_client_from_system_server() { auto socket = TRY(Core::take_over_socket_from_system_server()); - return IPC::new_client_connection(IPC::Transport(move(socket))); + return IPC::new_client_connection(make(move(socket))); } } diff --git a/Libraries/LibIPC/TransportSocket.cpp b/Libraries/LibIPC/TransportSocket.cpp index 61d31b60c83..86239539ce7 100644 --- a/Libraries/LibIPC/TransportSocket.cpp +++ b/Libraries/LibIPC/TransportSocket.cpp @@ -15,10 +15,9 @@ namespace IPC { TransportSocket::TransportSocket(NonnullOwnPtr socket) : m_socket(move(socket)) - , m_fds_retained_until_received_by_peer(make>>()) { m_send_queue = adopt_ref(*new SendQueue); - m_send_thread = Threading::Thread::construct([&socket = *m_socket, send_queue = m_send_queue]() -> intptr_t { + m_send_thread = Threading::Thread::construct([this, send_queue = m_send_queue]() -> intptr_t { for (;;) { send_queue->mutex.lock(); while (send_queue->messages.is_empty() && send_queue->running) @@ -32,7 +31,7 @@ TransportSocket::TransportSocket(NonnullOwnPtr socket) auto [bytes, fds] = send_queue->messages.take_first(); send_queue->mutex.unlock(); - if (auto result = send_message(socket, bytes, fds); result.is_error()) { + if (auto result = send_message(*m_socket, bytes, fds); result.is_error()) { dbgln("TransportSocket::send_thread: {}", result.error()); } } @@ -46,14 +45,12 @@ TransportSocket::TransportSocket(NonnullOwnPtr socket) TransportSocket::~TransportSocket() { - if (m_send_thread) { - { - Threading::MutexLocker locker(m_send_queue->mutex); - m_send_queue->running = false; - m_send_queue->condition.signal(); - } - (void)m_send_thread->join(); + { + Threading::MutexLocker locker(m_send_queue->mutex); + m_send_queue->running = false; + m_send_queue->condition.signal(); } + (void)m_send_thread->join(); } void TransportSocket::set_up_read_hook(Function hook) @@ -94,7 +91,7 @@ struct MessageHeader { u32 fd_count { 0 }; }; -void TransportSocket::post_message(Vector const& bytes_to_write, Vector> const& fds) const +void TransportSocket::post_message(Vector const& bytes_to_write, Vector> const& fds) { Vector message_buffer; message_buffer.resize(sizeof(MessageHeader) + bytes_to_write.size()); @@ -106,7 +103,7 @@ void TransportSocket::post_message(Vector const& bytes_to_write, Vectorenqueue(fd); + m_fds_retained_until_received_by_peer.enqueue(fd); auto raw_fds = Vector {}; auto num_fds_to_transfer = fds.size(); @@ -242,7 +239,7 @@ TransportSocket::ShouldShutdown TransportSocket::read_as_many_messages_as_possib if (acknowledged_fd_count > 0) { while (acknowledged_fd_count > 0) { - (void)m_fds_retained_until_received_by_peer->dequeue(); + (void)m_fds_retained_until_received_by_peer.dequeue(); --acknowledged_fd_count; } } diff --git a/Libraries/LibIPC/TransportSocket.h b/Libraries/LibIPC/TransportSocket.h index a1e7257601d..2c466d0f08c 100644 --- a/Libraries/LibIPC/TransportSocket.h +++ b/Libraries/LibIPC/TransportSocket.h @@ -44,7 +44,7 @@ private: class TransportSocket { AK_MAKE_NONCOPYABLE(TransportSocket); - AK_MAKE_DEFAULT_MOVABLE(TransportSocket); + AK_MAKE_NONMOVABLE(TransportSocket); public: static constexpr socklen_t SOCKET_BUFFER_SIZE = 128 * KiB; @@ -58,7 +58,7 @@ public: void wait_until_readable(); - void post_message(Vector const&, Vector> const&) const; + void post_message(Vector const&, Vector> const&); enum class ShouldShutdown { No, @@ -85,7 +85,7 @@ private: // After file descriptor is sent, it is moved to the wait queue until an acknowledgement is received from the peer. // This is necessary to handle a specific behavior of the macOS kernel, which may prematurely garbage-collect the file // descriptor contained in the message before the peer receives it. https://openradar.me/9477351 - NonnullOwnPtr>> m_fds_retained_until_received_by_peer; + Queue> m_fds_retained_until_received_by_peer; struct MessageToSend { Vector bytes; diff --git a/Libraries/LibImageDecoderClient/Client.cpp b/Libraries/LibImageDecoderClient/Client.cpp index 1f240417336..ab5a5a5c704 100644 --- a/Libraries/LibImageDecoderClient/Client.cpp +++ b/Libraries/LibImageDecoderClient/Client.cpp @@ -9,7 +9,7 @@ namespace ImageDecoderClient { -Client::Client(IPC::Transport transport) +Client::Client(NonnullOwnPtr transport) : IPC::ConnectionToServer(*this, move(transport)) { } diff --git a/Libraries/LibImageDecoderClient/Client.h b/Libraries/LibImageDecoderClient/Client.h index 53c38df21b1..5bd4ef650d7 100644 --- a/Libraries/LibImageDecoderClient/Client.h +++ b/Libraries/LibImageDecoderClient/Client.h @@ -36,7 +36,7 @@ class Client final public: using InitTransport = Messages::ImageDecoderServer::InitTransport; - Client(IPC::Transport); + Client(NonnullOwnPtr); NonnullRefPtr> decode_image(ReadonlyBytes, Function(DecodedImage&)> on_resolved, Function on_rejected, Optional ideal_size = {}, Optional mime_type = {}); diff --git a/Libraries/LibRequests/RequestClient.cpp b/Libraries/LibRequests/RequestClient.cpp index 10422fa5ca2..e80f5bed499 100644 --- a/Libraries/LibRequests/RequestClient.cpp +++ b/Libraries/LibRequests/RequestClient.cpp @@ -10,7 +10,7 @@ namespace Requests { -RequestClient::RequestClient(IPC::Transport transport) +RequestClient::RequestClient(NonnullOwnPtr transport) : IPC::ConnectionToServer(*this, move(transport)) { } diff --git a/Libraries/LibRequests/RequestClient.h b/Libraries/LibRequests/RequestClient.h index 08b19f06361..43fa504d1d7 100644 --- a/Libraries/LibRequests/RequestClient.h +++ b/Libraries/LibRequests/RequestClient.h @@ -27,7 +27,7 @@ class RequestClient final public: using InitTransport = Messages::RequestServer::InitTransport; - explicit RequestClient(IPC::Transport); + explicit RequestClient(NonnullOwnPtr); virtual ~RequestClient() override; RefPtr start_request(ByteString const& method, URL::URL const&, HTTP::HeaderMap const& request_headers = {}, ReadonlyBytes request_body = {}, Core::ProxyData const& = {}); diff --git a/Libraries/LibWeb/HTML/MessagePort.cpp b/Libraries/LibWeb/HTML/MessagePort.cpp index 4a322d104a4..03fe434b6ec 100644 --- a/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Libraries/LibWeb/HTML/MessagePort.cpp @@ -78,7 +78,7 @@ void MessagePort::visit_edges(Cell::Visitor& visitor) bool MessagePort::is_entangled() const { - return m_transport.has_value(); + return m_transport; } void MessagePort::set_worker_event_target(GC::Ref target) @@ -103,7 +103,7 @@ WebIDL::ExceptionOr MessagePort::transfer_steps(HTML::TransferDataHolder& // 2. Set dataHolder.[[RemotePort]] to remotePort. // TODO: Mach IPC auto fd = MUST(m_transport->release_underlying_transport_for_transfer()); - m_transport = {}; + m_transport.clear(); data_holder.fds.append(IPC::File::adopt_fd(fd)); data_holder.data.append(IPC_FILE_TAG); } @@ -131,7 +131,7 @@ WebIDL::ExceptionOr MessagePort::transfer_receiving_steps(HTML::TransferDa if (fd_tag == IPC_FILE_TAG) { // TODO: Mach IPC auto fd = data_holder.fds.take_first(); - m_transport = IPC::Transport(MUST(Core::LocalSocket::adopt_fd(fd.take_fd()))); + m_transport = make(MUST(Core::LocalSocket::adopt_fd(fd.take_fd()))); m_transport->set_up_read_hook([strong_this = GC::make_root(this)]() { strong_this->read_from_transport(); @@ -150,7 +150,7 @@ void MessagePort::disentangle() m_remote_port->m_remote_port = nullptr; m_remote_port = nullptr; - m_transport = {}; + m_transport.clear(); m_worker_event_target = nullptr; } @@ -187,8 +187,8 @@ void MessagePort::entangle_with(MessagePort& remote_port) }; auto sockets = create_paired_sockets(); - m_transport = IPC::Transport(move(sockets[0])); - m_remote_port->m_transport = IPC::Transport(move(sockets[1])); + m_transport = make(move(sockets[0])); + m_remote_port->m_transport = make(move(sockets[1])); m_transport->set_up_read_hook([strong_this = GC::make_root(this)]() { strong_this->read_from_transport(); @@ -256,7 +256,7 @@ WebIDL::ExceptionOr MessagePort::message_port_post_message_steps(GC::Ptr MessagePort::send_message_on_transport(SerializedTransferRecord co void MessagePort::post_port_message(SerializedTransferRecord serialize_with_transfer_result) { - if (!m_transport.has_value() || !m_transport->is_open()) + if (!m_transport || !m_transport->is_open()) return; if (auto result = send_message_on_transport(serialize_with_transfer_result); result.is_error()) { dbgln("Failed to post message: {}", result.error()); @@ -369,7 +369,7 @@ void MessagePort::start() if (!is_entangled()) return; - VERIFY(m_transport.has_value()); + VERIFY(m_transport); // TODO: The start() method steps are to enable this's port message queue, if it is not already enabled. } diff --git a/Libraries/LibWeb/HTML/MessagePort.h b/Libraries/LibWeb/HTML/MessagePort.h index cf8ad8e1879..0d48fd0adfb 100644 --- a/Libraries/LibWeb/HTML/MessagePort.h +++ b/Libraries/LibWeb/HTML/MessagePort.h @@ -86,7 +86,7 @@ private: // https://html.spec.whatwg.org/multipage/web-messaging.html#has-been-shipped bool m_has_been_shipped { false }; - Optional m_transport; + OwnPtr m_transport; GC::Ptr m_worker_event_target; }; diff --git a/Libraries/LibWeb/HTML/WorkerAgent.cpp b/Libraries/LibWeb/HTML/WorkerAgent.cpp index 3a011770dee..863b6355d78 100644 --- a/Libraries/LibWeb/HTML/WorkerAgent.cpp +++ b/Libraries/LibWeb/HTML/WorkerAgent.cpp @@ -40,7 +40,7 @@ void WorkerAgent::initialize(JS::Realm& realm) MUST(worker_socket->set_blocking(true)); // TODO: Mach IPC - auto transport = IPC::Transport(move(worker_socket)); + auto transport = make(move(worker_socket)); m_worker_ipc = make_ref_counted(move(transport)); diff --git a/Libraries/LibWeb/Worker/WebWorkerClient.cpp b/Libraries/LibWeb/Worker/WebWorkerClient.cpp index 2b501db7527..c4a63fae79a 100644 --- a/Libraries/LibWeb/Worker/WebWorkerClient.cpp +++ b/Libraries/LibWeb/Worker/WebWorkerClient.cpp @@ -20,14 +20,14 @@ void WebWorkerClient::did_close_worker() on_worker_close(); } -WebWorkerClient::WebWorkerClient(IPC::Transport transport) +WebWorkerClient::WebWorkerClient(NonnullOwnPtr transport) : IPC::ConnectionToServer(*this, move(transport)) { } IPC::File WebWorkerClient::clone_transport() { - return MUST(m_transport.clone_for_transfer()); + return MUST(m_transport->clone_for_transfer()); } } diff --git a/Libraries/LibWeb/Worker/WebWorkerClient.h b/Libraries/LibWeb/Worker/WebWorkerClient.h index 6e40be7e187..c2b616ae812 100644 --- a/Libraries/LibWeb/Worker/WebWorkerClient.h +++ b/Libraries/LibWeb/Worker/WebWorkerClient.h @@ -18,7 +18,7 @@ class WebWorkerClient final C_OBJECT_ABSTRACT(WebWorkerClient); public: - explicit WebWorkerClient(IPC::Transport); + explicit WebWorkerClient(NonnullOwnPtr); virtual void did_close_worker() override; diff --git a/Libraries/LibWebView/BrowserProcess.cpp b/Libraries/LibWebView/BrowserProcess.cpp index 9498694ad51..bcc857700cf 100644 --- a/Libraries/LibWebView/BrowserProcess.cpp +++ b/Libraries/LibWebView/BrowserProcess.cpp @@ -22,7 +22,7 @@ class UIProcessClient final C_OBJECT(UIProcessClient); private: - explicit UIProcessClient(IPC::Transport); + explicit UIProcessClient(NonnullOwnPtr); }; ErrorOr BrowserProcess::connect(Vector const& raw_urls, NewWindow new_window) @@ -49,7 +49,7 @@ ErrorOr BrowserProcess::connect_as_client(ByteString const& socket_path, V { // TODO: Mach IPC auto socket = TRY(Core::LocalSocket::connect(socket_path)); - auto client = UIProcessClient::construct(IPC::Transport(move(socket))); + auto client = UIProcessClient::construct(make(move(socket))); if (new_window == NewWindow::Yes) { if (!client->send_sync_but_allow_failure(raw_urls)) @@ -98,12 +98,12 @@ BrowserProcess::~BrowserProcess() MUST(Core::System::unlink(m_socket_path)); } -UIProcessClient::UIProcessClient(IPC::Transport transport) +UIProcessClient::UIProcessClient(NonnullOwnPtr transport) : IPC::ConnectionToServer(*this, move(transport)) { } -UIProcessConnectionFromClient::UIProcessConnectionFromClient(IPC::Transport transport, int client_id) +UIProcessConnectionFromClient::UIProcessConnectionFromClient(NonnullOwnPtr transport, int client_id) : IPC::ConnectionFromClient(*this, move(transport), client_id) { s_connections.set(client_id, *this); diff --git a/Libraries/LibWebView/BrowserProcess.h b/Libraries/LibWebView/BrowserProcess.h index e12ea842835..e3245c8d3ad 100644 --- a/Libraries/LibWebView/BrowserProcess.h +++ b/Libraries/LibWebView/BrowserProcess.h @@ -32,7 +32,7 @@ public: Function const&)> on_new_window; private: - UIProcessConnectionFromClient(IPC::Transport, int client_id); + UIProcessConnectionFromClient(NonnullOwnPtr, int client_id); virtual void create_new_tab(Vector urls) override; virtual void create_new_window(Vector urls) override; diff --git a/Libraries/LibWebView/Process.cpp b/Libraries/LibWebView/Process.cpp index 2f31aece3be..67444b3c1d0 100644 --- a/Libraries/LibWebView/Process.cpp +++ b/Libraries/LibWebView/Process.cpp @@ -47,7 +47,7 @@ ErrorOr Process::spawn_and_connect_to_process(C guard_fd_0.disarm(); TRY(ipc_socket->set_blocking(true)); - return ProcessAndIPCTransport { move(process), IPC::Transport(move(ipc_socket)) }; + return ProcessAndIPCTransport { move(process), make(move(ipc_socket)) }; } #ifdef AK_OS_WINDOWS diff --git a/Libraries/LibWebView/Process.h b/Libraries/LibWebView/Process.h index 3f6010057a4..9a27072e290 100644 --- a/Libraries/LibWebView/Process.h +++ b/Libraries/LibWebView/Process.h @@ -54,7 +54,7 @@ public: private: struct ProcessAndIPCTransport { Core::Process process; - IPC::Transport transport; + NonnullOwnPtr transport; }; static ErrorOr spawn_and_connect_to_process(Core::ProcessSpawnOptions const& options); diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp index 65881322f40..ede5a7fadc2 100644 --- a/Libraries/LibWebView/WebContentClient.cpp +++ b/Libraries/LibWebView/WebContentClient.cpp @@ -25,14 +25,14 @@ Optional WebContentClient::view_for_pid_and_page_id(pid_t p return {}; } -WebContentClient::WebContentClient(IPC::Transport transport, ViewImplementation& view) +WebContentClient::WebContentClient(NonnullOwnPtr transport, ViewImplementation& view) : IPC::ConnectionToServer(*this, move(transport)) { s_clients.set(this); m_views.set(0, &view); } -WebContentClient::WebContentClient(IPC::Transport transport) +WebContentClient::WebContentClient(NonnullOwnPtr transport) : IPC::ConnectionToServer(*this, move(transport)) { s_clients.set(this); diff --git a/Libraries/LibWebView/WebContentClient.h b/Libraries/LibWebView/WebContentClient.h index dac091f87de..a181b4e88e7 100644 --- a/Libraries/LibWebView/WebContentClient.h +++ b/Libraries/LibWebView/WebContentClient.h @@ -39,8 +39,8 @@ public: static size_t client_count() { return s_clients.size(); } - explicit WebContentClient(IPC::Transport); - WebContentClient(IPC::Transport, ViewImplementation&); + explicit WebContentClient(NonnullOwnPtr); + WebContentClient(NonnullOwnPtr, ViewImplementation&); ~WebContentClient(); void assign_view(Badge, ViewImplementation&); diff --git a/Libraries/LibWebView/WebUI.cpp b/Libraries/LibWebView/WebUI.cpp index 50d5b14a21b..27bd0318b21 100644 --- a/Libraries/LibWebView/WebUI.cpp +++ b/Libraries/LibWebView/WebUI.cpp @@ -27,7 +27,7 @@ static ErrorOr> create_web_ui(WebContentClient& client, return client_socket.release_error(); } - auto web_ui = WebUIType::create(client, IPC::Transport { client_socket.release_value() }, move(host)); + auto web_ui = WebUIType::create(client, make(client_socket.release_value()), move(host)); client.async_connect_to_web_ui(0, IPC::File::adopt_fd(socket_fds[1])); return web_ui; @@ -48,7 +48,7 @@ ErrorOr> WebUI::create(WebContentClient& client, String host) return web_ui; } -WebUI::WebUI(WebContentClient& client, IPC::Transport transport, String host) +WebUI::WebUI(WebContentClient& client, NonnullOwnPtr transport, String host) : IPC::ConnectionToServer(*this, move(transport)) , m_client(client) , m_host(move(host)) diff --git a/Libraries/LibWebView/WebUI.h b/Libraries/LibWebView/WebUI.h index 4c312b2befe..5f13c8ab9ec 100644 --- a/Libraries/LibWebView/WebUI.h +++ b/Libraries/LibWebView/WebUI.h @@ -30,7 +30,7 @@ public: String const& host() const { return m_host; } protected: - WebUI(WebContentClient&, IPC::Transport, String host); + WebUI(WebContentClient&, NonnullOwnPtr, String host); using Interface = Function; @@ -47,17 +47,17 @@ private: HashMap m_interfaces; }; -#define WEB_UI(WebUIType) \ -public: \ - static NonnullRefPtr create(WebContentClient& client, IPC::Transport transport, String host) \ - { \ - return adopt_ref(*new WebUIType(client, move(transport), move(host))); \ - } \ - \ -private: \ - WebUIType(WebContentClient& client, IPC::Transport transport, String host) \ - : WebView::WebUI(client, move(transport), move(host)) \ - { \ +#define WEB_UI(WebUIType) \ +public: \ + static NonnullRefPtr create(WebContentClient& client, NonnullOwnPtr transport, String host) \ + { \ + return adopt_ref(*new WebUIType(client, move(transport), move(host))); \ + } \ + \ +private: \ + WebUIType(WebContentClient& client, NonnullOwnPtr transport, String host) \ + : WebView::WebUI(client, move(transport), move(host)) \ + { \ } } diff --git a/Services/ImageDecoder/ConnectionFromClient.cpp b/Services/ImageDecoder/ConnectionFromClient.cpp index fd7653455db..ef275d2d487 100644 --- a/Services/ImageDecoder/ConnectionFromClient.cpp +++ b/Services/ImageDecoder/ConnectionFromClient.cpp @@ -17,7 +17,7 @@ namespace ImageDecoder { static HashMap> s_connections; static IDAllocator s_client_ids; -ConnectionFromClient::ConnectionFromClient(IPC::Transport transport) +ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr transport) : IPC::ConnectionFromClient(*this, move(transport), s_client_ids.allocate()) { s_connections.set(client_id(), *this); @@ -64,7 +64,7 @@ ErrorOr ConnectionFromClient::connect_new_client() auto client_socket = client_socket_or_error.release_value(); // Note: A ref is stored in the static s_connections map - auto client = adopt_ref(*new ConnectionFromClient(IPC::Transport(move(client_socket)))); + auto client = adopt_ref(*new ConnectionFromClient(make(move(client_socket)))); return IPC::File::adopt_fd(socket_fds[1]); } diff --git a/Services/ImageDecoder/ConnectionFromClient.h b/Services/ImageDecoder/ConnectionFromClient.h index e75c2c89e03..617e3956004 100644 --- a/Services/ImageDecoder/ConnectionFromClient.h +++ b/Services/ImageDecoder/ConnectionFromClient.h @@ -38,7 +38,7 @@ public: private: using Job = Threading::BackgroundAction; - explicit ConnectionFromClient(IPC::Transport); + explicit ConnectionFromClient(NonnullOwnPtr); virtual Messages::ImageDecoderServer::DecodeImageResponse decode_image(Core::AnonymousBuffer, Optional ideal_size, Optional mime_type) override; virtual void cancel_decoding(i64 image_id) override; diff --git a/Services/RequestServer/ConnectionFromClient.cpp b/Services/RequestServer/ConnectionFromClient.cpp index 9fda2b25fca..10392eb8d25 100644 --- a/Services/RequestServer/ConnectionFromClient.cpp +++ b/Services/RequestServer/ConnectionFromClient.cpp @@ -264,7 +264,7 @@ int ConnectionFromClient::on_timeout_callback(void*, long timeout_ms, void* user return 0; } -ConnectionFromClient::ConnectionFromClient(IPC::Transport transport) +ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr transport) : IPC::ConnectionFromClient(*this, move(transport), s_client_ids.allocate()) , m_resolver(default_resolver()) { @@ -335,7 +335,7 @@ Messages::RequestServer::ConnectNewClientResponse ConnectionFromClient::connect_ } auto client_socket = client_socket_or_error.release_value(); // Note: A ref is stored in the static s_connections map - auto client = adopt_ref(*new ConnectionFromClient(IPC::Transport(move(client_socket)))); + auto client = adopt_ref(*new ConnectionFromClient(make(move(client_socket)))); return IPC::File::adopt_fd(socket_fds[1]); } diff --git a/Services/RequestServer/ConnectionFromClient.h b/Services/RequestServer/ConnectionFromClient.h index 624e38daac6..41f12474b68 100644 --- a/Services/RequestServer/ConnectionFromClient.h +++ b/Services/RequestServer/ConnectionFromClient.h @@ -35,7 +35,7 @@ public: virtual void die() override; private: - explicit ConnectionFromClient(IPC::Transport); + explicit ConnectionFromClient(NonnullOwnPtr); virtual Messages::RequestServer::InitTransportResponse init_transport(int peer_pid) override; virtual Messages::RequestServer::ConnectNewClientResponse connect_new_client() override; diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index db5a6f0e530..5b5e13d6919 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -56,7 +56,7 @@ namespace WebContent { -ConnectionFromClient::ConnectionFromClient(IPC::Transport transport) +ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr transport) : IPC::ConnectionFromClient(*this, move(transport), 1) , m_page_host(PageHost::create(*this)) { diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h index 2d4b1f786b3..7347961ec52 100644 --- a/Services/WebContent/ConnectionFromClient.h +++ b/Services/WebContent/ConnectionFromClient.h @@ -51,7 +51,7 @@ public: Queue& input_event_queue() { return m_input_event_queue; } private: - explicit ConnectionFromClient(IPC::Transport); + explicit ConnectionFromClient(NonnullOwnPtr); Optional page(u64 index, SourceLocation = SourceLocation::current()); Optional page(u64 index, SourceLocation = SourceLocation::current()) const; diff --git a/Services/WebContent/WebDriverConnection.cpp b/Services/WebContent/WebDriverConnection.cpp index 373f7ff3f14..16f81ccacec 100644 --- a/Services/WebContent/WebDriverConnection.cpp +++ b/Services/WebContent/WebDriverConnection.cpp @@ -197,10 +197,10 @@ ErrorOr> WebDriverConnection::connect(Web::Pa page_client.page().set_should_block_pop_ups(false); dbgln_if(WEBDRIVER_DEBUG, "Connected to WebDriver"); - return adopt_nonnull_ref_or_enomem(new (nothrow) WebDriverConnection(IPC::Transport(move(socket)), page_client)); + return adopt_nonnull_ref_or_enomem(new (nothrow) WebDriverConnection(make(move(socket)), page_client)); } -WebDriverConnection::WebDriverConnection(IPC::Transport transport, Web::PageClient& page_client) +WebDriverConnection::WebDriverConnection(NonnullOwnPtr transport, Web::PageClient& page_client) : IPC::ConnectionToServer(*this, move(transport)) { set_current_top_level_browsing_context(page_client.page().top_level_browsing_context()); diff --git a/Services/WebContent/WebDriverConnection.h b/Services/WebContent/WebDriverConnection.h index 9321d3607a3..cdcdde99cfb 100644 --- a/Services/WebContent/WebDriverConnection.h +++ b/Services/WebContent/WebDriverConnection.h @@ -42,7 +42,7 @@ public: void page_did_open_dialog(Badge); private: - WebDriverConnection(IPC::Transport transport, Web::PageClient& page_client); + WebDriverConnection(NonnullOwnPtr transport, Web::PageClient& page_client); virtual void die() override { } diff --git a/Services/WebContent/WebUIConnection.cpp b/Services/WebContent/WebUIConnection.cpp index 2e7513f9691..4c45fe6a73a 100644 --- a/Services/WebContent/WebUIConnection.cpp +++ b/Services/WebContent/WebUIConnection.cpp @@ -26,10 +26,10 @@ ErrorOr> WebUIConnection::connect(IPC::File web_u auto socket = TRY(Core::LocalSocket::adopt_fd(web_ui_socket.take_fd())); TRY(socket->set_blocking(true)); - return adopt_ref(*new WebUIConnection(IPC::Transport { move(socket) }, document)); + return adopt_ref(*new WebUIConnection(make(move(socket)), document)); } -WebUIConnection::WebUIConnection(IPC::Transport transport, Web::DOM::Document& document) +WebUIConnection::WebUIConnection(NonnullOwnPtr transport, Web::DOM::Document& document) : IPC::ConnectionFromClient(*this, move(transport), 1) , m_document(document) { diff --git a/Services/WebContent/WebUIConnection.h b/Services/WebContent/WebUIConnection.h index fd6915a5d35..06d1986a585 100644 --- a/Services/WebContent/WebUIConnection.h +++ b/Services/WebContent/WebUIConnection.h @@ -28,7 +28,7 @@ public: void received_message_from_web_ui(String const& name, JS::Value data); private: - WebUIConnection(IPC::Transport, Web::DOM::Document&); + WebUIConnection(NonnullOwnPtr, Web::DOM::Document&); virtual void die() override { } virtual void send_message(String name, JsonValue data) override; diff --git a/Services/WebContent/main.cpp b/Services/WebContent/main.cpp index 6882fb8a881..0ae19e324b9 100644 --- a/Services/WebContent/main.cpp +++ b/Services/WebContent/main.cpp @@ -213,7 +213,7 @@ ErrorOr serenity_main(Main::Arguments arguments) static_assert(IsSame, "Need to handle other IPC transports here"); auto webcontent_socket = TRY(Core::take_over_socket_from_system_server("WebContent"sv)); - auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(IPC::Transport(move(webcontent_socket)))); + auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(make(move(webcontent_socket)))); webcontent_client->on_image_decoder_connection = [&](auto& socket_file) { auto maybe_error = reinitialize_image_decoder(socket_file); @@ -255,7 +255,7 @@ ErrorOr initialize_resource_loader(GC::Heap& heap, int request_server_sock auto socket = TRY(Core::LocalSocket::adopt_fd(request_server_socket)); TRY(socket->set_blocking(true)); - auto request_client = TRY(try_make_ref_counted(IPC::Transport(move(socket)))); + auto request_client = TRY(try_make_ref_counted(make(move(socket)))); #ifdef AK_OS_WINDOWS auto response = request_client->send_sync(Core::System::getpid()); request_client->transport().set_peer_pid(response->peer_pid()); @@ -271,7 +271,7 @@ ErrorOr initialize_image_decoder(int image_decoder_socket) auto socket = TRY(Core::LocalSocket::adopt_fd(image_decoder_socket)); TRY(socket->set_blocking(true)); - auto new_client = TRY(try_make_ref_counted(IPC::Transport(move(socket)))); + auto new_client = TRY(try_make_ref_counted(make(move(socket)))); #ifdef AK_OS_WINDOWS auto response = new_client->send_sync(Core::System::getpid()); new_client->transport().set_peer_pid(response->peer_pid()); @@ -289,7 +289,7 @@ ErrorOr reinitialize_image_decoder(IPC::File const& image_decoder_socket) auto socket = TRY(Core::LocalSocket::adopt_fd(image_decoder_socket.take_fd())); TRY(socket->set_blocking(true)); - auto new_client = TRY(try_make_ref_counted(IPC::Transport(move(socket)))); + auto new_client = TRY(try_make_ref_counted(make(move(socket)))); static_cast(Web::Platform::ImageCodecPlugin::the()).set_client(move(new_client)); diff --git a/Services/WebDriver/Session.cpp b/Services/WebDriver/Session.cpp index 9f02b8ff0ea..7ff57554a95 100644 --- a/Services/WebDriver/Session.cpp +++ b/Services/WebDriver/Session.cpp @@ -206,7 +206,7 @@ ErrorOr> Session::create_server(NonnullRefPtrlisten(*m_web_content_socket_path); server->on_accept = [this, promise](auto client_socket) { - auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(IPC::Transport(move(client_socket)))); + auto maybe_connection = adopt_nonnull_ref_or_enomem(new (nothrow) WebContentConnection(make(move(client_socket)))); if (maybe_connection.is_error()) { promise->resolve(maybe_connection.release_error()); return; diff --git a/Services/WebDriver/WebContentConnection.cpp b/Services/WebDriver/WebContentConnection.cpp index 54197bbed5d..79cb9fd72de 100644 --- a/Services/WebDriver/WebContentConnection.cpp +++ b/Services/WebDriver/WebContentConnection.cpp @@ -9,7 +9,7 @@ namespace WebDriver { -WebContentConnection::WebContentConnection(IPC::Transport transport) +WebContentConnection::WebContentConnection(NonnullOwnPtr transport) : IPC::ConnectionFromClient(*this, move(transport), 1) { } diff --git a/Services/WebDriver/WebContentConnection.h b/Services/WebDriver/WebContentConnection.h index f50d7b02f7f..f072a6378e7 100644 --- a/Services/WebDriver/WebContentConnection.h +++ b/Services/WebDriver/WebContentConnection.h @@ -19,7 +19,7 @@ class WebContentConnection : public IPC::ConnectionFromClient { C_OBJECT_ABSTRACT(WebContentConnection) public: - explicit WebContentConnection(IPC::Transport transport); + explicit WebContentConnection(NonnullOwnPtr transport); Function on_close; Function on_driver_execution_complete; diff --git a/Services/WebWorker/ConnectionFromClient.cpp b/Services/WebWorker/ConnectionFromClient.cpp index cc907790d9e..dd6b363c36b 100644 --- a/Services/WebWorker/ConnectionFromClient.cpp +++ b/Services/WebWorker/ConnectionFromClient.cpp @@ -45,7 +45,7 @@ void ConnectionFromClient::request_file(Web::FileRequest request) handle_file_return(0, IPC::File::adopt_file(file.release_value()), request_id); } -ConnectionFromClient::ConnectionFromClient(IPC::Transport transport) +ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr transport) : IPC::ConnectionFromClient(*this, move(transport), 1) , m_page_host(PageHost::create(Web::Bindings::main_thread_vm(), *this)) { diff --git a/Services/WebWorker/ConnectionFromClient.h b/Services/WebWorker/ConnectionFromClient.h index 42df6e0d687..65b8b8470f1 100644 --- a/Services/WebWorker/ConnectionFromClient.h +++ b/Services/WebWorker/ConnectionFromClient.h @@ -36,7 +36,7 @@ public: PageHost const& page_host() const { return *m_page_host; } private: - explicit ConnectionFromClient(IPC::Transport); + explicit ConnectionFromClient(NonnullOwnPtr); Web::Page& page(); Web::Page const& page() const; diff --git a/Services/WebWorker/main.cpp b/Services/WebWorker/main.cpp index b7ac54c632b..6ad9a7b58f4 100644 --- a/Services/WebWorker/main.cpp +++ b/Services/WebWorker/main.cpp @@ -83,7 +83,7 @@ static ErrorOr initialize_image_decoder(int image_decoder_socket) auto socket = TRY(Core::LocalSocket::adopt_fd(image_decoder_socket)); TRY(socket->set_blocking(true)); - auto new_client = TRY(try_make_ref_counted(IPC::Transport(move(socket)))); + auto new_client = TRY(try_make_ref_counted(make(move(socket)))); #ifdef AK_OS_WINDOWS auto response = new_client->send_sync(Core::System::getpid()); new_client->transport().set_peer_pid(response->peer_pid()); @@ -101,7 +101,7 @@ static ErrorOr initialize_resource_loader(GC::Heap& heap, int request_serv auto socket = TRY(Core::LocalSocket::adopt_fd(request_server_socket)); TRY(socket->set_blocking(true)); - auto request_client = TRY(try_make_ref_counted(IPC::Transport(move(socket)))); + auto request_client = TRY(try_make_ref_counted(make(move(socket)))); #ifdef AK_OS_WINDOWS auto response = request_client->send_sync(Core::System::getpid()); request_client->transport().set_peer_pid(response->peer_pid());