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
29 href="http://www.llucax.com.ar/~luca/eventxx/releases/eventxx.tar.gz">current
31 <a href="http://www.llucax.com.ar/~luca/eventxx/releases/">release
32 directory</a> or grab the
33 <a href="http://git.llucax.com.ar/?p=software/eventxx.git;a=snapshot">most up
34 to date sources</a> from the <a href="http://git.or.cz/">git</a> repository.
36 You can also take a look the the <a
37 href="http://git.llucax.com.ar/?p=software/eventxx.git;a=summary">eventxx
38 gitweb</a> interface to see the latest changes online or subscribe to its
39 <a href="http://git.llucax.com.ar/?p=software/eventxx.git;a=atom">RSS
40 feed</a> to follow the development.
45 You probably should read @libevent documentation to get started or at least
46 just for reference, although @eventxx is pretty simple so you can jump right
47 into the \ref Example section (or the example list) and write a working
48 program without much trouble.
50 This wrapper was designed to be used just like @libevent, but with C++ style
51 syntax sugar (or poison, depends on your point of view ;) and goodies. The
52 main difference to libevent is you always have to instance a
53 eventxx::dispatcher to get an event loop. There is no implicit global event
54 loop. This adds just an extra line of code for single threaded applications
55 and makes things much more simpler, so I hope nobody complains about it ;).
56 See eventxx::dispatcher documentation for more details.
58 You can use use the same plain functions callbacks @libevent use or the other
59 kind of function objects (see @ref events section for details on event
62 @eventxx uses @ref exceptions to report errors. All functions have exception
63 specifications, so it's easy to find out what to expect. See @ref exceptions
64 section for more detail.
66 A @c timespec abstraction is provided as eventxx::time for convenient
67 argument passing. Even more, it's a @c timespec itself, with some convenient
68 methods for accessing the attributes with pritier names. And even more,
69 @eventxx is such a direct mapping that all eventxx::event's are @libevent
70 event structs too, so theoretically you can pass a eventxx::event to
71 @libevent C functions without much trouble. eventxx::dispatcher is the only
72 class that is not derived from @libevent struct (@c event_base) because this
73 struct it's not defined on the libevent header (just declared).
75 Maybe you shouldn't know this implementation details to keep the abstraction,
76 but this is a basic design goal of this wrapper so there is not much chance
77 that this changes in the future (but use this knowledge with care, you have
90 eventxx::dispatcher& d;
92 handler(eventxx::dispatcher& d): d(d), i(0) {}
93 void operator() (int signum, eventxx::type event)
95 if (i < 5) std::cout << "keep going...\n";
98 std::cout << "done!\n";
104 void sighandler(int signum, short event, void* data)
106 int& i = *static_cast< int* >(data);
107 std::cout << ++i << " interrupts, ";
112 eventxx::dispatcher d;
114 eventxx::csignal sigev(SIGINT, sighandler, &h.i);
115 eventxx::signal< handler > e(SIGINT, h);
123 You can see more examples on the test directory of the distribution or on the
124 examples related page.
129 I think the library is moderately stable now. The library has no support
130 for buffered events yet, but patches are welcome. It doesn't support the
131 HTTP stuff, and probably never will because that has nothing to do with
134 @libevent had a memory leak before version 1.3b (before 1.2 it didn't even
135 had a way free that memory, from version 1.2 to 1.3a, if you tried to free
136 the memory the program @c abort() because a failed assertion). Because of
137 that, there is a way to disable the @link eventxx::dispatcher::~dispatcher()
138 dispatcher destructor @endlink (which calls the inexistent/broken
139 @c event_base_free() function in the broken versions). So if you use a
140 @libevent version previous to 1.3b, you have to compile your programs
141 defining the @c EVENTXX_NO_EVENT_BASE_FREE macro.
143 If something is broken it would be really easy to fix because @eventxx is
144 just a simple wrapper around @libevent. So, please try it out, and if you
145 have any problems, <a href="mailto:llucax+eventxx@gmail.com">drop me an
146 e-mail</a> and and I'll fix it ASAP (or provide a patch and you will be my
149 If you use this library, please drop me an e-mail with your thoughts, or
150 simply saying "I use it", so I can keep track of how many people really use
153 @author Leandro Lucarella <llucax+eventxx@gmail.com>
158 This program is under the BOLA license (see
159 http://auriga.wearlab.de/~alb/bola/ for more details or read the
160 <a href="http://git.llucax.com.ar/?p=software/eventxx.git;a=blob_plain;f=LICENSE">LICENSE</a>
161 file itself, it's very short and it basically says it's Public Domain).
165 /** @example c-way.cpp
166 This is a simple example illustrating the usage with C-like callback
170 /** @example functor-way.cpp
171 This is a simple example illustrating the usage with function object
175 /** @example wrapped-functor-way.cpp
176 This is a simple example illustrating the usage with an arbitrary member
177 function as an event handler callbacks.
180 /** @example mixed-way.cpp
181 This is a simple example illustrating the usage with a mix of C-like callbacks
182 and function object callbacks.
185 /** @example bench.cpp
186 This is a benchmark example, extracted from libevent and ported to eventxx.
189 /** @example prio-test.cpp
190 This is a priority usage example.
193 /** @example test-time.cpp
194 This is a timer usage example ported from libevent.
197 /** @example test-eof.cpp
198 This is some kind of test of EOF ported from libevent.
201 /** @example test-weof.cpp
202 Another test of EOF ported from libevent.
205 /** @example trivial.cpp
206 This is the most trivial example.