X-Git-Url: https://git.llucax.com/software/eventxx.git/blobdiff_plain/1df0df01b00d420fcfbcb4ad0c0a74e885c828df..2c722f14fdce3f1a32bf26eb26d316cced826ba4:/test/prio-test.cpp?ds=sidebyside diff --git a/test/prio-test.cpp b/test/prio-test.cpp index cd6f73a..af5af5e 100644 --- a/test/prio-test.cpp +++ b/test/prio-test.cpp @@ -1,26 +1,34 @@ #include #include +#include #include +#include using eventxx::dispatcher; -#define OSASSERT(func, ...) if (func(__VA_ARGS__) == -1) { perror(#func "()"); exit(1); } +#define OSASSERT(func, ...) \ + if (func(__VA_ARGS__) == -1) { perror(#func "()"); std::exit(1); } struct handler { dispatcher& d; int fds[4]; + std::map< int, eventxx::basic_event* > events; handler(dispatcher& d): d(d) { OSASSERT(pipe, fds); OSASSERT(pipe, fds+2); } - void operator() (int fd, short event) + void add(eventxx::basic_event& e) + { + events[e.fd()] = &e; + } + void operator() (int fd, eventxx::type event) { char buf[7]; OSASSERT(read, fd, buf, 7); std::cout << "Read from fd " << fd << ": " << buf << "\n"; - d.exit(); + d.del(*events[fd]); } }; @@ -30,8 +38,10 @@ int main() handler h(d); OSASSERT(write, h.fds[1], "hola 1", 7); OSASSERT(write, h.fds[3], "hola 2", 7); - eventxx::event< handler > e1(h.fds[0], EV_READ, h); - eventxx::event< handler > e2(h.fds[2], EV_READ, h); + eventxx::event< handler > e1(h.fds[0], eventxx::READ, h); + eventxx::event< handler > e2(h.fds[2], eventxx::READ, h); + h.add(e1); + h.add(e2); d.add(e1, 1); d.add(e2, 0); d.dispatch();