X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2Ftest_timerfdfork.c;h=34ceaedd1b317c0d29bf31397a2a7e5718ad54f0;hb=a59f46f457248921d34ba7175697a129469d6d90;hp=04fad750973f0726300a3e987fc530d5fc59e7fb;hpb=bd8c369514b9f49a58fe22c095f5313a521e6ee2;p=gapil.git diff --git a/sources/test_timerfdfork.c b/sources/test_timerfdfork.c index 04fad75..34ceaed 100644 --- a/sources/test_timerfdfork.c +++ b/sources/test_timerfdfork.c @@ -37,18 +37,28 @@ #include /* standard I/O library */ #include /* C strings library */ #include /* timerfd */ +#include /* Linux epoll interface */ // #include +#include "macros.h" +#include "Gapil.h" + /* Help printing routine */ void usage(void); +void die(char *); + +#define MAX_EPOLL_EV 10 int main(int argc, char *argv[]) { /* * Variables definition */ - int i, fd; + int i, n, nread, fd, epfd; + pid_t pid; + struct epoll_event epev, events[MAX_EPOLL_EV]; struct itimerspec expiring; + uint64_t expirated; /* * Input section: decode command line parameters * Use getopt function @@ -83,15 +93,53 @@ int main(int argc, char *argv[]) printf("From %d arguments, removed %d options\n", argc, optind); usage(); } - + /* timerfd setup */ fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); expiring.it_interval.tv_sec=1; expiring.it_interval.tv_nsec=0; expiring.it_value.tv_sec=5; expiring.it_value.tv_nsec=0; - if (timerfd_settime(fd, 0, expiring, NULL)) { - perror("Cannot set timer"); + if (timerfd_settime(fd, 0, &expiring, NULL)) { + die("Cannot set timer"); } + pid = fork(); + /* epoll setup */ + if ((epfd=epoll_create(5)) < 0) + die("Failing on epoll_create"); + epev.data.fd = fd; + epev.events = EPOLLIN; + if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &epev)) + die("Failing in epoll_ctl"); + /* main loop */ + //while (1) { + if ((n=epoll_wait(epfd, events, MAX_EPOLL_EV, -1)) < 0) + die("error on epoll_wait"); + debug("Got %i events\n", n); + /* loop on epoll events */ + for (i=0; i