diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-29 18:42:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-30 23:34:40 +0100 |
commit | fe003939413d0de648618e2cd5f5c72182c7cf7b (patch) | |
tree | e75b7e24ca4df39d07a4cc23af30a47ee87bd9c3 /Userland/Services | |
parent | 6cb3092b42132ab8ff59158e0b418a818c7ec315 (diff) | |
download | serenity-fe003939413d0de648618e2cd5f5c72182c7cf7b.zip |
LibCore: Change Core::LocalServer::on_ready_to_accept => on_accept
Everyone used this hook in the same way: immediately accept() on the
socket and then do something with the newly accepted fd.
This patch simplifies the hook by having LocalServer do the accepting
automatically.
Diffstat (limited to 'Userland/Services')
-rw-r--r-- | Userland/Services/AudioServer/main.cpp | 10 | ||||
-rw-r--r-- | Userland/Services/Clipboard/main.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/ConfigServer/main.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/InspectorServer/main.cpp | 19 | ||||
-rw-r--r-- | Userland/Services/LaunchServer/main.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/LookupServer/LookupServer.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/NotificationServer/main.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/SQLServer/main.cpp | 9 | ||||
-rw-r--r-- | Userland/Services/WindowServer/EventLoop.cpp | 18 |
9 files changed, 23 insertions, 78 deletions
diff --git a/Userland/Services/AudioServer/main.cpp b/Userland/Services/AudioServer/main.cpp index 202cf9e102..510c4f5f93 100644 --- a/Userland/Services/AudioServer/main.cpp +++ b/Userland/Services/AudioServer/main.cpp @@ -34,15 +34,11 @@ int main(int, char**) auto server = Core::LocalServer::construct(); bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("AudioServer: accept failed."); - return; - } + + server->on_accept = [&](NonnullRefPtr<Core::LocalSocket> client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<AudioServer::ClientConnection>(client_socket.release_nonnull(), client_id, *mixer); + IPC::new_client_connection<AudioServer::ClientConnection>(move(client_socket), client_id, *mixer); }; if (pledge("stdio recvfd thread accept cpath rpath wpath", nullptr) < 0) { diff --git a/Userland/Services/Clipboard/main.cpp b/Userland/Services/Clipboard/main.cpp index cd7d615afa..1d97ca9b1e 100644 --- a/Userland/Services/Clipboard/main.cpp +++ b/Userland/Services/Clipboard/main.cpp @@ -22,15 +22,10 @@ ErrorOr<int> serenity_main(Main::Arguments) bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("Clipboard: accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<Clipboard::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<Clipboard::ClientConnection>(move(client_socket), client_id); }; Clipboard::Storage::the().on_content_change = [&] { diff --git a/Userland/Services/ConfigServer/main.cpp b/Userland/Services/ConfigServer/main.cpp index ac97f033f1..3c4609e004 100644 --- a/Userland/Services/ConfigServer/main.cpp +++ b/Userland/Services/ConfigServer/main.cpp @@ -21,15 +21,10 @@ ErrorOr<int> serenity_main(Main::Arguments) bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("ConfigServer: accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<ConfigServer::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<ConfigServer::ClientConnection>(move(client_socket), client_id); }; return event_loop.exec(); diff --git a/Userland/Services/InspectorServer/main.cpp b/Userland/Services/InspectorServer/main.cpp index 86cb1f7981..fec999ae7d 100644 --- a/Userland/Services/InspectorServer/main.cpp +++ b/Userland/Services/InspectorServer/main.cpp @@ -22,30 +22,19 @@ int main(int, char**) bool ok = server->take_over_from_system_server("/tmp/portal/inspector"); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<InspectorServer::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<InspectorServer::ClientConnection>(move(client_socket), client_id); }; auto inspectables_server = Core::LocalServer::construct(); if (!inspectables_server->take_over_from_system_server("/tmp/portal/inspectables")) VERIFY_NOT_REACHED(); - inspectables_server->on_ready_to_accept = [&] { - auto client_socket = inspectables_server->accept(); - if (!client_socket) { - dbgln("backdoor accept failed."); - return; - } + inspectables_server->on_accept = [&](auto client_socket) { auto pid = client_socket->peer_pid(); - - InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, client_socket.release_nonnull())); + InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, move(client_socket))); }; return event_loop.exec(); diff --git a/Userland/Services/LaunchServer/main.cpp b/Userland/Services/LaunchServer/main.cpp index 1998ea243d..7d25a4ee3e 100644 --- a/Userland/Services/LaunchServer/main.cpp +++ b/Userland/Services/LaunchServer/main.cpp @@ -29,15 +29,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("LaunchServer: accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<LaunchServer::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<LaunchServer::ClientConnection>(move(client_socket), client_id); }; return event_loop.exec(); diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index d973c06300..ae0e60398f 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -73,15 +73,10 @@ LookupServer::LookupServer() m_mdns = MulticastDNS::construct(this); m_local_server = Core::LocalServer::construct(this); - m_local_server->on_ready_to_accept = [this]() { - auto socket = m_local_server->accept(); - if (!socket) { - dbgln("Failed to accept a client connection"); - return; - } + m_local_server->on_accept = [this](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<ClientConnection>(socket.release_nonnull(), client_id); + IPC::new_client_connection<ClientConnection>(move(client_socket), client_id); }; bool ok = m_local_server->take_over_from_system_server(); VERIFY(ok); diff --git a/Userland/Services/NotificationServer/main.cpp b/Userland/Services/NotificationServer/main.cpp index 8239d1e808..5980d95192 100644 --- a/Userland/Services/NotificationServer/main.cpp +++ b/Userland/Services/NotificationServer/main.cpp @@ -20,15 +20,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("NotificationServer: accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<NotificationServer::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<NotificationServer::ClientConnection>(move(client_socket), client_id); }; TRY(Core::System::unveil("/res", "r")); diff --git a/Userland/Services/SQLServer/main.cpp b/Userland/Services/SQLServer/main.cpp index 7c4683a659..353e2ceab7 100644 --- a/Userland/Services/SQLServer/main.cpp +++ b/Userland/Services/SQLServer/main.cpp @@ -37,15 +37,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) bool ok = server->take_over_from_system_server(); VERIFY(ok); - server->on_ready_to_accept = [&] { - auto client_socket = server->accept(); - if (!client_socket) { - dbgln("SQLServer: accept failed."); - return; - } + server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<SQLServer::ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<SQLServer::ClientConnection>(client_socket, client_id); }; return event_loop.exec(); diff --git a/Userland/Services/WindowServer/EventLoop.cpp b/Userland/Services/WindowServer/EventLoop.cpp index 7b21c820a0..1986695963 100644 --- a/Userland/Services/WindowServer/EventLoop.cpp +++ b/Userland/Services/WindowServer/EventLoop.cpp @@ -30,26 +30,16 @@ EventLoop::EventLoop() ok = m_wm_server->take_over_from_system_server("/tmp/portal/wm"); VERIFY(ok); - m_window_server->on_ready_to_accept = [this] { - auto client_socket = m_window_server->accept(); - if (!client_socket) { - dbgln("WindowServer: accept failed."); - return; - } + m_window_server->on_accept = [&](auto client_socket) { static int s_next_client_id = 0; int client_id = ++s_next_client_id; - IPC::new_client_connection<ClientConnection>(client_socket.release_nonnull(), client_id); + IPC::new_client_connection<ClientConnection>(move(client_socket), client_id); }; - m_wm_server->on_ready_to_accept = [this] { - auto client_socket = m_wm_server->accept(); - if (!client_socket) { - dbgln("WindowServer: WM accept failed."); - return; - } + m_wm_server->on_accept = [&](auto client_socket) { static int s_next_wm_id = 0; int wm_id = ++s_next_wm_id; - IPC::new_client_connection<WMClientConnection>(client_socket.release_nonnull(), wm_id); + IPC::new_client_connection<WMClientConnection>(move(client_socket), wm_id); }; if (m_keyboard_fd >= 0) { |