mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
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.
This commit is contained in:
parent
6cb3092b42
commit
fe00393941
11 changed files with 28 additions and 80 deletions
|
@ -83,8 +83,10 @@ void LocalServer::setup_notifier()
|
||||||
{
|
{
|
||||||
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
|
m_notifier = Notifier::construct(m_fd, Notifier::Event::Read, this);
|
||||||
m_notifier->on_ready_to_read = [this] {
|
m_notifier->on_ready_to_read = [this] {
|
||||||
if (on_ready_to_accept)
|
if (on_accept) {
|
||||||
on_ready_to_accept();
|
if (auto client_socket = accept())
|
||||||
|
on_accept(client_socket.release_nonnull());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ public:
|
||||||
|
|
||||||
RefPtr<LocalSocket> accept();
|
RefPtr<LocalSocket> accept();
|
||||||
|
|
||||||
|
Function<void(NonnullRefPtr<Core::LocalSocket>)> on_accept;
|
||||||
Function<void()> on_ready_to_accept;
|
Function<void()> on_ready_to_accept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,15 +34,11 @@ int main(int, char**)
|
||||||
auto server = Core::LocalServer::construct();
|
auto server = Core::LocalServer::construct();
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
server->on_ready_to_accept = [&] {
|
|
||||||
auto client_socket = server->accept();
|
server->on_accept = [&](NonnullRefPtr<Core::LocalSocket> client_socket) {
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("AudioServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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) {
|
if (pledge("stdio recvfd thread accept cpath rpath wpath", nullptr) < 0) {
|
||||||
|
|
|
@ -22,15 +22,10 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
|
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("Clipboard: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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 = [&] {
|
Clipboard::Storage::the().on_content_change = [&] {
|
||||||
|
|
|
@ -21,15 +21,10 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
|
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("ConfigServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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();
|
return event_loop.exec();
|
||||||
|
|
|
@ -22,30 +22,19 @@ int main(int, char**)
|
||||||
|
|
||||||
bool ok = server->take_over_from_system_server("/tmp/portal/inspector");
|
bool ok = server->take_over_from_system_server("/tmp/portal/inspector");
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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();
|
auto inspectables_server = Core::LocalServer::construct();
|
||||||
if (!inspectables_server->take_over_from_system_server("/tmp/portal/inspectables"))
|
if (!inspectables_server->take_over_from_system_server("/tmp/portal/inspectables"))
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
||||||
inspectables_server->on_ready_to_accept = [&] {
|
inspectables_server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = inspectables_server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("backdoor accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto pid = client_socket->peer_pid();
|
auto pid = client_socket->peer_pid();
|
||||||
|
InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, move(client_socket)));
|
||||||
InspectorServer::g_processes.set(pid, make<InspectorServer::InspectableProcess>(pid, client_socket.release_nonnull()));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return event_loop.exec();
|
return event_loop.exec();
|
||||||
|
|
|
@ -29,15 +29,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||||
|
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("LaunchServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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();
|
return event_loop.exec();
|
||||||
|
|
|
@ -73,15 +73,10 @@ LookupServer::LookupServer()
|
||||||
m_mdns = MulticastDNS::construct(this);
|
m_mdns = MulticastDNS::construct(this);
|
||||||
|
|
||||||
m_local_server = Core::LocalServer::construct(this);
|
m_local_server = Core::LocalServer::construct(this);
|
||||||
m_local_server->on_ready_to_accept = [this]() {
|
m_local_server->on_accept = [this](auto client_socket) {
|
||||||
auto socket = m_local_server->accept();
|
|
||||||
if (!socket) {
|
|
||||||
dbgln("Failed to accept a client connection");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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();
|
bool ok = m_local_server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
|
|
|
@ -20,15 +20,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("NotificationServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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"));
|
TRY(Core::System::unveil("/res", "r"));
|
||||||
|
|
|
@ -37,15 +37,10 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
|
||||||
bool ok = server->take_over_from_system_server();
|
bool ok = server->take_over_from_system_server();
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
|
|
||||||
server->on_ready_to_accept = [&] {
|
server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("SQLServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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();
|
return event_loop.exec();
|
||||||
|
|
|
@ -30,26 +30,16 @@ EventLoop::EventLoop()
|
||||||
ok = m_wm_server->take_over_from_system_server("/tmp/portal/wm");
|
ok = m_wm_server->take_over_from_system_server("/tmp/portal/wm");
|
||||||
VERIFY(ok);
|
VERIFY(ok);
|
||||||
|
|
||||||
m_window_server->on_ready_to_accept = [this] {
|
m_window_server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = m_window_server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("WindowServer: accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_client_id = 0;
|
static int s_next_client_id = 0;
|
||||||
int client_id = ++s_next_client_id;
|
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] {
|
m_wm_server->on_accept = [&](auto client_socket) {
|
||||||
auto client_socket = m_wm_server->accept();
|
|
||||||
if (!client_socket) {
|
|
||||||
dbgln("WindowServer: WM accept failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static int s_next_wm_id = 0;
|
static int s_next_wm_id = 0;
|
||||||
int wm_id = ++s_next_wm_id;
|
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) {
|
if (m_keyboard_fd >= 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue