initial commit
This commit is contained in:
commit
bb3f9a0bc6
18 files changed
+1053
No files matched your search
@@ -0,0 +1,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <eventloop.h>
|
||||
|
||||
int main() {
|
||||
struct tlsl_event timer, pipe_ev;
|
||||
EVENTLOOP_STACK_SCOPED(el);
|
||||
tlsl_event_id_t id;
|
||||
uint32_t flags;
|
||||
|
||||
int pfds[2];
|
||||
if (pipe(pfds))
|
||||
return 1;
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid < 0)
|
||||
return 1;
|
||||
|
||||
if (!pid) {
|
||||
char buf[] = "hello!";
|
||||
sleep(5);
|
||||
write(pfds[1], buf, sizeof(buf));
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (tlsl_eventloop_init(&el))
|
||||
return 1;
|
||||
|
||||
if (tlsl_eventloop_add_timer(&el, &timer, 2000, false))
|
||||
return 1;
|
||||
|
||||
if (tlsl_eventloop_add_fd(&el, &pipe_ev, pfds[0], TLSL_EVENT_READABLE))
|
||||
return 1;
|
||||
|
||||
for (;;) {
|
||||
if (tlsl_eventloop_wait(&el, &id, &flags, -1)) {
|
||||
fprintf(stderr, "failed to wait");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tlsl_event_id_eq(id, timer.id)) {
|
||||
tlsl_eventloop_clear(&el, &timer);
|
||||
printf("timer tick flags=%u\n", flags);
|
||||
}
|
||||
else if (tlsl_event_id_eq(id, pipe_ev.id)) {
|
||||
char buf[1024] = { 0 };
|
||||
read(pfds[0], buf, sizeof(buf) - 1);
|
||||
printf("pipe event flags=%u buf=%s\n", flags, buf);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "unknown id");
|
||||
}
|
||||
}
|
||||
|
||||
tlsl_eventloop_remove(&el, &timer);
|
||||
tlsl_eventloop_remove(&el, &pipe_ev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user