wind: Monitor data on client connections
This commit is contained in:
parent
6a35cad8d5
commit
e931d11ae1
@ -87,6 +87,10 @@ Result<int> luna_main(int argc, char** argv)
|
||||
TRY(make<Window>(ui::Rect { 600, 130, 350, 250 }, ui::CYAN, "File Manager"_sv));
|
||||
|
||||
Vector<os::LocalServer::Client> clients;
|
||||
Vector<struct pollfd> fds;
|
||||
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 = server->fd(), .events = POLLIN, .revents = 0 }));
|
||||
|
||||
TRY(os::Security::pledge("stdio rpath unix", NULL));
|
||||
|
||||
@ -97,13 +101,9 @@ Result<int> luna_main(int argc, char** argv)
|
||||
mouse_pointer.draw(screen.canvas());
|
||||
screen.sync();
|
||||
|
||||
struct pollfd fds[] = {
|
||||
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
||||
{ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 },
|
||||
{ .fd = server->fd(), .events = POLLIN, .revents = 0 },
|
||||
};
|
||||
for (auto& pfd : fds) { pfd.revents = 0; }
|
||||
|
||||
int rc = poll(fds, 3, 1000);
|
||||
int rc = poll(fds.data(), fds.size(), 1000);
|
||||
if (!rc) continue;
|
||||
if (rc < 0 && errno != EINTR) { os::println("poll: error: %s", strerror(errno)); }
|
||||
|
||||
@ -126,10 +126,22 @@ Result<int> luna_main(int argc, char** argv)
|
||||
strerror(packet.key)));
|
||||
}
|
||||
}
|
||||
for (usize i = 0; i < clients.size(); i++)
|
||||
{
|
||||
if (fds[i + 3].revents & POLLIN) os::println("wind: Client %d sent data!", 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.disconnect();
|
||||
}
|
||||
}
|
||||
if (fds[2].revents & POLLIN)
|
||||
{
|
||||
auto client = TRY(server->accept());
|
||||
os::println("wind: New client connected!");
|
||||
TRY(fds.try_append({ .fd = client.fd(), .events = POLLIN, .revents = 0 }));
|
||||
TRY(clients.try_append(move(client)));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user