-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestreader.c
56 lines (46 loc) · 925 Bytes
/
testreader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <fcntl.h>
int do_read(int fd)
{
fd_set fds;
struct timeval tv;
int res;
char buf[1024];
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = 0;
tv.tv_usec = 0;
res = select(fd+1, &fds, NULL, NULL, &tv);
if(res < 0) {
perror("select()");
return -1;
}
if(!FD_ISSET(fd, &fds))
return 0;
res = read(fd, buf, 1024);
if(res < 0) {
perror("read()");
return -1;
} else {
return res;
}
}
int main()
{
int fd;
fd = open("softscope.fifo", O_RDONLY | O_NONBLOCK);
if(fd < 0) {
perror("Open softscope.fifo");
return -1;
}
while(1) {
printf("Read: %d\n", do_read(fd));
usleep(10000);
}
return 0;
}