From 1b017733cbae399a6f8a4bdec93c69c85662afd4 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Wed, 15 Apr 2020 01:27:16 +0200 Subject: [PATCH] comments --- macrod.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/macrod.c b/macrod.c index 6928a67..ccc0ae8 100644 --- a/macrod.c +++ b/macrod.c @@ -27,7 +27,7 @@ struct pressed_buffer { unsigned int size; }; -int term = 0; // Received SIGTERM flag +int term = 0; // exit flag const char ev_root[] = "/dev/input/"; int pressBufferAdd (struct pressed_buffer*, unsigned short); @@ -80,14 +80,17 @@ int main (void) } closedir(ev_dir); // TODO: watch for events inside /dev/input and reload accordingly - // could use the inotify API (linux specific), a separate process - // or some polling system inside the main loop to maintain portability - // across other *NIX derivatives + // could use the epoll syscall or the inotify API (linux), + // event API (openbsd), kqueue syscall (BSD and macos), a separate + // process or some polling system inside the main loop to maintain + // portability across other *NIX derivatives, could also use libev struct input_event event; struct pressed_buffer pb = {NULL, 0}; // Pressed keys buffer ssize_t rb; // Read bits + // TODO: optimize the loop with an O(1) call as it runs for every + // event, some of those are in the previous comment while (poll(fds, fd_num, -1) != -1 && !term) { /* Use poll(2) to wait por a file dscriptor to become ready for reading. * NOTE: this could use select(2) but I don't know how */