I am working on a monothreaded process applet which creates a proxy virtual device (more precisely a virtual Xbox 360 pad); I do manage to create it with the uinput interface, I set it up properly and it works just fine.
In order to feed commands to this virtual device, I read events from another real interface (in this case a PS3 pad), and I open the real device file with these flags:
fd = open("/dev/input/event22", O_RDONLY); // open the PS3 pad
The main loop is something like (minus error checking):
while(run) {
input_event ev = {0};
read(fd, &ev, sizeof(struct input_event));
// convert from PS3 --> Xbox 360
convert(ev);
// write to the new virtual pad
write(fd_virtual, &ev, sizeof(struct input_event));
}
As you can imagine the read(fd, &ev, sizeof(struct input_event));
is a blocking call and I would like to have a sort of timeout to cycle through the loop and check for other events/execute other code.
For these reasons I am thinking of encapsulating that read(fd...
call inside an epoll loop, so I can also have a timeout.
Question is, would it be efficient to have it done this way? By virtue of using epoll_wait, am I introducing additional delays to the current loop, thus delays in responsiveness of the virtual pad?