]> git.llucax.com Git - software/eventxx.git/commitdiff
Fix a bug when the dispatcher destructor is working.
authorLeandro Lucarella <llucarella@integratech.com.ar>
Tue, 2 Jan 2007 20:01:53 +0000 (20:01 +0000)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Tue, 2 Jan 2007 20:01:53 +0000 (20:01 +0000)
eventxx
test/prio-test.cpp

diff --git a/eventxx b/eventxx
index 93e2669b8db40173ed41e7daaa01d339f3e1cceb..d2846ec53d804ddf47cae84e26f4c722e8276c18 100644 (file)
--- a/eventxx
+++ b/eventxx
@@ -537,6 +537,8 @@ struct dispatcher
 
 #ifdef EVENT_BASE_FREE_FIX
        ~dispatcher() throw() { event_base_free(_event_base); }
+#else
+#warning "The dispatcher class *will* leak memory because of a libevent bug, see http://www.mail-archive.com/libevent-users@monkey.org/msg00110.html for more info an a patch. If you already have this patch, please -DEVENT_BASE_FREE_FIX to your compiler to make this message disappear and really free the dispatcher memory using event_base_free()."
 #endif
 
        /**
index cd6f73a6808bc4827b908a89b91a91439aec868d..613d111d3959499c2743aa4de7167c399fb49a42 100644 (file)
@@ -1,5 +1,6 @@
 #include <eventxx>
 #include <iostream>
+#include <map>
 #include <csignal>
 
 using eventxx::dispatcher;
@@ -10,17 +11,22 @@ 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 +36,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();