Compare commits

..

No commits in common. "56066f332fe60c4b83a0cbb3430a723cbf5dd441" and "8b1632f443b164709d78290683239b2e1f8c8e08" have entirely different histories.

3 changed files with 13 additions and 24 deletions

View File

@ -8,11 +8,4 @@ struct Client
Vector<Window*> windows; Vector<Window*> windows;
bool rpc_in_progress { false }; bool rpc_in_progress { false };
u8 rpc_id { 0 }; u8 rpc_id { 0 };
Client(os::LocalServer::Client&& client)
#ifdef CLIENT_IMPLEMENTATION
: conn(move(client)), windows() {}
#else
;
#endif
}; };

View File

@ -26,32 +26,29 @@ static Result<u32*> create_shm_region(const char* path, int* outfd, ui::Rect rec
int fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600); int fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd < 0) if (fd < 0)
{ {
int olderr = errno; os::eprintln("wind: could not create shared memory region: shm_open failed (%s) - %s", path, strerror(errno));
os::eprintln("wind: could not create shared memory region: shm_open failed (%s) - %s", path, strerror(olderr)); return err(errno);
return err(olderr);
} }
usize size = align_up<PAGE_SIZE>(rect.width * rect.height * 4); // 4 bytes per pixel usize size = align_up<PAGE_SIZE>(rect.width * rect.height * 4); // 4 bytes per pixel
if (ftruncate(fd, size) < 0) if (ftruncate(fd, size) < 0)
{ {
int olderr = errno;
os::eprintln("wind: could not create shared memory region: ftruncate failed (%d, %zu) - %s", fd, size, os::eprintln("wind: could not create shared memory region: ftruncate failed (%d, %zu) - %s", fd, size,
strerror(olderr)); strerror(errno));
shm_unlink(path); shm_unlink(path);
close(fd); close(fd);
return err(olderr); return 0;
} }
void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); void* p = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) if (p == MAP_FAILED)
{ {
int olderr = errno;
os::eprintln("wind: could not create shared memory region: mmap failed (%zu, %d) - %s", size, fd, os::eprintln("wind: could not create shared memory region: mmap failed (%zu, %d) - %s", size, fd,
strerror(olderr)); strerror(errno));
shm_unlink(path); shm_unlink(path);
close(fd); close(fd);
return err(olderr); return 0;
} }
if (outfd) *outfd = fd; if (outfd) *outfd = fd;

View File

@ -1,4 +1,3 @@
#define CLIENT_IMPLEMENTATION
#include "Client.h" #include "Client.h"
#include "IPC.h" #include "IPC.h"
#include "Mouse.h" #include "Mouse.h"
@ -19,7 +18,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
static void debug(const Vector<OwnedPtr<Client>>& clients) static void debug(const Vector<Client>& clients)
{ {
os::println("--- wind: DEBUG OUTPUT ---"); os::println("--- wind: DEBUG OUTPUT ---");
@ -27,7 +26,7 @@ static void debug(const Vector<OwnedPtr<Client>>& clients)
for (const auto& client : 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 --"); os::println("-- wind: Listing windows --");
@ -114,7 +113,7 @@ Result<int> luna_main(int argc, char** argv)
ui::Color background = ui::BLACK; ui::Color background = ui::BLACK;
Vector<OwnedPtr<Client>> clients; Vector<Client> clients;
Vector<struct pollfd> fds; Vector<struct pollfd> fds;
TRY(fds.try_append({ .fd = mouse->fd(), .events = POLLIN, .revents = 0 })); TRY(fds.try_append({ .fd = mouse->fd(), .events = POLLIN, .revents = 0 }));
TRY(fds.try_append({ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 })); TRY(fds.try_append({ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 }));
@ -150,14 +149,14 @@ Result<int> luna_main(int argc, char** argv)
} }
for (usize i = 0; i < clients.size(); i++) 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) if (fds[i + 3].revents & POLLHUP)
{ {
os::println("wind: Client %d disconnected", i); os::println("wind: Client %d disconnected", i);
fds.remove_at(i + 3); fds.remove_at(i + 3);
auto client = clients.remove_at(i); auto client = clients.remove_at(i);
client->conn.disconnect(); client.conn.disconnect();
for (auto& window : client->windows) for (auto& window : client.windows)
{ {
if (window) if (window)
{ {
@ -172,7 +171,7 @@ Result<int> luna_main(int argc, char** argv)
auto client = TRY(server->accept()); auto client = TRY(server->accept());
os::println("wind: New client connected!"); os::println("wind: New client connected!");
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 })); TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
OwnedPtr<Client> c = TRY(adopt_owned_if_nonnull(new Client(move(client)))); Client c { move(client), {} };
TRY(clients.try_append(move(c))); TRY(clients.try_append(move(c)));
} }
} }