xref: /libevent-2.1.12/whatsnew-2.1.txt (revision 227bfe56)
1819e98acSNick Mathewson                         What's new in Libevent 2.1
27ae08e50SNick Mathewson                             Nick Mathewson
3819e98acSNick Mathewson
4819e98acSNick Mathewson0. Before we start
5819e98acSNick Mathewson
6819e98acSNick Mathewson0.1. About this document
7819e98acSNick Mathewson
87ae08e50SNick Mathewson  This document describes the key differences between Libevent 2.0 and
97ae08e50SNick Mathewson  Libevent 2.1, from a user's point of view.  It's a work in progress.
10819e98acSNick Mathewson
11819e98acSNick Mathewson  For better documentation about libevent, see the links at
12819e98acSNick Mathewson  http://libevent.org/
13819e98acSNick Mathewson
147ae08e50SNick Mathewson  Libevent 2.1 would not be possible without the generous help of
157ae08e50SNick Mathewson  numerous volunteers.  For a list of who did what in Libevent 2.1,
167ae08e50SNick Mathewson  please see the ChangeLog!
177ae08e50SNick Mathewson
187ae08e50SNick Mathewson  NOTE: I am very sure that I missed some thing on this list.  Caveat
197ae08e50SNick Mathewson  haxxor.
20819e98acSNick Mathewson
21819e98acSNick Mathewson0.2. Where to get help
22819e98acSNick Mathewson
237ae08e50SNick Mathewson  Try looking at the other documentation too.  All of the header files
247ae08e50SNick Mathewson  have documentation in the doxygen format; this gets turned into nice
257ae08e50SNick Mathewson  HTML and linked to from the libevent.org website.
267ae08e50SNick Mathewson
277ae08e50SNick Mathewson  There is a work-in-progress book with reference manual at
287ae08e50SNick Mathewson  http://www.wangafu.net/~nickm/libevent-book/ .
297ae08e50SNick Mathewson
307ae08e50SNick Mathewson  You can ask questions on the #libevent IRC channel at irc.oftc.net or
317ae08e50SNick Mathewson  on the mailing list at [email protected].  The mailing list
327ae08e50SNick Mathewson  is subscribers-only, so you will need to subscribe before you post.
337ae08e50SNick Mathewson
347ae08e50SNick Mathewson0.3. Compatibility
357ae08e50SNick Mathewson
367ae08e50SNick Mathewson  Our source-compatibility policy is that correct code (that is to say,
377ae08e50SNick Mathewson  code that uses public interfaces of Libevent and relies only on their
387ae08e50SNick Mathewson  documented behavior) should have forward source compatibility: any
397ae08e50SNick Mathewson  such code that worked with a previous version of Libevent should work
407ae08e50SNick Mathewson  with this version too.
417ae08e50SNick Mathewson
427ae08e50SNick Mathewson  We don't try to do binary compatibility except within stable release
437ae08e50SNick Mathewson  series, so binaries linked against any version of Libevent 2.0 will
443b1b330dSNick Mathewson  probably need to be recompiled against Libevent 2.1.4-alpha if you
457ae08e50SNick Mathewson  want to use it.  It is probable that we'll break binary compatibility
467ae08e50SNick Mathewson  again before Libevent 2.1 is stable.
477ae08e50SNick Mathewson
487ae08e50SNick Mathewson1. New APIs and features
497ae08e50SNick Mathewson
507ae08e50SNick Mathewson1.1. New ways to build libevent
517ae08e50SNick Mathewson
527ae08e50SNick Mathewson  We now provide an --enable-gcc-hardening configure option to turn on
537ae08e50SNick Mathewson  GCC features designed for increased code security.
547ae08e50SNick Mathewson
557ae08e50SNick Mathewson  There is also an --enable-silent-rules configure option to make
567ae08e50SNick Mathewson  compilation run more quietly with automake 1.11 or later.
577ae08e50SNick Mathewson
587ae08e50SNick Mathewson  You no longer need to use the --enable-gcc-warnings option to turn on
597ae08e50SNick Mathewson  all of the GCC warnings that Libevent uses.  The only change from
607ae08e50SNick Mathewson  using that option now is to turn warnings into errors.
617ae08e50SNick Mathewson
627ae08e50SNick Mathewson  For IDE users, files that are not supposed to be built are now
637ae08e50SNick Mathewson  surrounded with appropriate #ifdef lines to keep your IDE from getting
647ae08e50SNick Mathewson  upset.
657ae08e50SNick Mathewson
663b1b330dSNick Mathewson  There is now an alternative cmake-based build process; cmake users
673b1b330dSNick Mathewson  should see the relevant sections in the README.
683b1b330dSNick Mathewson
697ae08e50SNick Mathewson
707ae08e50SNick Mathewson1.2. New functions for events and the event loop
717ae08e50SNick Mathewson
727ae08e50SNick Mathewson  If you're running Libevent with multiple event priorities, you might
737ae08e50SNick Mathewson  want to make sure that Libevent checks for new events frequently, so
747ae08e50SNick Mathewson  that time-consuming or numerous low-priority events don't keep it from
757ae08e50SNick Mathewson  checking for new high-priority events.  You can now use the
767ae08e50SNick Mathewson  event_config_set_max_dispatch_interval() interface to ensure that the
777ae08e50SNick Mathewson  loop checks for new events either every N microseconds, every M
787ae08e50SNick Mathewson  callbacks, or both.
797ae08e50SNick Mathewson
803db0737aSNick Mathewson  When configuring an event base, you can now choose whether you want
813db0737aSNick Mathewson  timers to be more efficient, or more precise.  (This only has effect
823db0737aSNick Mathewson  on Linux for now.)  Timers are efficient by default: to select more
833db0737aSNick Mathewson  precise timers, use the EVENT_BASE_FLAG_PRECISE_TIMER flag when
843db0737aSNick Mathewson  constructing the event_config, or set the EVENT_PRECISE_TIMER
853db0737aSNick Mathewson  environment variable to a non-empty string.
863db0737aSNick Mathewson
877ae08e50SNick Mathewson  There is an EVLOOP_NO_EXIT_ON_EMPTY flag that tells event_base_loop()
887ae08e50SNick Mathewson  to keep looping even when there are no pending events.  (Ordinarily,
897ae08e50SNick Mathewson  event_base_loop() will exit as soon as no events are pending.)
907ae08e50SNick Mathewson
917ae08e50SNick Mathewson  Past versions of Libevent have been annoying to use with some
927ae08e50SNick Mathewson  memory-leak-checking tools, because Libevent allocated some global
937ae08e50SNick Mathewson  singletons but provided no means to free them.  There is now a
947ae08e50SNick Mathewson  function, libevent_global_shutdown(), that you can use to free all
957ae08e50SNick Mathewson  globally held resources before exiting, so that your leak-check tools
967ae08e50SNick Mathewson  don't complain.  (Note: this function doesn't free non-global things
977ae08e50SNick Mathewson  like events, bufferevents, and so on; and it doesn't free anything
987ae08e50SNick Mathewson  that wouldn't otherwise get cleaned up by the operating system when
997ae08e50SNick Mathewson  your process exit()s.  If you aren't using a leak-checking tool, there
1007ae08e50SNick Mathewson  is not much reason to call libevent_global_shutdown().)
1017ae08e50SNick Mathewson
1027ae08e50SNick Mathewson  There is a new event_base_get_npriorities() function to return the
1037ae08e50SNick Mathewson  number of priorities set in the event base.
1047ae08e50SNick Mathewson
1057ae08e50SNick Mathewson  Libevent 2.0 added an event_new() function to construct a new struct
1067ae08e50SNick Mathewson  event on the heap.  Unfortunately, with event_new(), there was no
1077ae08e50SNick Mathewson  equivalent for:
1087ae08e50SNick Mathewson
1097ae08e50SNick Mathewson         struct event ev;
1107ae08e50SNick Mathewson         event_assign(&ev, base, fd, EV_READ, callback, &ev);
1117ae08e50SNick Mathewson
1127ae08e50SNick Mathewson  In other words, there was no easy way for event_new() to set up an
1137ae08e50SNick Mathewson  event so that the event itself would be its callback argument.
1147ae08e50SNick Mathewson  Libevent 2.1 lets you do this by passing "event_self_cbarg()" as the
1157ae08e50SNick Mathewson  callback argument:
1167ae08e50SNick Mathewson
1177ae08e50SNick Mathewson         struct event *evp;
1187ae08e50SNick Mathewson         evp = event_new(base, fd, EV_READ, callback,
1197ae08e50SNick Mathewson         event_self_cbarg());
1207ae08e50SNick Mathewson
12143d5389cSNick Mathewson  There's also a new event_base_get_running_event() function you can
12243d5389cSNick Mathewson  call from within a Libevent callback to get a pointer to the current
12343d5389cSNick Mathewson  event.  This should never be strictly necessary, but it's sometimes
12443d5389cSNick Mathewson  convenient.
12543d5389cSNick Mathewson
1263db0737aSNick Mathewson  The event_base_once() function used to leak some memory if the event
1273db0737aSNick Mathewson  that it added was never actually triggered.  Now, its memory is
1283db0737aSNick Mathewson  tracked in the event_base and freed when the event_base is freed.
1293db0737aSNick Mathewson  Note however that Libevent doesn't know how to free any information
1303db0737aSNick Mathewson  passed as the callback argument to event_base_once is still something
1313db0737aSNick Mathewson  you'll might need a way to de-allocate yourself.
1323db0737aSNick Mathewson
1333db0737aSNick Mathewson  There is an event_get_priority() function to return an event's
1343db0737aSNick Mathewson  priority.
1353db0737aSNick Mathewson
1363db0737aSNick Mathewson  By analogy to event_base_loopbreak(), there is now an
1373db0737aSNick Mathewson  event_base_loopcontinue() that tells Libevent to stop processing
1383db0737aSNick Mathewson  active event callbacks, and re-scan for new events right away.
1393db0737aSNick Mathewson
1403db0737aSNick Mathewson  There's a function, event_base_foreach_event(), that can iterate over
1413db0737aSNick Mathewson  every event currently pending or active on an event base, and invoke a
1423db0737aSNick Mathewson  user-supplied callback on each. The callback must not alter the events
1433db0737aSNick Mathewson  or add or remove anything to the event base.
1443db0737aSNick Mathewson
1453db0737aSNick Mathewson  We now have an event_remove_timer() function to remove the timeout on
1463db0737aSNick Mathewson  an event while leaving its socket and/or signal triggers unchanged.
1473db0737aSNick Mathewson  (If we were designing the API from scratch, this would be the behavior
1483db0737aSNick Mathewson  of "event_add(ev, NULL)" on an already-added event with a timeout. But
1493db0737aSNick Mathewson  that's a no-op in past versions of Libevent, and we don't want to
1503db0737aSNick Mathewson  break compatibility.)
1513db0737aSNick Mathewson
1523b1b330dSNick Mathewson  You can use the new event_base_get_num_events() function to find the
1533b1b330dSNick Mathewson  number of events active or pending on an event_base. To find the
1543b1b330dSNick Mathewson  largest number of events that there have been since the last call, use
1553b1b330dSNick Mathewson  event_base_get_max_events().
1563b1b330dSNick Mathewson
1573b1b330dSNick Mathewson  You can now activate all the events waiting for a given fd or signal
1583b1b330dSNick Mathewson  using the event_base_active_by_fd() and event_base_active_by_signal()
1593b1b330dSNick Mathewson  APIs.
1603b1b330dSNick Mathewson
1613b1b330dSNick Mathewson  On backends that support it (currently epoll), there is now an
1623b1b330dSNick Mathewson  EV_CLOSED flag that programs can use to detect when a socket has
1633b1b330dSNick Mathewson  closed without having to read all the bytes until receiving an EOF.
1643b1b330dSNick Mathewson
165e6cdd17bSNick Mathewson1.3. Event finalization
166e6cdd17bSNick Mathewson
167e6cdd17bSNick Mathewson1.3.1. Why event finalization?
168e6cdd17bSNick Mathewson
169e6cdd17bSNick Mathewson  Libevent 2.1 now supports an API for safely "finalizing" events that
170e6cdd17bSNick Mathewson  might be running in multiple threads, and provides a way to slightly
171e6cdd17bSNick Mathewson  change the semantics of event_del() to prevent deadlocks in
172e6cdd17bSNick Mathewson  multithreaded programs.
173e6cdd17bSNick Mathewson
174e6cdd17bSNick Mathewson  To motivate this feature, consider the following code, in the context
175e6cdd17bSNick Mathewson  of a mulithreaded Libevent application:
176e6cdd17bSNick Mathewson
177e6cdd17bSNick Mathewson        struct connection *conn = event_get_callback_arg(ev);
178e6cdd17bSNick Mathewson        event_del(ev);
179e6cdd17bSNick Mathewson        connection_free(conn);
180e6cdd17bSNick Mathewson
181e6cdd17bSNick Mathewson  Suppose that the event's callback might be running in another thread,
182e6cdd17bSNick Mathewson  and using the value of "conn" concurrently.  We wouldn't want to
183e6cdd17bSNick Mathewson  execute the connection_free() call until "conn" is no longer in use.
184e6cdd17bSNick Mathewson  How can we make this code safe?
185e6cdd17bSNick Mathewson
186e6cdd17bSNick Mathewson  Libevent 2.0 answered that question by saying that the event_del()
187e6cdd17bSNick Mathewson  call should block if the event's callback is running in another
188e6cdd17bSNick Mathewson  thread.  That way, we can be sure that event_del() has canceled the
189e6cdd17bSNick Mathewson  callback (if the callback hadn't started running yet), or has waited
190e6cdd17bSNick Mathewson  for the callback to finish.
191e6cdd17bSNick Mathewson
192e6cdd17bSNick Mathewson  But now suppose that the data structure is protected by a lock, and we
193e6cdd17bSNick Mathewson  have the following code:
194e6cdd17bSNick Mathewson
195e6cdd17bSNick Mathewson        void check_disable(struct connection *connection) {
196e6cdd17bSNick Mathewson            lock(connection);
197e6cdd17bSNick Mathewson            if (should_stop_reading(connection))
198e6cdd17bSNick Mathewson                    event_del(connection->read_event);
199e6cdd17bSNick Mathewson            unlock(connection);
200e6cdd17bSNick Mathewson        }
201e6cdd17bSNick Mathewson
202e6cdd17bSNick Mathewson  What happens when we call check_disable() from a callback and from
203e6cdd17bSNick Mathewson  another thread?  Let's say that the other thread gets the lock
204e6cdd17bSNick Mathewson  first.  If it decides to call event_del(), it will wait for the
205e6cdd17bSNick Mathewson  callback to finish.  But meanwhile, the callback will be waiting for
206e6cdd17bSNick Mathewson  the lock on the connection.  Since each threads is waiting for the
207e6cdd17bSNick Mathewson  other one to release a resource, the program will deadlock.
208e6cdd17bSNick Mathewson
209e6cdd17bSNick Mathewson  This bug showed up in multithreaded bufferevent programs in 2.1,
210e6cdd17bSNick Mathewson  particularly when freeing bufferevents.  (For more information, see
211e6cdd17bSNick Mathewson  the "Deadlock when calling bufferevent_free from an other thread"
212e6cdd17bSNick Mathewson  thread on libevent-users starting on 6 August 2012 and running through
213e6cdd17bSNick Mathewson  February of 2013.  You might also like to read my earlier writeup at
214e6cdd17bSNick Mathewson  http://archives.seul.org/libevent/users/Feb-2012/msg00053.html and
215e6cdd17bSNick Mathewson  the ensuing discussion.)
216e6cdd17bSNick Mathewson
217e6cdd17bSNick Mathewson1.3.2. The EV_FINALIZE flag and avoiding deadlock
218e6cdd17bSNick Mathewson
219e6cdd17bSNick Mathewson  To prevent the deadlock condition described above, Libevent
220e6cdd17bSNick Mathewson  2.1.3-alpha adds a new flag, "EV_FINALIZE".  You can pass it to
221e6cdd17bSNick Mathewson  event_new() and event_assign() along with EV_READ, EV_WRITE, and the
222e6cdd17bSNick Mathewson  other event flags.
223e6cdd17bSNick Mathewson
224e6cdd17bSNick Mathewson  When an event is constructed with the EV_FINALIZE flag, event_del()
225e6cdd17bSNick Mathewson  will not block on that event, even when the event's callback is
226e6cdd17bSNick Mathewson  running in another thread.  By using EV_FINALIZE, you are therefore
227e6cdd17bSNick Mathewson  promising not to use the "event_del(ev); free(event_get_callback_arg(ev));"
228e6cdd17bSNick Mathewson  pattern, but rather to use one of the finalization functions below to
229e6cdd17bSNick Mathewson  clean up the event.
230e6cdd17bSNick Mathewson
231e6cdd17bSNick Mathewson  EV_FINALIZE has no effect on a single-threaded program, or on a
232e6cdd17bSNick Mathewson  program where events are only used from one thread.
233e6cdd17bSNick Mathewson
234e6cdd17bSNick Mathewson
235e6cdd17bSNick Mathewson  There are also two new variants of event_del() that you can use for
236e6cdd17bSNick Mathewson  more fine-grained control:
237e6cdd17bSNick Mathewson     event_del_noblock(ev)
238e6cdd17bSNick Mathewson     event_del_block(ev)
239e6cdd17bSNick Mathewson  The event_del_noblock() function will never block, even if the event
240e6cdd17bSNick Mathewson  callback is running in another thread and doesn't have the EV_FINALIZE
241e6cdd17bSNick Mathewson  flag.  The event_del_block() function will _always_ block if the event
242e6cdd17bSNick Mathewson  callback is running in another thread, even if the event _does_ have
243e6cdd17bSNick Mathewson  the EV_FINALIZE flag.
244e6cdd17bSNick Mathewson
245e6cdd17bSNick Mathewson  [A future version of Libevent may have a way to make the EV_FINALIZE
246e6cdd17bSNick Mathewson  flag the default.]
247e6cdd17bSNick Mathewson
248e6cdd17bSNick Mathewson1.3.3. Safely finalizing events
249e6cdd17bSNick Mathewson
250e6cdd17bSNick Mathewson  To safely tear down an event that may be running, Libevent 2.1.3-alpha
251e6cdd17bSNick Mathewson  introduces event_finalize() and event_free_finalize(). You call them
252e6cdd17bSNick Mathewson  on an event, and provide a finalizer callback to be run on the event
253e6cdd17bSNick Mathewson  and its callback argument once the event is definitely no longer
254e6cdd17bSNick Mathewson  running.
255e6cdd17bSNick Mathewson
256e6cdd17bSNick Mathewson  With event_free_finalize(), the event is also freed once the finalizer
257e6cdd17bSNick Mathewson  callback has been invoked.
258e6cdd17bSNick Mathewson
259e6cdd17bSNick Mathewson  A finalized event cannot be re-added or activated.  The finalizer
260e6cdd17bSNick Mathewson  callback must not add events, activate events, or attempt to
261e6cdd17bSNick Mathewson  "resucitate" the event being finalized in any way.
262e6cdd17bSNick Mathewson
263e6cdd17bSNick Mathewson  If any finalizer callbacks are pending as the event_base is being
264e6cdd17bSNick Mathewson  freed, they will be invoked.  You can override this behavior with the
265e6cdd17bSNick Mathewson  new function event_base_free_nofinalize().
266e6cdd17bSNick Mathewson
267e6cdd17bSNick Mathewson1.4. New debugging features
2687ae08e50SNick Mathewson
2697ae08e50SNick Mathewson  You can now turn on debug logs at runtime using a new function,
2707ae08e50SNick Mathewson  event_enable_debug_logging().
2717ae08e50SNick Mathewson
2723db0737aSNick Mathewson  The event_enable_lock_debugging() function is now spelled correctly.
2733db0737aSNick Mathewson  You can still use the old "event_enable_lock_debuging" name, though,
2743db0737aSNick Mathewson  so your old programs shouldnt' break.
2753db0737aSNick Mathewson
2767ae08e50SNick Mathewson  There's also been some work done to try to make the debugging logs
2777ae08e50SNick Mathewson  more generally useful.
2787ae08e50SNick Mathewson
279e6cdd17bSNick Mathewson1.5. New evbuffer functions
2807ae08e50SNick Mathewson
2817ae08e50SNick Mathewson  In Libevent 2.0, we introduced evbuffer_add_file() to add an entire
2827ae08e50SNick Mathewson  file's contents to an evbuffer, and then send them using sendfile() or
2837ae08e50SNick Mathewson  mmap() as appropriate.  This API had some drawbacks, however.
2847ae08e50SNick Mathewson  Notably, it created one mapping or fd for every instance of the same
2857ae08e50SNick Mathewson  file added to any evbuffer.  Also, adding a file to an evbuffer could
2867ae08e50SNick Mathewson  make that buffer unusable with SSL bufferevents, filtering
2877ae08e50SNick Mathewson  bufferevents, and any code that tried to read the contents of the
2887ae08e50SNick Mathewson  evbuffer.
2897ae08e50SNick Mathewson
2907ae08e50SNick Mathewson  Libevent 2.1 adds a new evbuffer_file_segment API to solve these
2917ae08e50SNick Mathewson  problems.  Now, you can use evbuffer_file_segment_new() to construct a
2927ae08e50SNick Mathewson  file-segment object, and evbuffer_add_file_segment() to insert it (or
2937ae08e50SNick Mathewson  part of it) into an evbuffer.  These segments avoid creating redundant
2947ae08e50SNick Mathewson  maps or fds.  Better still, the code is smart enough (when the OS
2957ae08e50SNick Mathewson  supports sendfile) to map the file when that's necessary, and use
2967ae08e50SNick Mathewson  sendfile() otherwise.
2977ae08e50SNick Mathewson
2983db0737aSNick Mathewson  File segments can receive callback functions that are invoked when the
2993db0737aSNick Mathewson  file segments are freed.
3003db0737aSNick Mathewson
3017ae08e50SNick Mathewson  The evbuffer_ptr interface has been extended so that an evbuffer_ptr
3027ae08e50SNick Mathewson  can now yield a point just after the end of the buffer.  This makes
3037ae08e50SNick Mathewson  many algorithms simpler to implement.
3047ae08e50SNick Mathewson
3057ae08e50SNick Mathewson  There's a new evbuffer_add_buffer() interface that you can use to add
3067ae08e50SNick Mathewson  one buffer to another nondestructively.  When you say
3077ae08e50SNick Mathewson  evbuffer_add_buffer_reference(outbuf, inbuf), outbuf now contains a
3087ae08e50SNick Mathewson  reference to the contents of inbuf.
3097ae08e50SNick Mathewson
3107ae08e50SNick Mathewson  To aid in adding data in bulk while minimizing evbuffer calls, there
3117ae08e50SNick Mathewson  is an evbuffer_add_iovec() function.
3127ae08e50SNick Mathewson
3137ae08e50SNick Mathewson  There's a new evbuffer_copyout_from() variant function to enable
3147ae08e50SNick Mathewson  copying data nondestructively from the middle of a buffer.
3157ae08e50SNick Mathewson
3167ae08e50SNick Mathewson  evbuffer_readln() now supports an EVBUFFER_EOL_NUL argument to fetch
3177ae08e50SNick Mathewson  NUL-terminated strings from buffers.
3187ae08e50SNick Mathewson
319*227bfe56SAzat Khuzhin  There's a new evbuffer_set_flags()/evbuffer_clear_flags() that you can use to
320*227bfe56SAzat Khuzhin  set EVBUFFER_FLAG_DRAINS_TO_FD.
321*227bfe56SAzat Khuzhin
322e6cdd17bSNick Mathewson1.6. New functions and features: bufferevents
3237ae08e50SNick Mathewson
3247ae08e50SNick Mathewson  You can now use the bufferevent_getcb() function to find out a
3257ae08e50SNick Mathewson  bufferevent's callbacks.  Previously, there was no supported way to do
3267ae08e50SNick Mathewson  that.
3277ae08e50SNick Mathewson
3287ae08e50SNick Mathewson  The largest chunk readable or writeable in a single bufferevent
3297ae08e50SNick Mathewson  callback is no longer hardcoded; it's now configurable with
3307ae08e50SNick Mathewson  the new functions bufferevent_set_max_single_read() and
3317ae08e50SNick Mathewson  bufferevent_set_max_single_write().
3327ae08e50SNick Mathewson
3337ae08e50SNick Mathewson  For consistency, OpenSSL bufferevents now make sure to always set one
3343db0737aSNick Mathewson  of BEV_EVENT_READING or BEV_EVENT_WRITING when invoking an event
3353db0737aSNick Mathewson  callback.
3363db0737aSNick Mathewson
3373db0737aSNick Mathewson  Calling bufferevent_set_timeouts(bev, NULL, NULL) now removes the
3383db0737aSNick Mathewson  timeouts from socket and ssl bufferevents correctly.
3393db0737aSNick Mathewson
3403db0737aSNick Mathewson  You can find the priority at which a bufferevent runs with
3413db0737aSNick Mathewson  bufferevent_get_priority().
3427ae08e50SNick Mathewson
3433b1b330dSNick Mathewson  The function bufferevent_get_token_bucket_cfg() can retrieve the
3443b1b330dSNick Mathewson  rate-limit settings for a bufferevent; bufferevent_getwatermark() can
3453b1b330dSNick Mathewson  return a bufferevent's current watermark settings.
3463b1b330dSNick Mathewson
3473b1b330dSNick Mathewson  You can manually trigger a bufferevent's callbacks via
3483b1b330dSNick Mathewson  bufferevent_trigger() and bufferevent_trigger_event().
3493b1b330dSNick Mathewson
350*227bfe56SAzat Khuzhin  Also you can manually increment/decrement reference for bufferevent with
351*227bfe56SAzat Khuzhin  bufferevent_incref()/bufferevent_decref(), it is useful in situations where a
352*227bfe56SAzat Khuzhin  user may reference the bufferevent somewhere else.
353*227bfe56SAzat Khuzhin
354*227bfe56SAzat Khuzhin  Now bufferevent_openssl supports "dirty" shutdown (when the peer closes the
355*227bfe56SAzat Khuzhin  TCP connection before closing the SSL channel), see
356*227bfe56SAzat Khuzhin  bufferevent_openssl_get_allow_dirty_shutdown() and
357*227bfe56SAzat Khuzhin  bufferevent_openssl_set_allow_dirty_shutdown().
358*227bfe56SAzat Khuzhin
359*227bfe56SAzat Khuzhin  And also libevent supports openssl 1.1.
360*227bfe56SAzat Khuzhin
361e6cdd17bSNick Mathewson1.7. New functions and features: evdns
3627ae08e50SNick Mathewson
3637ae08e50SNick Mathewson  The previous evdns interface used an "open a test UDP socket" trick in
3647ae08e50SNick Mathewson  order to detect IPv6 support.  This was a hack, since it would
3657ae08e50SNick Mathewson  sometimes badly confuse people's firewall software, even though no
3667ae08e50SNick Mathewson  packets were sent.  The current evdns interface-detection code uses
3677ae08e50SNick Mathewson  the appropriate OS functions to see which interfaces are configured.
3687ae08e50SNick Mathewson
369e6cdd17bSNick Mathewson  The evdns_base_new() function now has multiple possible values for its
370e6cdd17bSNick Mathewson  second (flags) argument.  Using 1 and 0 have their old meanings, though the
371e6cdd17bSNick Mathewson  1 flag now has a symbolic name of EVDNS_BASE_INITIALIZE_NAMESERVERS.
372e6cdd17bSNick Mathewson  A second flag is now supported too: the EVDNS_BASE_DISABLE_WHEN_INACTIVE
373e6cdd17bSNick Mathewson  flag, which tells the evdns_base that it should not prevent Libevent from
374e6cdd17bSNick Mathewson  exiting while it has no DNS requests in progress.
375e6cdd17bSNick Mathewson
3763b1b330dSNick Mathewson  There is a new evdns_base_clear_host_addresses() function to remove
3773b1b330dSNick Mathewson  all the /etc/hosts addresses registered with an evdns instance.
3783b1b330dSNick Mathewson
379*227bfe56SAzat Khuzhin  Also there is evdns_base_get_nameserver_addr() for retrieve the address of
380*227bfe56SAzat Khuzhin  the 'idx'th configured nameserver.
381*227bfe56SAzat Khuzhin
382e6cdd17bSNick Mathewson1.8. New functions and features: evconnlistener
3837ae08e50SNick Mathewson
3847ae08e50SNick Mathewson  Libevent 2.1 adds the following evconnlistener flags:
3857ae08e50SNick Mathewson
3867ae08e50SNick Mathewson    LEV_OPT_DEFERRED_ACCEPT -- Tells the OS that it doesn't need to
3877ae08e50SNick Mathewson    report sockets as having arrived until the initiator has sent some
3887ae08e50SNick Mathewson    data too.  This can greatly improve performance with protocols like
3897ae08e50SNick Mathewson    HTTP where the client always speaks first.  On operating systems
3907ae08e50SNick Mathewson    that don't support this functionality, this option has no effect.
3917ae08e50SNick Mathewson
392*227bfe56SAzat Khuzhin    LEV_OPT_REUSEABLE_PORT -- Indicates that we ask to allow multiple servers
393*227bfe56SAzat Khuzhin    to bind to the same port if they each set the option Ionly on Linux and
394*227bfe56SAzat Khuzhin    >=3.9)
395*227bfe56SAzat Khuzhin
3967ae08e50SNick Mathewson    LEV_OPT_DISABLED -- Creates an evconnlistener in the disabled (not
3977ae08e50SNick Mathewson    listening) state.
3987ae08e50SNick Mathewson
3997ae08e50SNick Mathewson  Libevent 2.1 changes the behavior of the LEV_OPT_CLOSE_ON_EXEC
4007ae08e50SNick Mathewson  flag.  Previously, it would apply to the listener sockets, but not to
4017ae08e50SNick Mathewson  the accepted sockets themselves.  That's almost never what you want.
4027ae08e50SNick Mathewson  Now, it applies both to the listener and the accepted sockets.
4037ae08e50SNick Mathewson
404e6cdd17bSNick Mathewson1.9. New functions and features: evhttp
4057ae08e50SNick Mathewson
4067ae08e50SNick Mathewson  **********************************************************************
4077ae08e50SNick Mathewson  NOTE: The evhttp module will eventually be deprecated in favor of Mark
4087ae08e50SNick Mathewson  Ellzey's libevhtp library.  Don't worry -- this won't happen until
4097ae08e50SNick Mathewson  libevhtp provides every feature that evhttp does, and provides a
4107ae08e50SNick Mathewson  compatible interface that applications can use to migrate.
4117ae08e50SNick Mathewson  **********************************************************************
4127ae08e50SNick Mathewson
4137ae08e50SNick Mathewson  Previously, you could only set evhttp timeouts in increments of one
4147ae08e50SNick Mathewson  second.  Now, you can use evhttp_set_timeout_tv() and
4157ae08e50SNick Mathewson  evhttp_connection_set_timeout_tv() to configure
4167ae08e50SNick Mathewson  microsecond-granularity timeouts.
4177ae08e50SNick Mathewson
418*227bfe56SAzat Khuzhin  Also there is evhttp_connection_set_initial_retry_tv() to change initial
419*227bfe56SAzat Khuzhin  retry timeout.
420*227bfe56SAzat Khuzhin
4217ae08e50SNick Mathewson  There are a new pair of functions: evhttp_set_bevcb() and
4227ae08e50SNick Mathewson  evhttp_connection_base_bufferevent_new(), that you can use to
4237ae08e50SNick Mathewson  configure which bufferevents will be used for incoming and outgoing
4247ae08e50SNick Mathewson  http connections respectively.  These functions, combined with SSL
4257ae08e50SNick Mathewson  bufferevents, should enable HTTPS support.
4267ae08e50SNick Mathewson
4277ae08e50SNick Mathewson  There's a new evhttp_foreach_bound_socket() function to iterate over
4287ae08e50SNick Mathewson  every listener on an evhttp object.
4297ae08e50SNick Mathewson
4303db0737aSNick Mathewson  Whitespace between lines in headers is now folded into a single space;
4313db0737aSNick Mathewson  whitespace at the end of a header is now removed.
4323db0737aSNick Mathewson
4333db0737aSNick Mathewson  The socket errno value is now preserved when invoking an http error
4343db0737aSNick Mathewson  callback.
4353db0737aSNick Mathewson
436e6cdd17bSNick Mathewson  There's a new kind of request callback for errors; you can set it with
437e6cdd17bSNick Mathewson  evhttp_request_set_error_cb(). It gets called when there's a request error,
438e6cdd17bSNick Mathewson  and actually reports the error code and lets you figure out which request
439e6cdd17bSNick Mathewson  failed.
440e6cdd17bSNick Mathewson
4413b1b330dSNick Mathewson  You can navigate from an evhttp_connection back to its evhttp with the
4423b1b330dSNick Mathewson  new evhttp_connection_get_server() function.
4433b1b330dSNick Mathewson
4443b1b330dSNick Mathewson  You can override the default HTTP Content-Type with the new
4453b1b330dSNick Mathewson  evhttp_set_default_content_type() function
4463b1b330dSNick Mathewson
4473b1b330dSNick Mathewson  There's a new evhttp_connection_get_addr() API to return the peer
4483b1b330dSNick Mathewson  address of an evhttp_connection.
4493b1b330dSNick Mathewson
4503b1b330dSNick Mathewson  The new evhttp_send_reply_chunk_with_cb() is a variant of
4513b1b330dSNick Mathewson  evhttp_send_reply_chunk() with a callback to be invoked when the
4523b1b330dSNick Mathewson  chunk is sent.
4533b1b330dSNick Mathewson
4543b1b330dSNick Mathewson  The evhttp_request_set_header_cb() facility adds a callback to be
4553b1b330dSNick Mathewson  invoked while parsing headers.
4563b1b330dSNick Mathewson
4573b1b330dSNick Mathewson  The evhttp_request_set_on_complete_cb() facility adds a callback to be
4583b1b330dSNick Mathewson  invoked on request completion.
4593b1b330dSNick Mathewson
460*227bfe56SAzat Khuzhin  You can add linger-close for http server by passing
461*227bfe56SAzat Khuzhin  EVHTTP_SERVER_LINGERING_CLOSE to evhttp_set_flags(), with this flag server
462*227bfe56SAzat Khuzhin  read all the clients body, and only after this respond with an error if the
463*227bfe56SAzat Khuzhin  clients body exceed max_body_size (since some clients cannot read response
464*227bfe56SAzat Khuzhin  otherwise).
465*227bfe56SAzat Khuzhin
466*227bfe56SAzat Khuzhin  The evhttp_connection_set_family() can bypass family hint to evdns.
467*227bfe56SAzat Khuzhin
468*227bfe56SAzat Khuzhin  There are some flags available for connections, which can be installed with
469*227bfe56SAzat Khuzhin  evhttp_connection_set_flags():
470*227bfe56SAzat Khuzhin  - EVHTTP_CON_REUSE_CONNECTED_ADDR -- reuse connection address on retry (avoid
471*227bfe56SAzat Khuzhin    extra DNS request).
472*227bfe56SAzat Khuzhin  - EVHTTP_CON_READ_ON_WRITE_ERROR - try read error, since server may already
473*227bfe56SAzat Khuzhin    close the connection.
474*227bfe56SAzat Khuzhin
475*227bfe56SAzat Khuzhin  The evhttp_connection_free_on_completion() can be used to tell libevent to
476*227bfe56SAzat Khuzhin  free the connection object after the last request has completed or failed.
477*227bfe56SAzat Khuzhin
478*227bfe56SAzat Khuzhin  There is evhttp_request_get_response_code_line() if
479*227bfe56SAzat Khuzhin  evhttp_request_get_response_code() is not enough for you.
480*227bfe56SAzat Khuzhin
481*227bfe56SAzat Khuzhin  There are *evhttp_uri_parse_with_flags() that accepts
482*227bfe56SAzat Khuzhin  EVHTTP_URI_NONCONFORMANT to tolerate URIs that do not conform to RFC3986.
483*227bfe56SAzat Khuzhin  The evhttp_uri_set_flags() can changes the flags on URI.
484*227bfe56SAzat Khuzhin
4853b1b330dSNick Mathewson1.10. New functions and features: evutil
4863b1b330dSNick Mathewson
4873b1b330dSNick Mathewson  There's a function "evutil_secure_rng_set_urandom_device_file()" that
4883b1b330dSNick Mathewson  you can use to override the default file that Libevent uses to seed
4893b1b330dSNick Mathewson  its (sort-of) secure RNG.
4903b1b330dSNick Mathewson
491*227bfe56SAzat Khuzhin  The evutil_date_rfc1123() returns date in RFC1123
492*227bfe56SAzat Khuzhin
493*227bfe56SAzat Khuzhin  There are new API to work with monotonic timer -- monotonic time is
494*227bfe56SAzat Khuzhin  guaranteed never to run in reverse, but is not necessarily epoch-based. Use
495*227bfe56SAzat Khuzhin  it to make reliable measurements of elapsed time between events even when the
496*227bfe56SAzat Khuzhin  system time may be changed:
497*227bfe56SAzat Khuzhin  - evutil_monotonic_timer_new()/evutil_monotonic_timer_free()
498*227bfe56SAzat Khuzhin  - evutil_configure_monotonic_time()
499*227bfe56SAzat Khuzhin  - evutil_gettime_monotonic()
500*227bfe56SAzat Khuzhin
501*227bfe56SAzat Khuzhin  Use evutil_make_listen_socket_reuseable_port() to set SO_REUSEPORT (linux >=
502*227bfe56SAzat Khuzhin  3.9)
503*227bfe56SAzat Khuzhin
504*227bfe56SAzat Khuzhin  The evutil_make_tcp_listen_socket_deferred() can make a tcp listener socket
505*227bfe56SAzat Khuzhin  defer accept()s until there is data to read (TCP_DEFER_ACCEPT).
506*227bfe56SAzat Khuzhin
5077ae08e50SNick Mathewson2. Cross-platform performance improvements
5087ae08e50SNick Mathewson
5097ae08e50SNick Mathewson2.1. Better data structures
5107ae08e50SNick Mathewson
5117ae08e50SNick Mathewson  We replaced several users of the sys/queue.h "TAILQ" data structure
5127ae08e50SNick Mathewson  with the "LIST" data structure.  Because this data type doesn't
5137ae08e50SNick Mathewson  require FIFO access, it requires fewer pointer checks and
5147ae08e50SNick Mathewson  manipulations to keep it in line.
5157ae08e50SNick Mathewson
5167ae08e50SNick Mathewson  All previous versions of Libevent have kept every pending (added)
5177ae08e50SNick Mathewson  event in an "eventqueue" data structure.  Starting in Libevent 2.0,
5187ae08e50SNick Mathewson  however, this structure became redundant: every pending timeout event
5197ae08e50SNick Mathewson  is stored in the timeout heap or in one of the common_timeout queues,
5207ae08e50SNick Mathewson  and every pending fd or signal event is stored in an evmap.  Libevent
5217ae08e50SNick Mathewson  2.1 removes this data structure, and thereby saves all of the code
5227ae08e50SNick Mathewson  that we'd been using to keep it updated.
5237ae08e50SNick Mathewson
5247ae08e50SNick Mathewson2.2. Faster activations and timeouts
5257ae08e50SNick Mathewson
5267ae08e50SNick Mathewson  It's a common pattern in older code to use event_base_once() with a
5277ae08e50SNick Mathewson  0-second timeout to ensure that a callback will get run 'as soon as
5287ae08e50SNick Mathewson  possible' in the current iteration of the Libevent loop.  We optimize
5297ae08e50SNick Mathewson  this case by calling event_active() directly, and bypassing the
5307ae08e50SNick Mathewson  timeout pool.  (People who are using this pattern should also consider
5317ae08e50SNick Mathewson  using event_active() themselves.)
5327ae08e50SNick Mathewson
5337ae08e50SNick Mathewson  Libevent 2.0 would wake up a polling event loop whenever the first
5347ae08e50SNick Mathewson  timeout in the event loop was adjusted--whether it had become earlier
5357ae08e50SNick Mathewson  or later.  We now only notify the event loop when a change causes the
5367ae08e50SNick Mathewson  expiration time to become _sooner_ than it would have been otherwise.
5377ae08e50SNick Mathewson
5387ae08e50SNick Mathewson  The timeout heap code is now optimized to perform fewer comparisons
5397ae08e50SNick Mathewson  and shifts when changing or removing a timeout.
5407ae08e50SNick Mathewson
5417ae08e50SNick Mathewson  Instead of checking for a wall-clock time jump every time we call
5427ae08e50SNick Mathewson  clock_gettime(), we now check only every 5 seconds.  This should save
5437ae08e50SNick Mathewson  a huge number of gettimeofday() calls.
5447ae08e50SNick Mathewson
5457ae08e50SNick Mathewson2.3. Microoptimizations
5467ae08e50SNick Mathewson
5477ae08e50SNick Mathewson  Internal event list maintainance no longer use the antipattern where
5487ae08e50SNick Mathewson  we have one function with multiple totally independent behaviors
5497ae08e50SNick Mathewson  depending on an argument:
5507ae08e50SNick Mathewson      #define OP1 1
5517ae08e50SNick Mathewson      #define OP2 2
5527ae08e50SNick Mathewson      #define OP3 3
5537ae08e50SNick Mathewson      void func(int operation, struct event *ev) {
5547ae08e50SNick Mathewson        switch (op) {
5557ae08e50SNick Mathewson          ...
5567ae08e50SNick Mathewson        }
5577ae08e50SNick Mathewson      }
5587ae08e50SNick Mathewson  Instead, these functions are now split into separate functions for
5597ae08e50SNick Mathewson  each operation:
5607ae08e50SNick Mathewson      void func_op1(struct event *ev) { ... }
5617ae08e50SNick Mathewson      void func_op2(struct event *ev) { ... }
5627ae08e50SNick Mathewson      void func_op3(struct event *ev) { ... }
5637ae08e50SNick Mathewson
5647ae08e50SNick Mathewson  This produces better code generation and inlining decisions on some
5657ae08e50SNick Mathewson  compilers, and makes the code easier to read and check.
5667ae08e50SNick Mathewson
5677ae08e50SNick Mathewson2.4. Evbuffer performance improvements
5687ae08e50SNick Mathewson
5697ae08e50SNick Mathewson  The EVBUFFER_EOL_CRLF line-ending type is now much faster, thanks to
5707ae08e50SNick Mathewson  smart optimizations.
5717ae08e50SNick Mathewson
5727ae08e50SNick Mathewson2.5. HTTP performance improvements
5737ae08e50SNick Mathewson
5747ae08e50SNick Mathewson   o Performance tweak to evhttp_parse_request_line. (aee1a97 Mark Ellzey)
5757ae08e50SNick Mathewson   o Add missing break to evhttp_parse_request_line (0fcc536)
5767ae08e50SNick Mathewson
5773db0737aSNick Mathewson2.6. Coarse timers by default on Linux
5783db0737aSNick Mathewson
5793db0737aSNick Mathewson  Due to limitations of the epoll interface, Libevent programs using epoll
5803db0737aSNick Mathewson  have not previously been able to wait for timeouts with accuracy smaller
5813db0737aSNick Mathewson  than 1 millisecond.  But Libevent had been using CLOCK_MONOTONIC for
5823db0737aSNick Mathewson  timekeeping on Linux, which is needlessly expensive: CLOCK_MONOTONIC_COARSE
5833db0737aSNick Mathewson  has approximately the resolution corresponding to epoll, and is much faster
58449905ac3SNick Mathewson  to invoke than CLOCK_MONOTONIC.
5853db0737aSNick Mathewson
5863db0737aSNick Mathewson  To disable coarse timers, and get a more plausible precision, use the
5873db0737aSNick Mathewson  new EVENT_BASE_FLAG_PRECISE_TIMER flag when setting up your event base.
5887ae08e50SNick Mathewson
5897ae08e50SNick Mathewson3. Backend/OS-specific improvements
5907ae08e50SNick Mathewson
5917ae08e50SNick Mathewson3.1. Linux-specific improvements
5927ae08e50SNick Mathewson
5937ae08e50SNick Mathewson  The logic for deciding which arguements to use with epoll_ctl() is now
5947ae08e50SNick Mathewson  a table-driven lookup, rather than the previous pile of cascading
5957ae08e50SNick Mathewson  branches.  This should minimize epoll_ctl() calls and make the epoll
5967ae08e50SNick Mathewson  code run a little faster on change-heavy loads.
5977ae08e50SNick Mathewson
5987ae08e50SNick Mathewson  Libevent now takes advantage of Linux's support for enhanced APIs
5997ae08e50SNick Mathewson  (e.g., SOCK_CLOEXEC, SOCK_NONBLOCK, accept4, pipe2) that allow us to
6007ae08e50SNick Mathewson  simultaneously create a socket, make it nonblocking, and make it
6017ae08e50SNick Mathewson  close-on-exec.  This should save syscalls throughout our codebase, and
6027ae08e50SNick Mathewson  avoid race-conditions if an exec() occurs after a socket is socket is
6037ae08e50SNick Mathewson  created but before we can make it close-on-execute on it.
6047ae08e50SNick Mathewson
6057ae08e50SNick Mathewson3.2. Windows-specific improvements
6067ae08e50SNick Mathewson
6077ae08e50SNick Mathewson  We now use GetSystemTimeAsFileTime to implement gettimeofday.  It's
6087ae08e50SNick Mathewson  significantly faster and more accurate than our old ftime()-based approach.
6097ae08e50SNick Mathewson
6107ae08e50SNick Mathewson3.3. Improvements in the solaris evport backend.
6117ae08e50SNick Mathewson
6127ae08e50SNick Mathewson  The evport backend has been updated to use many of the infrastructure
6137ae08e50SNick Mathewson  improvements from Libevent 2.0.  Notably, it keeps track of per-fd
6147ae08e50SNick Mathewson  information using the evmap infrastructure, and removes a number of
6157ae08e50SNick Mathewson  linear scans over recently-added events.  This last change makes it
6167ae08e50SNick Mathewson  efficient to receive many more events per evport_getn() call, thereby
6177ae08e50SNick Mathewson  reducing evport overhead in general.
6187ae08e50SNick Mathewson
6197ae08e50SNick Mathewson3.4. OSX backend improvements
6207ae08e50SNick Mathewson
6217ae08e50SNick Mathewson  The OSX select backend doesn't like to have more than a certain number
6227ae08e50SNick Mathewson  of fds set unless an "unlimited select" option has been set.
6237ae08e50SNick Mathewson  Therefore, we now set it.
6247ae08e50SNick Mathewson
6253db0737aSNick Mathewson3.5. Monotonic clocks on even more platforms
6263db0737aSNick Mathewson
6273db0737aSNick Mathewson  Libevent previously used a monotonic clock for its internal timekeeping
6283db0737aSNick Mathewson  only on platforms supporting the POSIX clock_gettime() interface. Now,
6293db0737aSNick Mathewson  Libevent has support for monotonic clocks on OSX and Windows too, and a
6303db0737aSNick Mathewson  fallback implementation for systems without monotonic clocks that will at
6313db0737aSNick Mathewson  least keep time running forwards.
6323db0737aSNick Mathewson
6333db0737aSNick Mathewson  Using monotonic timers makes Libevent more resilient to changes in the
6343db0737aSNick Mathewson  system time, as can happen in small amounts due to clock adjustments from
6353db0737aSNick Mathewson  NTP, or in large amounts due to users who move their system clocks all over
6363db0737aSNick Mathewson  the timeline in order to keep nagware from nagging them.
6373db0737aSNick Mathewson
6383db0737aSNick Mathewson3.6. Faster cross-thread notification on kqueue
6393db0737aSNick Mathewson
6403db0737aSNick Mathewson  When a thread other than the one in which the main event loop is
6413db0737aSNick Mathewson  running needs to wake the thread running the main event loop, Libevent
6423db0737aSNick Mathewson  usually writes to a socketpair in order to force the main event loop
6433db0737aSNick Mathewson  to wake up.  On Linux, we've been able to use eventfd() instead.  Now
6443db0737aSNick Mathewson  on BSD and OSX systems (any anywhere else that has kqueue with the
6453db0737aSNick Mathewson  EVFILT_USER extension), we can use EVFILT_USER to wake up the main
6463db0737aSNick Mathewson  thread from kqueue.  This should be a tiny bit faster than the
6473db0737aSNick Mathewson  previous approach.
6483db0737aSNick Mathewson
6497ae08e50SNick Mathewson4. Infrastructure improvements
6507ae08e50SNick Mathewson
6517ae08e50SNick Mathewson4.1. Faster tests
6527ae08e50SNick Mathewson
6537ae08e50SNick Mathewson  I've spent some time to try to make the unit tests run faster in
6547ae08e50SNick Mathewson  Libevent 2.1.  Nearly all of this was a matter of searching slow tests
6557ae08e50SNick Mathewson  for unreasonably long timeouts, and cutting them down to reasonably
6567ae08e50SNick Mathewson  long delays, though on one or two cases I actually had to parallelize
6577ae08e50SNick Mathewson  an operation or improve an algorithm.
6587ae08e50SNick Mathewson
6597ae08e50SNick Mathewson  On my desktop, a full "make verify" run of Libevent 2.0.18-stable
6607ae08e50SNick Mathewson  requires about 218 seconds.  Libevent 2.1.1-alpha cuts this down to
6617ae08e50SNick Mathewson  about 78 seconds.
6627ae08e50SNick Mathewson
6637ae08e50SNick Mathewson  Faster unit tests are great, since they let programmers test their
6647ae08e50SNick Mathewson  changes without losing their train of thought.
6657ae08e50SNick Mathewson
6663db0737aSNick Mathewson4.2. Finicky tests are now off-by-default
6673db0737aSNick Mathewson
6683db0737aSNick Mathewson  The Tinytest unit testing framework now supports optional tests, and
6693db0737aSNick Mathewson  Libevent uses them.  By default, Libevent's unit testing framework
6703db0737aSNick Mathewson  does not run tests that require a working network, and does not run
6713db0737aSNick Mathewson  tests that tend to fail on heavily loaded systems because of timing
6723db0737aSNick Mathewson  issues.  To re-enable all tests, run ./test/regress using the "@all"
6733db0737aSNick Mathewson  alias.
6743db0737aSNick Mathewson
6753db0737aSNick Mathewson4.3. Modernized use of autotools
6763db0737aSNick Mathewson
6773db0737aSNick Mathewson  Our autotools-based build system has been updated to build without
6783db0737aSNick Mathewson  warnings on recent autoconf/automake versions.
6793db0737aSNick Mathewson
6803db0737aSNick Mathewson  Libevent's autotools makefiles are no longer recursive.  This allows
6813db0737aSNick Mathewson  make to use the maximum possible parallelism to do the minimally
6823db0737aSNick Mathewson  necessary amount of work.  See Peter Miller's "Recursive Make
6833db0737aSNick Mathewson  Considered Harmful" at http://miller.emu.id.au/pmiller/books/rmch/ for
6843db0737aSNick Mathewson  more information here.
6853db0737aSNick Mathewson
6863db0737aSNick Mathewson  We now use the "quiet build" option to suppress distracting messages
6873db0737aSNick Mathewson  about which commandlines are running.  You can get them back with
6883db0737aSNick Mathewson  "make V=1".
6893db0737aSNick Mathewson
6903db0737aSNick Mathewson4.4. Portability
6917ae08e50SNick Mathewson
6927ae08e50SNick Mathewson  Libevent now uses large-file support internally on platforms where it
6937ae08e50SNick Mathewson  matters.  You shouldn't need to set _LARGEFILE or OFFSET_BITS or
6947ae08e50SNick Mathewson  anything magic before including the Libevent headers, either, since
6957ae08e50SNick Mathewson  Libevent now sets the size of ev_off_t to the size of off_t that it
6967ae08e50SNick Mathewson  received at compile time, not to some (possibly different) size based
6977ae08e50SNick Mathewson  on current macro definitions when your program is building.
6987ae08e50SNick Mathewson
6997ae08e50SNick Mathewson  We now also use the Autoconf AC_USE_SYSTEM_EXTENSIONS mechanism to
7007ae08e50SNick Mathewson  enable per-system macros needed to enable not-on-by-default features.
7017ae08e50SNick Mathewson  Unlike the rest of the autoconf macros, we output these to an
7027ae08e50SNick Mathewson  internal-use-only evconfig-private.h header, since their names need to
7037ae08e50SNick Mathewson  survive unmangled.  This lets us build correctly on more platforms,
7047ae08e50SNick Mathewson  and avoid inconsistencies when some files define _GNU_SOURCE and
7057ae08e50SNick Mathewson  others don't.
7067ae08e50SNick Mathewson
7077ae08e50SNick Mathewson  Libevent now tries to detect OpenSSL via pkg-config.
7087ae08e50SNick Mathewson
7093db0737aSNick Mathewson4.5. Standards conformance
7107ae08e50SNick Mathewson
7117ae08e50SNick Mathewson  Previous Libevent versions had no consistent convention for internal
7127ae08e50SNick Mathewson  vs external identifiers, and used identifiers starting with the "_"
7137ae08e50SNick Mathewson  character throughout the codebase.  That's no good, since the C
7147ae08e50SNick Mathewson  standard says that identifiers beginning with _ are reserved.  I'm not
7157ae08e50SNick Mathewson  aware of having any collisions with system identifiers, but it's best
7167ae08e50SNick Mathewson  to fix these things before they cause trouble.
7177ae08e50SNick Mathewson
7187ae08e50SNick Mathewson  We now avoid all use of the _identifiers in the Libevent source code.
7197ae08e50SNick Mathewson  These changes were made *mainly* through the use of automated scripts,
7207ae08e50SNick Mathewson  so there shouldn't be any mistakes, but you never know.
7217ae08e50SNick Mathewson
7227ae08e50SNick Mathewson  As an exception, the names _EVENT_LOG_DEBUG, _EVENT_LOG_MSG_,
7237ae08e50SNick Mathewson  _EVENT_LOG_WARN, and _EVENT_LOG_ERR are still exposed in event.h: they
7247ae08e50SNick Mathewson  are now deprecated, but to support older code, they will need to stay
7257ae08e50SNick Mathewson  around for a while.  New code should use EVENT_LOG_DEBUG,
7267ae08e50SNick Mathewson  EVENT_LOG_MSG, EVENT_LOG_WARN, and EVENT_LOG_ERR instead.
7277ae08e50SNick Mathewson
7283db0737aSNick Mathewson4.6. Event and callback refactoring
7293db0737aSNick Mathewson
7303db0737aSNick Mathewson  As a simplification and optimization to Libevent's "deferred callback"
7313db0737aSNick Mathewson  logic (introduced in 2.0 to avoid callback recursion), Libevent now
7323db0737aSNick Mathewson  treats all of its deferrable callback types using the same logic it
7333db0737aSNick Mathewson  uses for active events.  Now deferred events no longer cause priority
7343db0737aSNick Mathewson  inversion, no longer require special code to cancel them, and so on.
7353db0737aSNick Mathewson
7363db0737aSNick Mathewson  Regular events and deferred callbacks now both descend from an
7373db0737aSNick Mathewson  internal light-weight event_callback supertype, and both support
7383db0737aSNick Mathewson  priorities and take part in the other anti-priority-inversion
7393db0737aSNick Mathewson  mechanisms in Libevent.
7403db0737aSNick Mathewson
7413db0737aSNick Mathewson  To avoid starvation from callback recursion (which was the reason we
7423db0737aSNick Mathewson  introduced "deferred callbacks" in the first place) the implementation
7433db0737aSNick Mathewson  now allows an event callback to be scheduled as "active later":
7443db0737aSNick Mathewson  instead of running in the current iteration of the event loop, it runs
7453db0737aSNick Mathewson  in the next one.
7463db0737aSNick Mathewson
7477ae08e50SNick Mathewson5. Testing
7487ae08e50SNick Mathewson
74909098f70SPatrick Pelletier  Libevent's test coverage level is more or less unchanged since before:
750*227bfe56SAzat Khuzhin  we still have over 80% line coverage in our tests on Linux, FreeBSD, NetBSD,
751*227bfe56SAzat Khuzhin  Windows, OSX.
75243d5389cSNick Mathewson  There are some under-tested modules, though: we need to fix those.
753*227bfe56SAzat Khuzhin
754*227bfe56SAzat Khuzhin  And now we have CI:
755*227bfe56SAzat Khuzhin  - https://travis-ci.org/libevent/libevent
756*227bfe56SAzat Khuzhin  - https://ci.appveyor.com/project/nmathewson/libevent
757*227bfe56SAzat Khuzhin
758*227bfe56SAzat Khuzhin  And code coverage:
759*227bfe56SAzat Khuzhin  - https://coveralls.io/github/libevent/libevent
760*227bfe56SAzat Khuzhin
761*227bfe56SAzat Khuzhin  Plus there is vagrant boxes if you what to test it on more OS'es then
762*227bfe56SAzat Khuzhin  travis-ci allows, and there is a wrapper (in python) that will parse logs and
763*227bfe56SAzat Khuzhin  provide report:
764*227bfe56SAzat Khuzhin  - https://github.com/libevent/libevent-extras/blob/master/tools/vagrant-tests.py
765*227bfe56SAzat Khuzhin
766*227bfe56SAzat Khuzhin6. Contributing
767*227bfe56SAzat Khuzhin
768*227bfe56SAzat Khuzhin  From now we have contributing guide and checkpatch.sh.
769