diff --git a/wind/Client.h b/wind/Client.h index 30b402ad..435590cc 100644 --- a/wind/Client.h +++ b/wind/Client.h @@ -8,4 +8,11 @@ struct Client Vector windows; bool rpc_in_progress { false }; u8 rpc_id { 0 }; + + Client(os::LocalServer::Client&& client) +#ifdef CLIENT_IMPLEMENTATION + : conn(move(client)), windows() {} +#else + ; +#endif }; diff --git a/wind/main.cpp b/wind/main.cpp index 419feb1e..fc24786d 100644 --- a/wind/main.cpp +++ b/wind/main.cpp @@ -1,3 +1,4 @@ +#define CLIENT_IMPLEMENTATION #include "Client.h" #include "IPC.h" #include "Mouse.h" @@ -18,7 +19,7 @@ #include #include -static void debug(const Vector& clients) +static void debug(const Vector>& clients) { os::println("--- wind: DEBUG OUTPUT ---"); @@ -26,7 +27,7 @@ static void debug(const Vector& clients) for (const auto& client : clients) { - os::println("Client with fd %d, owns %zu windows", client.conn.fd(), client.windows.size()); + os::println("Client with fd %d, owns %zu windows", client->conn.fd(), client->windows.size()); } os::println("-- wind: Listing windows --"); @@ -113,7 +114,7 @@ Result luna_main(int argc, char** argv) ui::Color background = ui::BLACK; - Vector clients; + Vector> clients; Vector fds; TRY(fds.try_append({ .fd = mouse->fd(), .events = POLLIN, .revents = 0 })); TRY(fds.try_append({ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 })); @@ -149,14 +150,14 @@ Result luna_main(int argc, char** argv) } for (usize i = 0; i < clients.size(); i++) { - if (fds[i + 3].revents & POLLIN) wind::handle_ipc(clients[i]); + if (fds[i + 3].revents & POLLIN) wind::handle_ipc(*clients[i]); if (fds[i + 3].revents & POLLHUP) { os::println("wind: Client %d disconnected", i); fds.remove_at(i + 3); auto client = clients.remove_at(i); - client.conn.disconnect(); - for (auto& window : client.windows) + client->conn.disconnect(); + for (auto& window : client->windows) { if (window) { @@ -171,7 +172,7 @@ Result luna_main(int argc, char** argv) auto client = TRY(server->accept()); os::println("wind: New client connected!"); TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 })); - Client c { move(client), {} }; + OwnedPtr c = TRY(adopt_owned_if_nonnull(new Client(move(client)))); TRY(clients.try_append(move(c))); } }