1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 12:17:35 +00:00

LibCore: Port CoreIPCServer to using CLocalServer.

Use CLocalServer to listen for connections in WindowServer and AudioServer.
This allows us to accept incoming CLocalSocket objects from the CLocalServer
and construct client connections based on those.

Removed COpenedSocket since it's replaced by CLocalSocket.
This commit is contained in:
Andreas Kling 2019-07-27 10:53:50 +02:00
parent c289e49ee5
commit fe45f5a6d2
9 changed files with 40 additions and 93 deletions

View file

@ -1,5 +1,6 @@
#include <Kernel/KeyCode.h>
#include <Kernel/MousePacket.h>
#include <LibCore/CLocalSocket.h>
#include <LibCore/CObject.h>
#include <WindowServer/WSAPITypes.h>
#include <WindowServer/WSClientConnection.h>
@ -25,22 +26,22 @@ WSEventLoop::WSEventLoop()
m_mouse_fd = open("/dev/psaux", O_RDONLY | O_NONBLOCK | O_CLOEXEC);
unlink("/tmp/wsportal");
m_server_sock.listen("/tmp/wsportal");
sockaddr_un address;
address.sun_family = AF_LOCAL;
strcpy(address.sun_path, "/tmp/wsportal");
int rc = bind(m_server_sock.fd(), (const sockaddr*)&address, sizeof(address));
ASSERT(rc == 0);
rc = listen(m_server_sock.fd(), 5);
ASSERT(rc == 0);
m_server_sock.on_ready_to_accept = [this] {
auto* client_socket = m_server_sock.accept();
if (!client_socket) {
dbg() << "WindowServer: accept failed.";
return;
}
static int s_next_client_id = 0;
int client_id = ++s_next_client_id;
IPC::Server::new_connection_for_client<WSClientConnection>(*client_socket, client_id);
};
ASSERT(m_server_sock.fd() >= 0);
ASSERT(m_keyboard_fd >= 0);
ASSERT(m_mouse_fd >= 0);
m_server_notifier = make<CNotifier>(m_server_sock.fd(), CNotifier::Read);
m_server_notifier->on_ready_to_read = [this] { drain_server(); };
m_keyboard_notifier = make<CNotifier>(m_keyboard_fd, CNotifier::Read);
m_keyboard_notifier->on_ready_to_read = [this] { drain_keyboard(); };
@ -52,20 +53,6 @@ WSEventLoop::~WSEventLoop()
{
}
void WSEventLoop::drain_server()
{
sockaddr_un address;
socklen_t address_size = sizeof(address);
int client_fd = accept(m_server_sock.fd(), (sockaddr*)&address, &address_size);
if (client_fd < 0) {
dbgprintf("WindowServer: accept() failed: %s\n", strerror(errno));
} else {
static int s_next_client_id = 0;
int client_id = ++s_next_client_id;
IPC::Server::new_connection_for_client<WSClientConnection>(client_fd, client_id);
}
}
void WSEventLoop::drain_mouse()
{
auto& screen = WSScreen::the();
@ -109,4 +96,3 @@ void WSEventLoop::drain_keyboard()
screen.on_receive_keyboard_data(event);
}
}