wind: Monitor data on client connections
This commit is contained in:
parent
753a56d14c
commit
2c2c6fbc2d
@ -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));
|
TRY(make<Window>(ui::Rect { 600, 130, 350, 250 }, ui::CYAN, "File Manager"_sv));
|
||||||
|
|
||||||
Vector<os::LocalServer::Client> clients;
|
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));
|
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());
|
mouse_pointer.draw(screen.canvas());
|
||||||
screen.sync();
|
screen.sync();
|
||||||
|
|
||||||
struct pollfd fds[] = {
|
for (auto& pfd : fds) { pfd.revents = 0; }
|
||||||
{ .fd = mouse->fd(), .events = POLLIN, .revents = 0 },
|
|
||||||
{ .fd = keyboard->fd(), .events = POLLIN, .revents = 0 },
|
|
||||||
{ .fd = server->fd(), .events = POLLIN, .revents = 0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
int rc = poll(fds, 3, 1000);
|
int rc = poll(fds.data(), fds.size(), 1000);
|
||||||
if (!rc) continue;
|
if (!rc) continue;
|
||||||
if (rc < 0 && errno != EINTR) { os::println("poll: error: %s", strerror(errno)); }
|
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)));
|
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)
|
if (fds[2].revents & POLLIN)
|
||||||
{
|
{
|
||||||
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(clients.try_append(move(client)));
|
TRY(clients.try_append(move(client)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user