From db9ba86023886d6ba4344921e8a2e4de731e839d Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 24 Sep 2007 16:52:40 -0300 Subject: [PATCH] Fixed the main documentation example which was *WRONG*. libevent don't support multiple callbacks for the same event, so the main example presented in eventxx documentation was wrong. Thanks Jason Novak for reporting the problem. --- README | 10 +++++----- test/mixed-way.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README b/README index 380ecfb..dbc5a6a 100644 --- a/README +++ b/README @@ -92,6 +92,7 @@ struct handler handler(eventxx::dispatcher& d): d(d), i(0) {} void operator() (int signum, eventxx::type event) { + std::cout << ++i << " interrupts, "; if (i < 5) std::cout << "keep going...\n"; else { @@ -101,19 +102,18 @@ struct handler } }; -void sighandler(int signum, short event, void* data) +void timer_handler(int, short, void*) { - int& i = *static_cast< int* >(data); - std::cout << ++i << " interrupts, "; + std::cout << "Press Ctrl-C 5 times to quit.\n"; } int main() { eventxx::dispatcher d; handler h(d); - eventxx::csignal sigev(SIGINT, sighandler, &h.i); + eventxx::ctimer t(timer_handler); eventxx::signal< handler > e(SIGINT, h); - d.add(sigev); + d.add(t, eventxx::time(1)); // 1 second d.add(e); d.dispatch(); return 0; diff --git a/test/mixed-way.cpp b/test/mixed-way.cpp index daea2e6..f3238b2 100644 --- a/test/mixed-way.cpp +++ b/test/mixed-way.cpp @@ -9,6 +9,7 @@ struct handler handler(eventxx::dispatcher& d): d(d), i(0) {} void operator() (int signum, eventxx::type event) { + std::cout << ++i << " interrupts, "; if (i < 5) std::cout << "keep going...\n"; else { @@ -18,19 +19,18 @@ struct handler } }; -void sighandler(int signum, short event, void* data) +void timer_handler(int, short, void*) { - int& i = *static_cast< int* >(data); - std::cout << ++i << " interrupts, "; + std::cout << "Press Ctrl-C 5 times to quit.\n"; } int main() { eventxx::dispatcher d; handler h(d); - eventxx::csignal sigev(SIGINT, sighandler, &h.i); + eventxx::ctimer t(timer_handler); eventxx::signal< handler > e(SIGINT, h); - d.add(sigev); + d.add(t, eventxx::time(1)); // 1 second d.add(e); d.dispatch(); return 0; -- 2.43.0