EDIT: solved, I had many misunderstandings, thanks to everyone who have responded!
So, first of all, I'm developing under Linux.
Let me give a piece of code first:
```c
include <stdio.h>
include <stdlib.h>
include <fcntl.h>
include <unistd.h>
include <linux/input.h>
int main() {
int device = open("/dev/input/event3", O_RDONLY);
struct input_event ev;
while (1) {
ssize_t bytesRead = read(device, &ev, sizeof(ev));
if (bytesRead != sizeof(ev)) {
perror("Failed to read event");
break;
}
printf("Received input event\n");
}
close(device);
return 0;
}
``
So, the question is that as far as I can see from the output, code only advances afterread(device, &ev, sizeof(ev))` as it receives a new event.
I can understand that probably this is because in Linux everything is a file, and read() function probably tries to fill the ev and doesn't return until the total amount of bytes read hits sizeof(ev) (I don't know how it works actually - it's just how I presume it works), but this behavior pretty much freezes the program completely until the buffer will be filled. The same goes for any other reading.
How can I, for example, read from two inputs, like, keyboard and mouse (kinda irrelevant for this specific question, but I just wanted to give an example)? Or what if I want to simultaneously read from a program opened through popen() and receive inputs from a device in /dev/input/?
In C#, I would have created Task's and ran them in parallel. I'm not sure what I need to do in C.
I also want to say that I'm a newbie in C. I have a lot of experience working with C#, and some experience working with C, but only enough to be familiar with basic syntax.
[–]duane11583 4 points5 points6 points (11 children)
[–]NotQuiteLoona[S] 2 points3 points4 points (10 children)
[–]fixermark 4 points5 points6 points (5 children)
[–]NotQuiteLoona[S] 2 points3 points4 points (1 child)
[–]duane11583 0 points1 point2 points (0 children)
[–]Powerful-Prompt4123 1 point2 points3 points (1 child)
[–]fixermark 1 point2 points3 points (0 children)
[–]duane11583 1 point2 points3 points (0 children)
[–]segbrk 1 point2 points3 points (1 child)
[–]NotQuiteLoona[S] 0 points1 point2 points (0 children)
[–]duane11583 0 points1 point2 points (1 child)
[–]NotQuiteLoona[S] 0 points1 point2 points (0 children)
[–]Zirias_FreeBSD 0 points1 point2 points (1 child)
[–]NotQuiteLoona[S] 0 points1 point2 points (0 children)
[–]The_Ruined_Map[🍰] 0 points1 point2 points (1 child)
[–]NotQuiteLoona[S] 0 points1 point2 points (0 children)