1 // NOTE: This file is in doxygen[1] format. Maybe you should try to run
2 // doxygen to get a better looking documentation ;)
4 // [1] http://www.stack.nl/~dimitri/doxygen/
10 @libevent is a popular API that provides a mechanism to execute a callback
11 function when a specific event occurs on a file descriptor or after a
12 timeout has been reached. Furthermore, @libevent also support callbacks due
13 to signals or regular timeouts.
15 @eventxx is a simple, direct, one-header inline C++ wrapper for @libevent.
16 Yes, it's just one header file, so if you want to use it you can just copy
17 the file to your project and you are set (well, you'll need to link to
20 It's designed to be as close to use to @libevent (without compromising
21 modern C++ programming techniques) and efficient (since all implementation
22 is trivial and inline, theoretically, it imposes no overhead at all) as
25 Please, visit the @eventxx website for the latest version of this
28 You can always get the <a href="@home/releases/eventxx.tar.gz">current
29 release</a> from the <a href="@home/releases/">release directory</a> or
30 grab the <a href="@gitweb?a=snapshot">most up to date sources</a> from
31 the <a href="http://git.or.cz/">git</a> repository.
33 You can also take a look the the <a href="@gitweb">eventxx gitweb</a>
34 interface to see the latest changes online or subscribe to its
35 <a href="@gitweb?a=atom">Atom feed</a> to follow the development.
37 For more information, bug reports or support, please visit the
38 <a href="@redmine">eventxx project</a>.
43 You probably should read @libevent documentation to get started or at least
44 just for reference, although @eventxx is pretty simple so you can jump right
45 into the \ref Example section (or the example list) and write a working
46 program without much trouble.
48 This wrapper was designed to be used just like @libevent, but with C++ style
49 syntax sugar (or poison, depends on your point of view ;) and goodies. The
50 main difference to libevent is you always have to instance a
51 eventxx::dispatcher to get an event loop. There is no implicit global event
52 loop. This adds just an extra line of code for single threaded applications
53 and makes things much more simpler, so I hope nobody complains about it ;).
54 See eventxx::dispatcher documentation for more details.
56 You can use use the same plain functions callbacks @libevent use or the other
57 kind of function objects (see @ref events section for details on event
60 @eventxx uses @ref exceptions to report errors. All functions have exception
61 specifications, so it's easy to find out what to expect. See @ref exceptions
62 section for more detail.
64 A @c timespec abstraction is provided as eventxx::time for convenient
65 argument passing. Even more, it's a @c timespec itself, with some convenient
66 methods for accessing the attributes with pritier names. And even more,
67 @eventxx is such a direct mapping that all eventxx::event's are @libevent
68 event structs too, so theoretically you can pass a eventxx::event to
69 @libevent C functions without much trouble. eventxx::dispatcher is the only
70 class that is not derived from @libevent struct (@c event_base) because this
71 struct it's not defined on the libevent header (just declared).
73 Maybe you shouldn't know this implementation details to keep the abstraction,
74 but this is a basic design goal of this wrapper so there is not much chance
75 that this changes in the future (but use this knowledge with care, you have
88 eventxx::dispatcher& d;
90 handler(eventxx::dispatcher& d): d(d), i(0) {}
91 void operator() (int signum, eventxx::type event)
93 std::cout << ++i << " interrupts, ";
94 if (i < 5) std::cout << "keep going...\n";
97 std::cout << "done!\n";
103 void timer_handler(int, short, void*)
105 std::cout << "Press Ctrl-C 5 times to quit.\n";
110 eventxx::dispatcher d;
112 eventxx::ctimer t(timer_handler);
113 eventxx::signal< handler > e(SIGINT, h);
114 d.add(t, eventxx::time(1)); // 1 second
121 You can see more examples on the test directory of the distribution or on the
122 examples related page.
127 I think the library is stable now. The library has no support for buffered
128 events yet, but patches are welcome. It doesn't support the HTTP stuff, and
129 probably never will because that has nothing to do with event handling.
131 @libevent had a memory leak before version 1.3b (before 1.2 it didn't even
132 had a way free that memory, from version 1.2 to 1.3a, if you tried to free
133 the memory the program @c abort() because a failed assertion). Because of
134 that, there is a way to disable the @link eventxx::dispatcher::~dispatcher()
135 dispatcher destructor @endlink (which calls the inexistent/broken
136 @c event_base_free() function in the broken versions). So if you use a
137 @libevent version previous to 1.3b, you have to compile your programs
138 defining the @c EVENTXX_NO_EVENT_BASE_FREE macro.
140 If something is broken it would be really easy to fix because @eventxx is
141 just a simple wrapper around @libevent. So, please try it out, and if you
142 have any problems, <a href="mailto:llucax+eventxx@gmail.com">drop me an
143 e-mail</a> and and I'll fix it ASAP (or provide a patch and you will be my
146 If you use this library, please drop me an e-mail with your thoughts, or
147 simply saying "I use it", so I can keep track of how many people really use
150 @author Leandro Lucarella <llucax+eventxx@gmail.com>
155 This program is under the <a href="http://auriga.wearlab.de/~alb/bola/">BOLA
156 License</a> (see the license website or the
157 <a href="@gitweb?a=blob_plain;f=LICENSE">LICENSE</a>
158 file itself for more details, it's very short and it basically says it's
163 /** @example c-way.cpp
164 This is a simple example illustrating the usage with C-like callback
168 /** @example functor-way.cpp
169 This is a simple example illustrating the usage with function object
173 /** @example wrapped-functor-way.cpp
174 This is a simple example illustrating the usage with an arbitrary member
175 function as an event handler callbacks.
178 /** @example mixed-way.cpp
179 This is a simple example illustrating the usage with a mix of C-like callbacks
180 and function object callbacks.
183 /** @example bench.cpp
184 This is a benchmark example, extracted from libevent and ported to eventxx.
187 /** @example prio-test.cpp
188 This is a priority usage example.
191 /** @example test-time.cpp
192 This is a timer usage example ported from libevent.
195 /** @example test-eof.cpp
196 This is some kind of test of EOF ported from libevent.
199 /** @example test-weof.cpp
200 Another test of EOF ported from libevent.
203 /** @example trivial.cpp
204 This is the most trivial example.