12b15cb3dSCy Schubert What's new in Libevent 2.1 22b15cb3dSCy Schubert Nick Mathewson 32b15cb3dSCy Schubert 42b15cb3dSCy Schubert0. Before we start 52b15cb3dSCy Schubert 62b15cb3dSCy Schubert0.1. About this document 72b15cb3dSCy Schubert 82b15cb3dSCy Schubert This document describes the key differences between Libevent 2.0 and 92b15cb3dSCy Schubert Libevent 2.1, from a user's point of view. It's a work in progress. 102b15cb3dSCy Schubert 112b15cb3dSCy Schubert For better documentation about libevent, see the links at 122b15cb3dSCy Schubert http://libevent.org/ 132b15cb3dSCy Schubert 142b15cb3dSCy Schubert Libevent 2.1 would not be possible without the generous help of 152b15cb3dSCy Schubert numerous volunteers. For a list of who did what in Libevent 2.1, 162b15cb3dSCy Schubert please see the ChangeLog! 172b15cb3dSCy Schubert 182b15cb3dSCy Schubert NOTE: I am very sure that I missed some thing on this list. Caveat 192b15cb3dSCy Schubert haxxor. 202b15cb3dSCy Schubert 212b15cb3dSCy Schubert0.2. Where to get help 222b15cb3dSCy Schubert 232b15cb3dSCy Schubert Try looking at the other documentation too. All of the header files 242b15cb3dSCy Schubert have documentation in the doxygen format; this gets turned into nice 252b15cb3dSCy Schubert HTML and linked to from the libevent.org website. 262b15cb3dSCy Schubert 272b15cb3dSCy Schubert There is a work-in-progress book with reference manual at 282b15cb3dSCy Schubert http://www.wangafu.net/~nickm/libevent-book/ . 292b15cb3dSCy Schubert 302b15cb3dSCy Schubert You can ask questions on the #libevent IRC channel at irc.oftc.net or 312b15cb3dSCy Schubert on the mailing list at libevent-users@freehaven.net. The mailing list 322b15cb3dSCy Schubert is subscribers-only, so you will need to subscribe before you post. 332b15cb3dSCy Schubert 342b15cb3dSCy Schubert0.3. Compatibility 352b15cb3dSCy Schubert 362b15cb3dSCy Schubert Our source-compatibility policy is that correct code (that is to say, 372b15cb3dSCy Schubert code that uses public interfaces of Libevent and relies only on their 382b15cb3dSCy Schubert documented behavior) should have forward source compatibility: any 392b15cb3dSCy Schubert such code that worked with a previous version of Libevent should work 402b15cb3dSCy Schubert with this version too. 412b15cb3dSCy Schubert 422b15cb3dSCy Schubert We don't try to do binary compatibility except within stable release 432b15cb3dSCy Schubert series, so binaries linked against any version of Libevent 2.0 will 44a25439b6SCy Schubert probably need to be recompiled against Libevent 2.1.4-alpha if you 452b15cb3dSCy Schubert want to use it. It is probable that we'll break binary compatibility 462b15cb3dSCy Schubert again before Libevent 2.1 is stable. 472b15cb3dSCy Schubert 482b15cb3dSCy Schubert1. New APIs and features 492b15cb3dSCy Schubert 502b15cb3dSCy Schubert1.1. New ways to build libevent 512b15cb3dSCy Schubert 522b15cb3dSCy Schubert We now provide an --enable-gcc-hardening configure option to turn on 532b15cb3dSCy Schubert GCC features designed for increased code security. 542b15cb3dSCy Schubert 552b15cb3dSCy Schubert There is also an --enable-silent-rules configure option to make 562b15cb3dSCy Schubert compilation run more quietly with automake 1.11 or later. 572b15cb3dSCy Schubert 582b15cb3dSCy Schubert You no longer need to use the --enable-gcc-warnings option to turn on 592b15cb3dSCy Schubert all of the GCC warnings that Libevent uses. The only change from 602b15cb3dSCy Schubert using that option now is to turn warnings into errors. 612b15cb3dSCy Schubert 622b15cb3dSCy Schubert For IDE users, files that are not supposed to be built are now 632b15cb3dSCy Schubert surrounded with appropriate #ifdef lines to keep your IDE from getting 642b15cb3dSCy Schubert upset. 652b15cb3dSCy Schubert 66a25439b6SCy Schubert There is now an alternative cmake-based build process; cmake users 67a25439b6SCy Schubert should see the relevant sections in the README. 68a25439b6SCy Schubert 692b15cb3dSCy Schubert 702b15cb3dSCy Schubert1.2. New functions for events and the event loop 712b15cb3dSCy Schubert 722b15cb3dSCy Schubert If you're running Libevent with multiple event priorities, you might 732b15cb3dSCy Schubert want to make sure that Libevent checks for new events frequently, so 742b15cb3dSCy Schubert that time-consuming or numerous low-priority events don't keep it from 752b15cb3dSCy Schubert checking for new high-priority events. You can now use the 762b15cb3dSCy Schubert event_config_set_max_dispatch_interval() interface to ensure that the 772b15cb3dSCy Schubert loop checks for new events either every N microseconds, every M 782b15cb3dSCy Schubert callbacks, or both. 792b15cb3dSCy Schubert 802b15cb3dSCy Schubert When configuring an event base, you can now choose whether you want 812b15cb3dSCy Schubert timers to be more efficient, or more precise. (This only has effect 822b15cb3dSCy Schubert on Linux for now.) Timers are efficient by default: to select more 832b15cb3dSCy Schubert precise timers, use the EVENT_BASE_FLAG_PRECISE_TIMER flag when 842b15cb3dSCy Schubert constructing the event_config, or set the EVENT_PRECISE_TIMER 852b15cb3dSCy Schubert environment variable to a non-empty string. 862b15cb3dSCy Schubert 872b15cb3dSCy Schubert There is an EVLOOP_NO_EXIT_ON_EMPTY flag that tells event_base_loop() 882b15cb3dSCy Schubert to keep looping even when there are no pending events. (Ordinarily, 892b15cb3dSCy Schubert event_base_loop() will exit as soon as no events are pending.) 902b15cb3dSCy Schubert 912b15cb3dSCy Schubert Past versions of Libevent have been annoying to use with some 922b15cb3dSCy Schubert memory-leak-checking tools, because Libevent allocated some global 932b15cb3dSCy Schubert singletons but provided no means to free them. There is now a 942b15cb3dSCy Schubert function, libevent_global_shutdown(), that you can use to free all 952b15cb3dSCy Schubert globally held resources before exiting, so that your leak-check tools 962b15cb3dSCy Schubert don't complain. (Note: this function doesn't free non-global things 972b15cb3dSCy Schubert like events, bufferevents, and so on; and it doesn't free anything 982b15cb3dSCy Schubert that wouldn't otherwise get cleaned up by the operating system when 992b15cb3dSCy Schubert your process exit()s. If you aren't using a leak-checking tool, there 1002b15cb3dSCy Schubert is not much reason to call libevent_global_shutdown().) 1012b15cb3dSCy Schubert 1022b15cb3dSCy Schubert There is a new event_base_get_npriorities() function to return the 1032b15cb3dSCy Schubert number of priorities set in the event base. 1042b15cb3dSCy Schubert 1052b15cb3dSCy Schubert Libevent 2.0 added an event_new() function to construct a new struct 1062b15cb3dSCy Schubert event on the heap. Unfortunately, with event_new(), there was no 1072b15cb3dSCy Schubert equivalent for: 1082b15cb3dSCy Schubert 1092b15cb3dSCy Schubert struct event ev; 1102b15cb3dSCy Schubert event_assign(&ev, base, fd, EV_READ, callback, &ev); 1112b15cb3dSCy Schubert 1122b15cb3dSCy Schubert In other words, there was no easy way for event_new() to set up an 1132b15cb3dSCy Schubert event so that the event itself would be its callback argument. 1142b15cb3dSCy Schubert Libevent 2.1 lets you do this by passing "event_self_cbarg()" as the 1152b15cb3dSCy Schubert callback argument: 1162b15cb3dSCy Schubert 1172b15cb3dSCy Schubert struct event *evp; 1182b15cb3dSCy Schubert evp = event_new(base, fd, EV_READ, callback, 1192b15cb3dSCy Schubert event_self_cbarg()); 1202b15cb3dSCy Schubert 1212b15cb3dSCy Schubert There's also a new event_base_get_running_event() function you can 1222b15cb3dSCy Schubert call from within a Libevent callback to get a pointer to the current 1232b15cb3dSCy Schubert event. This should never be strictly necessary, but it's sometimes 1242b15cb3dSCy Schubert convenient. 1252b15cb3dSCy Schubert 1262b15cb3dSCy Schubert The event_base_once() function used to leak some memory if the event 1272b15cb3dSCy Schubert that it added was never actually triggered. Now, its memory is 1282b15cb3dSCy Schubert tracked in the event_base and freed when the event_base is freed. 1292b15cb3dSCy Schubert Note however that Libevent doesn't know how to free any information 1302b15cb3dSCy Schubert passed as the callback argument to event_base_once is still something 1312b15cb3dSCy Schubert you'll might need a way to de-allocate yourself. 1322b15cb3dSCy Schubert 1332b15cb3dSCy Schubert There is an event_get_priority() function to return an event's 1342b15cb3dSCy Schubert priority. 1352b15cb3dSCy Schubert 1362b15cb3dSCy Schubert By analogy to event_base_loopbreak(), there is now an 1372b15cb3dSCy Schubert event_base_loopcontinue() that tells Libevent to stop processing 1382b15cb3dSCy Schubert active event callbacks, and re-scan for new events right away. 1392b15cb3dSCy Schubert 1402b15cb3dSCy Schubert There's a function, event_base_foreach_event(), that can iterate over 1412b15cb3dSCy Schubert every event currently pending or active on an event base, and invoke a 1422b15cb3dSCy Schubert user-supplied callback on each. The callback must not alter the events 1432b15cb3dSCy Schubert or add or remove anything to the event base. 1442b15cb3dSCy Schubert 1452b15cb3dSCy Schubert We now have an event_remove_timer() function to remove the timeout on 1462b15cb3dSCy Schubert an event while leaving its socket and/or signal triggers unchanged. 1472b15cb3dSCy Schubert (If we were designing the API from scratch, this would be the behavior 1482b15cb3dSCy Schubert of "event_add(ev, NULL)" on an already-added event with a timeout. But 1492b15cb3dSCy Schubert that's a no-op in past versions of Libevent, and we don't want to 1502b15cb3dSCy Schubert break compatibility.) 1512b15cb3dSCy Schubert 152a25439b6SCy Schubert You can use the new event_base_get_num_events() function to find the 153a25439b6SCy Schubert number of events active or pending on an event_base. To find the 154a25439b6SCy Schubert largest number of events that there have been since the last call, use 155a25439b6SCy Schubert event_base_get_max_events(). 156a25439b6SCy Schubert 157a25439b6SCy Schubert You can now activate all the events waiting for a given fd or signal 158a25439b6SCy Schubert using the event_base_active_by_fd() and event_base_active_by_signal() 159a25439b6SCy Schubert APIs. 160a25439b6SCy Schubert 161a25439b6SCy Schubert On backends that support it (currently epoll), there is now an 162a25439b6SCy Schubert EV_CLOSED flag that programs can use to detect when a socket has 163a25439b6SCy Schubert closed without having to read all the bytes until receiving an EOF. 164a25439b6SCy Schubert 1652b15cb3dSCy Schubert1.3. Event finalization 1662b15cb3dSCy Schubert 1672b15cb3dSCy Schubert1.3.1. Why event finalization? 1682b15cb3dSCy Schubert 1692b15cb3dSCy Schubert Libevent 2.1 now supports an API for safely "finalizing" events that 1702b15cb3dSCy Schubert might be running in multiple threads, and provides a way to slightly 1712b15cb3dSCy Schubert change the semantics of event_del() to prevent deadlocks in 1722b15cb3dSCy Schubert multithreaded programs. 1732b15cb3dSCy Schubert 1742b15cb3dSCy Schubert To motivate this feature, consider the following code, in the context 1752b15cb3dSCy Schubert of a mulithreaded Libevent application: 1762b15cb3dSCy Schubert 1772b15cb3dSCy Schubert struct connection *conn = event_get_callback_arg(ev); 1782b15cb3dSCy Schubert event_del(ev); 1792b15cb3dSCy Schubert connection_free(conn); 1802b15cb3dSCy Schubert 1812b15cb3dSCy Schubert Suppose that the event's callback might be running in another thread, 1822b15cb3dSCy Schubert and using the value of "conn" concurrently. We wouldn't want to 1832b15cb3dSCy Schubert execute the connection_free() call until "conn" is no longer in use. 1842b15cb3dSCy Schubert How can we make this code safe? 1852b15cb3dSCy Schubert 1862b15cb3dSCy Schubert Libevent 2.0 answered that question by saying that the event_del() 1872b15cb3dSCy Schubert call should block if the event's callback is running in another 1882b15cb3dSCy Schubert thread. That way, we can be sure that event_del() has canceled the 1892b15cb3dSCy Schubert callback (if the callback hadn't started running yet), or has waited 1902b15cb3dSCy Schubert for the callback to finish. 1912b15cb3dSCy Schubert 1922b15cb3dSCy Schubert But now suppose that the data structure is protected by a lock, and we 1932b15cb3dSCy Schubert have the following code: 1942b15cb3dSCy Schubert 1952b15cb3dSCy Schubert void check_disable(struct connection *connection) { 1962b15cb3dSCy Schubert lock(connection); 1972b15cb3dSCy Schubert if (should_stop_reading(connection)) 1982b15cb3dSCy Schubert event_del(connection->read_event); 1992b15cb3dSCy Schubert unlock(connection); 2002b15cb3dSCy Schubert } 2012b15cb3dSCy Schubert 2022b15cb3dSCy Schubert What happens when we call check_disable() from a callback and from 2032b15cb3dSCy Schubert another thread? Let's say that the other thread gets the lock 2042b15cb3dSCy Schubert first. If it decides to call event_del(), it will wait for the 2052b15cb3dSCy Schubert callback to finish. But meanwhile, the callback will be waiting for 2062b15cb3dSCy Schubert the lock on the connection. Since each threads is waiting for the 2072b15cb3dSCy Schubert other one to release a resource, the program will deadlock. 2082b15cb3dSCy Schubert 2092b15cb3dSCy Schubert This bug showed up in multithreaded bufferevent programs in 2.1, 2102b15cb3dSCy Schubert particularly when freeing bufferevents. (For more information, see 2112b15cb3dSCy Schubert the "Deadlock when calling bufferevent_free from an other thread" 2122b15cb3dSCy Schubert thread on libevent-users starting on 6 August 2012 and running through 2132b15cb3dSCy Schubert February of 2013. You might also like to read my earlier writeup at 2142b15cb3dSCy Schubert http://archives.seul.org/libevent/users/Feb-2012/msg00053.html and 2152b15cb3dSCy Schubert the ensuing discussion.) 2162b15cb3dSCy Schubert 2172b15cb3dSCy Schubert1.3.2. The EV_FINALIZE flag and avoiding deadlock 2182b15cb3dSCy Schubert 2192b15cb3dSCy Schubert To prevent the deadlock condition described above, Libevent 2202b15cb3dSCy Schubert 2.1.3-alpha adds a new flag, "EV_FINALIZE". You can pass it to 2212b15cb3dSCy Schubert event_new() and event_assign() along with EV_READ, EV_WRITE, and the 2222b15cb3dSCy Schubert other event flags. 2232b15cb3dSCy Schubert 2242b15cb3dSCy Schubert When an event is constructed with the EV_FINALIZE flag, event_del() 2252b15cb3dSCy Schubert will not block on that event, even when the event's callback is 2262b15cb3dSCy Schubert running in another thread. By using EV_FINALIZE, you are therefore 2272b15cb3dSCy Schubert promising not to use the "event_del(ev); free(event_get_callback_arg(ev));" 2282b15cb3dSCy Schubert pattern, but rather to use one of the finalization functions below to 2292b15cb3dSCy Schubert clean up the event. 2302b15cb3dSCy Schubert 2312b15cb3dSCy Schubert EV_FINALIZE has no effect on a single-threaded program, or on a 2322b15cb3dSCy Schubert program where events are only used from one thread. 2332b15cb3dSCy Schubert 2342b15cb3dSCy Schubert 2352b15cb3dSCy Schubert There are also two new variants of event_del() that you can use for 2362b15cb3dSCy Schubert more fine-grained control: 2372b15cb3dSCy Schubert event_del_noblock(ev) 2382b15cb3dSCy Schubert event_del_block(ev) 2392b15cb3dSCy Schubert The event_del_noblock() function will never block, even if the event 2402b15cb3dSCy Schubert callback is running in another thread and doesn't have the EV_FINALIZE 2412b15cb3dSCy Schubert flag. The event_del_block() function will _always_ block if the event 2422b15cb3dSCy Schubert callback is running in another thread, even if the event _does_ have 2432b15cb3dSCy Schubert the EV_FINALIZE flag. 2442b15cb3dSCy Schubert 2452b15cb3dSCy Schubert [A future version of Libevent may have a way to make the EV_FINALIZE 2462b15cb3dSCy Schubert flag the default.] 2472b15cb3dSCy Schubert 2482b15cb3dSCy Schubert1.3.3. Safely finalizing events 2492b15cb3dSCy Schubert 2502b15cb3dSCy Schubert To safely tear down an event that may be running, Libevent 2.1.3-alpha 2512b15cb3dSCy Schubert introduces event_finalize() and event_free_finalize(). You call them 2522b15cb3dSCy Schubert on an event, and provide a finalizer callback to be run on the event 2532b15cb3dSCy Schubert and its callback argument once the event is definitely no longer 2542b15cb3dSCy Schubert running. 2552b15cb3dSCy Schubert 2562b15cb3dSCy Schubert With event_free_finalize(), the event is also freed once the finalizer 2572b15cb3dSCy Schubert callback has been invoked. 2582b15cb3dSCy Schubert 2592b15cb3dSCy Schubert A finalized event cannot be re-added or activated. The finalizer 2602b15cb3dSCy Schubert callback must not add events, activate events, or attempt to 2612b15cb3dSCy Schubert "resucitate" the event being finalized in any way. 2622b15cb3dSCy Schubert 2632b15cb3dSCy Schubert If any finalizer callbacks are pending as the event_base is being 2642b15cb3dSCy Schubert freed, they will be invoked. You can override this behavior with the 2652b15cb3dSCy Schubert new function event_base_free_nofinalize(). 2662b15cb3dSCy Schubert 2672b15cb3dSCy Schubert1.4. New debugging features 2682b15cb3dSCy Schubert 2692b15cb3dSCy Schubert You can now turn on debug logs at runtime using a new function, 2702b15cb3dSCy Schubert event_enable_debug_logging(). 2712b15cb3dSCy Schubert 2722b15cb3dSCy Schubert The event_enable_lock_debugging() function is now spelled correctly. 2732b15cb3dSCy Schubert You can still use the old "event_enable_lock_debuging" name, though, 2742b15cb3dSCy Schubert so your old programs shouldnt' break. 2752b15cb3dSCy Schubert 2762b15cb3dSCy Schubert There's also been some work done to try to make the debugging logs 2772b15cb3dSCy Schubert more generally useful. 2782b15cb3dSCy Schubert 2792b15cb3dSCy Schubert1.5. New evbuffer functions 2802b15cb3dSCy Schubert 2812b15cb3dSCy Schubert In Libevent 2.0, we introduced evbuffer_add_file() to add an entire 2822b15cb3dSCy Schubert file's contents to an evbuffer, and then send them using sendfile() or 2832b15cb3dSCy Schubert mmap() as appropriate. This API had some drawbacks, however. 2842b15cb3dSCy Schubert Notably, it created one mapping or fd for every instance of the same 2852b15cb3dSCy Schubert file added to any evbuffer. Also, adding a file to an evbuffer could 2862b15cb3dSCy Schubert make that buffer unusable with SSL bufferevents, filtering 2872b15cb3dSCy Schubert bufferevents, and any code that tried to read the contents of the 2882b15cb3dSCy Schubert evbuffer. 2892b15cb3dSCy Schubert 2902b15cb3dSCy Schubert Libevent 2.1 adds a new evbuffer_file_segment API to solve these 2912b15cb3dSCy Schubert problems. Now, you can use evbuffer_file_segment_new() to construct a 2922b15cb3dSCy Schubert file-segment object, and evbuffer_add_file_segment() to insert it (or 2932b15cb3dSCy Schubert part of it) into an evbuffer. These segments avoid creating redundant 2942b15cb3dSCy Schubert maps or fds. Better still, the code is smart enough (when the OS 2952b15cb3dSCy Schubert supports sendfile) to map the file when that's necessary, and use 2962b15cb3dSCy Schubert sendfile() otherwise. 2972b15cb3dSCy Schubert 2982b15cb3dSCy Schubert File segments can receive callback functions that are invoked when the 2992b15cb3dSCy Schubert file segments are freed. 3002b15cb3dSCy Schubert 3012b15cb3dSCy Schubert The evbuffer_ptr interface has been extended so that an evbuffer_ptr 3022b15cb3dSCy Schubert can now yield a point just after the end of the buffer. This makes 3032b15cb3dSCy Schubert many algorithms simpler to implement. 3042b15cb3dSCy Schubert 3052b15cb3dSCy Schubert There's a new evbuffer_add_buffer() interface that you can use to add 3062b15cb3dSCy Schubert one buffer to another nondestructively. When you say 3072b15cb3dSCy Schubert evbuffer_add_buffer_reference(outbuf, inbuf), outbuf now contains a 3082b15cb3dSCy Schubert reference to the contents of inbuf. 3092b15cb3dSCy Schubert 3102b15cb3dSCy Schubert To aid in adding data in bulk while minimizing evbuffer calls, there 3112b15cb3dSCy Schubert is an evbuffer_add_iovec() function. 3122b15cb3dSCy Schubert 3132b15cb3dSCy Schubert There's a new evbuffer_copyout_from() variant function to enable 3142b15cb3dSCy Schubert copying data nondestructively from the middle of a buffer. 3152b15cb3dSCy Schubert 3162b15cb3dSCy Schubert evbuffer_readln() now supports an EVBUFFER_EOL_NUL argument to fetch 3172b15cb3dSCy Schubert NUL-terminated strings from buffers. 3182b15cb3dSCy Schubert 319*a466cc55SCy Schubert There's a new evbuffer_set_flags()/evbuffer_clear_flags() that you can use to 320*a466cc55SCy Schubert set EVBUFFER_FLAG_DRAINS_TO_FD. 321*a466cc55SCy Schubert 3222b15cb3dSCy Schubert1.6. New functions and features: bufferevents 3232b15cb3dSCy Schubert 3242b15cb3dSCy Schubert You can now use the bufferevent_getcb() function to find out a 3252b15cb3dSCy Schubert bufferevent's callbacks. Previously, there was no supported way to do 3262b15cb3dSCy Schubert that. 3272b15cb3dSCy Schubert 3282b15cb3dSCy Schubert The largest chunk readable or writeable in a single bufferevent 3292b15cb3dSCy Schubert callback is no longer hardcoded; it's now configurable with 3302b15cb3dSCy Schubert the new functions bufferevent_set_max_single_read() and 3312b15cb3dSCy Schubert bufferevent_set_max_single_write(). 3322b15cb3dSCy Schubert 3332b15cb3dSCy Schubert For consistency, OpenSSL bufferevents now make sure to always set one 3342b15cb3dSCy Schubert of BEV_EVENT_READING or BEV_EVENT_WRITING when invoking an event 3352b15cb3dSCy Schubert callback. 3362b15cb3dSCy Schubert 3372b15cb3dSCy Schubert Calling bufferevent_set_timeouts(bev, NULL, NULL) now removes the 3382b15cb3dSCy Schubert timeouts from socket and ssl bufferevents correctly. 3392b15cb3dSCy Schubert 3402b15cb3dSCy Schubert You can find the priority at which a bufferevent runs with 3412b15cb3dSCy Schubert bufferevent_get_priority(). 3422b15cb3dSCy Schubert 343a25439b6SCy Schubert The function bufferevent_get_token_bucket_cfg() can retrieve the 344a25439b6SCy Schubert rate-limit settings for a bufferevent; bufferevent_getwatermark() can 345a25439b6SCy Schubert return a bufferevent's current watermark settings. 346a25439b6SCy Schubert 347a25439b6SCy Schubert You can manually trigger a bufferevent's callbacks via 348a25439b6SCy Schubert bufferevent_trigger() and bufferevent_trigger_event(). 349a25439b6SCy Schubert 350*a466cc55SCy Schubert Also you can manually increment/decrement reference for bufferevent with 351*a466cc55SCy Schubert bufferevent_incref()/bufferevent_decref(), it is useful in situations where a 352*a466cc55SCy Schubert user may reference the bufferevent somewhere else. 353*a466cc55SCy Schubert 354*a466cc55SCy Schubert Now bufferevent_openssl supports "dirty" shutdown (when the peer closes the 355*a466cc55SCy Schubert TCP connection before closing the SSL channel), see 356*a466cc55SCy Schubert bufferevent_openssl_get_allow_dirty_shutdown() and 357*a466cc55SCy Schubert bufferevent_openssl_set_allow_dirty_shutdown(). 358*a466cc55SCy Schubert 359*a466cc55SCy Schubert And also libevent supports openssl 1.1. 360*a466cc55SCy Schubert 3612b15cb3dSCy Schubert1.7. New functions and features: evdns 3622b15cb3dSCy Schubert 3632b15cb3dSCy Schubert The previous evdns interface used an "open a test UDP socket" trick in 3642b15cb3dSCy Schubert order to detect IPv6 support. This was a hack, since it would 3652b15cb3dSCy Schubert sometimes badly confuse people's firewall software, even though no 3662b15cb3dSCy Schubert packets were sent. The current evdns interface-detection code uses 3672b15cb3dSCy Schubert the appropriate OS functions to see which interfaces are configured. 3682b15cb3dSCy Schubert 3692b15cb3dSCy Schubert The evdns_base_new() function now has multiple possible values for its 3702b15cb3dSCy Schubert second (flags) argument. Using 1 and 0 have their old meanings, though the 3712b15cb3dSCy Schubert 1 flag now has a symbolic name of EVDNS_BASE_INITIALIZE_NAMESERVERS. 3722b15cb3dSCy Schubert A second flag is now supported too: the EVDNS_BASE_DISABLE_WHEN_INACTIVE 3732b15cb3dSCy Schubert flag, which tells the evdns_base that it should not prevent Libevent from 3742b15cb3dSCy Schubert exiting while it has no DNS requests in progress. 3752b15cb3dSCy Schubert 376a25439b6SCy Schubert There is a new evdns_base_clear_host_addresses() function to remove 377a25439b6SCy Schubert all the /etc/hosts addresses registered with an evdns instance. 378a25439b6SCy Schubert 379*a466cc55SCy Schubert Also there is evdns_base_get_nameserver_addr() for retrieve the address of 380*a466cc55SCy Schubert the 'idx'th configured nameserver. 381*a466cc55SCy Schubert 3822b15cb3dSCy Schubert1.8. New functions and features: evconnlistener 3832b15cb3dSCy Schubert 3842b15cb3dSCy Schubert Libevent 2.1 adds the following evconnlistener flags: 3852b15cb3dSCy Schubert 3862b15cb3dSCy Schubert LEV_OPT_DEFERRED_ACCEPT -- Tells the OS that it doesn't need to 3872b15cb3dSCy Schubert report sockets as having arrived until the initiator has sent some 3882b15cb3dSCy Schubert data too. This can greatly improve performance with protocols like 3892b15cb3dSCy Schubert HTTP where the client always speaks first. On operating systems 3902b15cb3dSCy Schubert that don't support this functionality, this option has no effect. 3912b15cb3dSCy Schubert 392*a466cc55SCy Schubert LEV_OPT_REUSEABLE_PORT -- Indicates that we ask to allow multiple servers 393*a466cc55SCy Schubert to bind to the same port if they each set the option Ionly on Linux and 394*a466cc55SCy Schubert >=3.9) 395*a466cc55SCy Schubert 3962b15cb3dSCy Schubert LEV_OPT_DISABLED -- Creates an evconnlistener in the disabled (not 3972b15cb3dSCy Schubert listening) state. 3982b15cb3dSCy Schubert 3992b15cb3dSCy Schubert Libevent 2.1 changes the behavior of the LEV_OPT_CLOSE_ON_EXEC 4002b15cb3dSCy Schubert flag. Previously, it would apply to the listener sockets, but not to 4012b15cb3dSCy Schubert the accepted sockets themselves. That's almost never what you want. 4022b15cb3dSCy Schubert Now, it applies both to the listener and the accepted sockets. 4032b15cb3dSCy Schubert 4042b15cb3dSCy Schubert1.9. New functions and features: evhttp 4052b15cb3dSCy Schubert 4062b15cb3dSCy Schubert ********************************************************************** 4072b15cb3dSCy Schubert NOTE: The evhttp module will eventually be deprecated in favor of Mark 4082b15cb3dSCy Schubert Ellzey's libevhtp library. Don't worry -- this won't happen until 4092b15cb3dSCy Schubert libevhtp provides every feature that evhttp does, and provides a 4102b15cb3dSCy Schubert compatible interface that applications can use to migrate. 4112b15cb3dSCy Schubert ********************************************************************** 4122b15cb3dSCy Schubert 4132b15cb3dSCy Schubert Previously, you could only set evhttp timeouts in increments of one 4142b15cb3dSCy Schubert second. Now, you can use evhttp_set_timeout_tv() and 4152b15cb3dSCy Schubert evhttp_connection_set_timeout_tv() to configure 4162b15cb3dSCy Schubert microsecond-granularity timeouts. 4172b15cb3dSCy Schubert 418*a466cc55SCy Schubert Also there is evhttp_connection_set_initial_retry_tv() to change initial 419*a466cc55SCy Schubert retry timeout. 420*a466cc55SCy Schubert 4212b15cb3dSCy Schubert There are a new pair of functions: evhttp_set_bevcb() and 4222b15cb3dSCy Schubert evhttp_connection_base_bufferevent_new(), that you can use to 4232b15cb3dSCy Schubert configure which bufferevents will be used for incoming and outgoing 4242b15cb3dSCy Schubert http connections respectively. These functions, combined with SSL 4252b15cb3dSCy Schubert bufferevents, should enable HTTPS support. 4262b15cb3dSCy Schubert 4272b15cb3dSCy Schubert There's a new evhttp_foreach_bound_socket() function to iterate over 4282b15cb3dSCy Schubert every listener on an evhttp object. 4292b15cb3dSCy Schubert 4302b15cb3dSCy Schubert Whitespace between lines in headers is now folded into a single space; 4312b15cb3dSCy Schubert whitespace at the end of a header is now removed. 4322b15cb3dSCy Schubert 4332b15cb3dSCy Schubert The socket errno value is now preserved when invoking an http error 4342b15cb3dSCy Schubert callback. 4352b15cb3dSCy Schubert 4362b15cb3dSCy Schubert There's a new kind of request callback for errors; you can set it with 4372b15cb3dSCy Schubert evhttp_request_set_error_cb(). It gets called when there's a request error, 4382b15cb3dSCy Schubert and actually reports the error code and lets you figure out which request 4392b15cb3dSCy Schubert failed. 4402b15cb3dSCy Schubert 441a25439b6SCy Schubert You can navigate from an evhttp_connection back to its evhttp with the 442a25439b6SCy Schubert new evhttp_connection_get_server() function. 443a25439b6SCy Schubert 444a25439b6SCy Schubert You can override the default HTTP Content-Type with the new 445a25439b6SCy Schubert evhttp_set_default_content_type() function 446a25439b6SCy Schubert 447a25439b6SCy Schubert There's a new evhttp_connection_get_addr() API to return the peer 448a25439b6SCy Schubert address of an evhttp_connection. 449a25439b6SCy Schubert 450a25439b6SCy Schubert The new evhttp_send_reply_chunk_with_cb() is a variant of 451a25439b6SCy Schubert evhttp_send_reply_chunk() with a callback to be invoked when the 452a25439b6SCy Schubert chunk is sent. 453a25439b6SCy Schubert 454a25439b6SCy Schubert The evhttp_request_set_header_cb() facility adds a callback to be 455a25439b6SCy Schubert invoked while parsing headers. 456a25439b6SCy Schubert 457a25439b6SCy Schubert The evhttp_request_set_on_complete_cb() facility adds a callback to be 458a25439b6SCy Schubert invoked on request completion. 459a25439b6SCy Schubert 460*a466cc55SCy Schubert You can add linger-close for http server by passing 461*a466cc55SCy Schubert EVHTTP_SERVER_LINGERING_CLOSE to evhttp_set_flags(), with this flag server 462*a466cc55SCy Schubert read all the clients body, and only after this respond with an error if the 463*a466cc55SCy Schubert clients body exceed max_body_size (since some clients cannot read response 464*a466cc55SCy Schubert otherwise). 465*a466cc55SCy Schubert 466*a466cc55SCy Schubert The evhttp_connection_set_family() can bypass family hint to evdns. 467*a466cc55SCy Schubert 468*a466cc55SCy Schubert There are some flags available for connections, which can be installed with 469*a466cc55SCy Schubert evhttp_connection_set_flags(): 470*a466cc55SCy Schubert - EVHTTP_CON_REUSE_CONNECTED_ADDR -- reuse connection address on retry (avoid 471*a466cc55SCy Schubert extra DNS request). 472*a466cc55SCy Schubert - EVHTTP_CON_READ_ON_WRITE_ERROR - try read error, since server may already 473*a466cc55SCy Schubert close the connection. 474*a466cc55SCy Schubert 475*a466cc55SCy Schubert The evhttp_connection_free_on_completion() can be used to tell libevent to 476*a466cc55SCy Schubert free the connection object after the last request has completed or failed. 477*a466cc55SCy Schubert 478*a466cc55SCy Schubert There is evhttp_request_get_response_code_line() if 479*a466cc55SCy Schubert evhttp_request_get_response_code() is not enough for you. 480*a466cc55SCy Schubert 481*a466cc55SCy Schubert There are *evhttp_uri_parse_with_flags() that accepts 482*a466cc55SCy Schubert EVHTTP_URI_NONCONFORMANT to tolerate URIs that do not conform to RFC3986. 483*a466cc55SCy Schubert The evhttp_uri_set_flags() can changes the flags on URI. 484*a466cc55SCy Schubert 485a25439b6SCy Schubert1.10. New functions and features: evutil 486a25439b6SCy Schubert 487a25439b6SCy Schubert There's a function "evutil_secure_rng_set_urandom_device_file()" that 488a25439b6SCy Schubert you can use to override the default file that Libevent uses to seed 489a25439b6SCy Schubert its (sort-of) secure RNG. 490a25439b6SCy Schubert 491*a466cc55SCy Schubert The evutil_date_rfc1123() returns date in RFC1123 492*a466cc55SCy Schubert 493*a466cc55SCy Schubert There are new API to work with monotonic timer -- monotonic time is 494*a466cc55SCy Schubert guaranteed never to run in reverse, but is not necessarily epoch-based. Use 495*a466cc55SCy Schubert it to make reliable measurements of elapsed time between events even when the 496*a466cc55SCy Schubert system time may be changed: 497*a466cc55SCy Schubert - evutil_monotonic_timer_new()/evutil_monotonic_timer_free() 498*a466cc55SCy Schubert - evutil_configure_monotonic_time() 499*a466cc55SCy Schubert - evutil_gettime_monotonic() 500*a466cc55SCy Schubert 501*a466cc55SCy Schubert Use evutil_make_listen_socket_reuseable_port() to set SO_REUSEPORT (linux >= 502*a466cc55SCy Schubert 3.9) 503*a466cc55SCy Schubert 504*a466cc55SCy Schubert The evutil_make_tcp_listen_socket_deferred() can make a tcp listener socket 505*a466cc55SCy Schubert defer accept()s until there is data to read (TCP_DEFER_ACCEPT). 506*a466cc55SCy Schubert 5072b15cb3dSCy Schubert2. Cross-platform performance improvements 5082b15cb3dSCy Schubert 5092b15cb3dSCy Schubert2.1. Better data structures 5102b15cb3dSCy Schubert 5112b15cb3dSCy Schubert We replaced several users of the sys/queue.h "TAILQ" data structure 5122b15cb3dSCy Schubert with the "LIST" data structure. Because this data type doesn't 5132b15cb3dSCy Schubert require FIFO access, it requires fewer pointer checks and 5142b15cb3dSCy Schubert manipulations to keep it in line. 5152b15cb3dSCy Schubert 5162b15cb3dSCy Schubert All previous versions of Libevent have kept every pending (added) 5172b15cb3dSCy Schubert event in an "eventqueue" data structure. Starting in Libevent 2.0, 5182b15cb3dSCy Schubert however, this structure became redundant: every pending timeout event 5192b15cb3dSCy Schubert is stored in the timeout heap or in one of the common_timeout queues, 5202b15cb3dSCy Schubert and every pending fd or signal event is stored in an evmap. Libevent 5212b15cb3dSCy Schubert 2.1 removes this data structure, and thereby saves all of the code 5222b15cb3dSCy Schubert that we'd been using to keep it updated. 5232b15cb3dSCy Schubert 5242b15cb3dSCy Schubert2.2. Faster activations and timeouts 5252b15cb3dSCy Schubert 5262b15cb3dSCy Schubert It's a common pattern in older code to use event_base_once() with a 5272b15cb3dSCy Schubert 0-second timeout to ensure that a callback will get run 'as soon as 5282b15cb3dSCy Schubert possible' in the current iteration of the Libevent loop. We optimize 5292b15cb3dSCy Schubert this case by calling event_active() directly, and bypassing the 5302b15cb3dSCy Schubert timeout pool. (People who are using this pattern should also consider 5312b15cb3dSCy Schubert using event_active() themselves.) 5322b15cb3dSCy Schubert 5332b15cb3dSCy Schubert Libevent 2.0 would wake up a polling event loop whenever the first 5342b15cb3dSCy Schubert timeout in the event loop was adjusted--whether it had become earlier 5352b15cb3dSCy Schubert or later. We now only notify the event loop when a change causes the 5362b15cb3dSCy Schubert expiration time to become _sooner_ than it would have been otherwise. 5372b15cb3dSCy Schubert 5382b15cb3dSCy Schubert The timeout heap code is now optimized to perform fewer comparisons 5392b15cb3dSCy Schubert and shifts when changing or removing a timeout. 5402b15cb3dSCy Schubert 5412b15cb3dSCy Schubert Instead of checking for a wall-clock time jump every time we call 5422b15cb3dSCy Schubert clock_gettime(), we now check only every 5 seconds. This should save 5432b15cb3dSCy Schubert a huge number of gettimeofday() calls. 5442b15cb3dSCy Schubert 5452b15cb3dSCy Schubert2.3. Microoptimizations 5462b15cb3dSCy Schubert 5472b15cb3dSCy Schubert Internal event list maintainance no longer use the antipattern where 5482b15cb3dSCy Schubert we have one function with multiple totally independent behaviors 5492b15cb3dSCy Schubert depending on an argument: 5502b15cb3dSCy Schubert #define OP1 1 5512b15cb3dSCy Schubert #define OP2 2 5522b15cb3dSCy Schubert #define OP3 3 5532b15cb3dSCy Schubert void func(int operation, struct event *ev) { 5542b15cb3dSCy Schubert switch (op) { 5552b15cb3dSCy Schubert ... 5562b15cb3dSCy Schubert } 5572b15cb3dSCy Schubert } 5582b15cb3dSCy Schubert Instead, these functions are now split into separate functions for 5592b15cb3dSCy Schubert each operation: 5602b15cb3dSCy Schubert void func_op1(struct event *ev) { ... } 5612b15cb3dSCy Schubert void func_op2(struct event *ev) { ... } 5622b15cb3dSCy Schubert void func_op3(struct event *ev) { ... } 5632b15cb3dSCy Schubert 5642b15cb3dSCy Schubert This produces better code generation and inlining decisions on some 5652b15cb3dSCy Schubert compilers, and makes the code easier to read and check. 5662b15cb3dSCy Schubert 5672b15cb3dSCy Schubert2.4. Evbuffer performance improvements 5682b15cb3dSCy Schubert 5692b15cb3dSCy Schubert The EVBUFFER_EOL_CRLF line-ending type is now much faster, thanks to 5702b15cb3dSCy Schubert smart optimizations. 5712b15cb3dSCy Schubert 5722b15cb3dSCy Schubert2.5. HTTP performance improvements 5732b15cb3dSCy Schubert 5742b15cb3dSCy Schubert o Performance tweak to evhttp_parse_request_line. (aee1a97 Mark Ellzey) 5752b15cb3dSCy Schubert o Add missing break to evhttp_parse_request_line (0fcc536) 5762b15cb3dSCy Schubert 5772b15cb3dSCy Schubert2.6. Coarse timers by default on Linux 5782b15cb3dSCy Schubert 5792b15cb3dSCy Schubert Due to limitations of the epoll interface, Libevent programs using epoll 5802b15cb3dSCy Schubert have not previously been able to wait for timeouts with accuracy smaller 5812b15cb3dSCy Schubert than 1 millisecond. But Libevent had been using CLOCK_MONOTONIC for 5822b15cb3dSCy Schubert timekeeping on Linux, which is needlessly expensive: CLOCK_MONOTONIC_COARSE 5832b15cb3dSCy Schubert has approximately the resolution corresponding to epoll, and is much faster 5842b15cb3dSCy Schubert to invoke than CLOCK_MONOTONIC. 5852b15cb3dSCy Schubert 5862b15cb3dSCy Schubert To disable coarse timers, and get a more plausible precision, use the 5872b15cb3dSCy Schubert new EVENT_BASE_FLAG_PRECISE_TIMER flag when setting up your event base. 5882b15cb3dSCy Schubert 5892b15cb3dSCy Schubert3. Backend/OS-specific improvements 5902b15cb3dSCy Schubert 5912b15cb3dSCy Schubert3.1. Linux-specific improvements 5922b15cb3dSCy Schubert 5932b15cb3dSCy Schubert The logic for deciding which arguements to use with epoll_ctl() is now 5942b15cb3dSCy Schubert a table-driven lookup, rather than the previous pile of cascading 5952b15cb3dSCy Schubert branches. This should minimize epoll_ctl() calls and make the epoll 5962b15cb3dSCy Schubert code run a little faster on change-heavy loads. 5972b15cb3dSCy Schubert 5982b15cb3dSCy Schubert Libevent now takes advantage of Linux's support for enhanced APIs 5992b15cb3dSCy Schubert (e.g., SOCK_CLOEXEC, SOCK_NONBLOCK, accept4, pipe2) that allow us to 6002b15cb3dSCy Schubert simultaneously create a socket, make it nonblocking, and make it 6012b15cb3dSCy Schubert close-on-exec. This should save syscalls throughout our codebase, and 6022b15cb3dSCy Schubert avoid race-conditions if an exec() occurs after a socket is socket is 6032b15cb3dSCy Schubert created but before we can make it close-on-execute on it. 6042b15cb3dSCy Schubert 6052b15cb3dSCy Schubert3.2. Windows-specific improvements 6062b15cb3dSCy Schubert 6072b15cb3dSCy Schubert We now use GetSystemTimeAsFileTime to implement gettimeofday. It's 6082b15cb3dSCy Schubert significantly faster and more accurate than our old ftime()-based approach. 6092b15cb3dSCy Schubert 6102b15cb3dSCy Schubert3.3. Improvements in the solaris evport backend. 6112b15cb3dSCy Schubert 6122b15cb3dSCy Schubert The evport backend has been updated to use many of the infrastructure 6132b15cb3dSCy Schubert improvements from Libevent 2.0. Notably, it keeps track of per-fd 6142b15cb3dSCy Schubert information using the evmap infrastructure, and removes a number of 6152b15cb3dSCy Schubert linear scans over recently-added events. This last change makes it 6162b15cb3dSCy Schubert efficient to receive many more events per evport_getn() call, thereby 6172b15cb3dSCy Schubert reducing evport overhead in general. 6182b15cb3dSCy Schubert 6192b15cb3dSCy Schubert3.4. OSX backend improvements 6202b15cb3dSCy Schubert 6212b15cb3dSCy Schubert The OSX select backend doesn't like to have more than a certain number 6222b15cb3dSCy Schubert of fds set unless an "unlimited select" option has been set. 6232b15cb3dSCy Schubert Therefore, we now set it. 6242b15cb3dSCy Schubert 6252b15cb3dSCy Schubert3.5. Monotonic clocks on even more platforms 6262b15cb3dSCy Schubert 6272b15cb3dSCy Schubert Libevent previously used a monotonic clock for its internal timekeeping 6282b15cb3dSCy Schubert only on platforms supporting the POSIX clock_gettime() interface. Now, 6292b15cb3dSCy Schubert Libevent has support for monotonic clocks on OSX and Windows too, and a 6302b15cb3dSCy Schubert fallback implementation for systems without monotonic clocks that will at 6312b15cb3dSCy Schubert least keep time running forwards. 6322b15cb3dSCy Schubert 6332b15cb3dSCy Schubert Using monotonic timers makes Libevent more resilient to changes in the 6342b15cb3dSCy Schubert system time, as can happen in small amounts due to clock adjustments from 6352b15cb3dSCy Schubert NTP, or in large amounts due to users who move their system clocks all over 6362b15cb3dSCy Schubert the timeline in order to keep nagware from nagging them. 6372b15cb3dSCy Schubert 6382b15cb3dSCy Schubert3.6. Faster cross-thread notification on kqueue 6392b15cb3dSCy Schubert 6402b15cb3dSCy Schubert When a thread other than the one in which the main event loop is 6412b15cb3dSCy Schubert running needs to wake the thread running the main event loop, Libevent 6422b15cb3dSCy Schubert usually writes to a socketpair in order to force the main event loop 6432b15cb3dSCy Schubert to wake up. On Linux, we've been able to use eventfd() instead. Now 6442b15cb3dSCy Schubert on BSD and OSX systems (any anywhere else that has kqueue with the 6452b15cb3dSCy Schubert EVFILT_USER extension), we can use EVFILT_USER to wake up the main 6462b15cb3dSCy Schubert thread from kqueue. This should be a tiny bit faster than the 6472b15cb3dSCy Schubert previous approach. 6482b15cb3dSCy Schubert 6492b15cb3dSCy Schubert4. Infrastructure improvements 6502b15cb3dSCy Schubert 6512b15cb3dSCy Schubert4.1. Faster tests 6522b15cb3dSCy Schubert 6532b15cb3dSCy Schubert I've spent some time to try to make the unit tests run faster in 6542b15cb3dSCy Schubert Libevent 2.1. Nearly all of this was a matter of searching slow tests 6552b15cb3dSCy Schubert for unreasonably long timeouts, and cutting them down to reasonably 6562b15cb3dSCy Schubert long delays, though on one or two cases I actually had to parallelize 6572b15cb3dSCy Schubert an operation or improve an algorithm. 6582b15cb3dSCy Schubert 6592b15cb3dSCy Schubert On my desktop, a full "make verify" run of Libevent 2.0.18-stable 6602b15cb3dSCy Schubert requires about 218 seconds. Libevent 2.1.1-alpha cuts this down to 6612b15cb3dSCy Schubert about 78 seconds. 6622b15cb3dSCy Schubert 6632b15cb3dSCy Schubert Faster unit tests are great, since they let programmers test their 6642b15cb3dSCy Schubert changes without losing their train of thought. 6652b15cb3dSCy Schubert 6662b15cb3dSCy Schubert4.2. Finicky tests are now off-by-default 6672b15cb3dSCy Schubert 6682b15cb3dSCy Schubert The Tinytest unit testing framework now supports optional tests, and 6692b15cb3dSCy Schubert Libevent uses them. By default, Libevent's unit testing framework 6702b15cb3dSCy Schubert does not run tests that require a working network, and does not run 6712b15cb3dSCy Schubert tests that tend to fail on heavily loaded systems because of timing 6722b15cb3dSCy Schubert issues. To re-enable all tests, run ./test/regress using the "@all" 6732b15cb3dSCy Schubert alias. 6742b15cb3dSCy Schubert 6752b15cb3dSCy Schubert4.3. Modernized use of autotools 6762b15cb3dSCy Schubert 6772b15cb3dSCy Schubert Our autotools-based build system has been updated to build without 6782b15cb3dSCy Schubert warnings on recent autoconf/automake versions. 6792b15cb3dSCy Schubert 6802b15cb3dSCy Schubert Libevent's autotools makefiles are no longer recursive. This allows 6812b15cb3dSCy Schubert make to use the maximum possible parallelism to do the minimally 6822b15cb3dSCy Schubert necessary amount of work. See Peter Miller's "Recursive Make 6832b15cb3dSCy Schubert Considered Harmful" at http://miller.emu.id.au/pmiller/books/rmch/ for 6842b15cb3dSCy Schubert more information here. 6852b15cb3dSCy Schubert 6862b15cb3dSCy Schubert We now use the "quiet build" option to suppress distracting messages 6872b15cb3dSCy Schubert about which commandlines are running. You can get them back with 6882b15cb3dSCy Schubert "make V=1". 6892b15cb3dSCy Schubert 6902b15cb3dSCy Schubert4.4. Portability 6912b15cb3dSCy Schubert 6922b15cb3dSCy Schubert Libevent now uses large-file support internally on platforms where it 6932b15cb3dSCy Schubert matters. You shouldn't need to set _LARGEFILE or OFFSET_BITS or 6942b15cb3dSCy Schubert anything magic before including the Libevent headers, either, since 6952b15cb3dSCy Schubert Libevent now sets the size of ev_off_t to the size of off_t that it 6962b15cb3dSCy Schubert received at compile time, not to some (possibly different) size based 6972b15cb3dSCy Schubert on current macro definitions when your program is building. 6982b15cb3dSCy Schubert 6992b15cb3dSCy Schubert We now also use the Autoconf AC_USE_SYSTEM_EXTENSIONS mechanism to 7002b15cb3dSCy Schubert enable per-system macros needed to enable not-on-by-default features. 7012b15cb3dSCy Schubert Unlike the rest of the autoconf macros, we output these to an 7022b15cb3dSCy Schubert internal-use-only evconfig-private.h header, since their names need to 7032b15cb3dSCy Schubert survive unmangled. This lets us build correctly on more platforms, 7042b15cb3dSCy Schubert and avoid inconsistencies when some files define _GNU_SOURCE and 7052b15cb3dSCy Schubert others don't. 7062b15cb3dSCy Schubert 7072b15cb3dSCy Schubert Libevent now tries to detect OpenSSL via pkg-config. 7082b15cb3dSCy Schubert 7092b15cb3dSCy Schubert4.5. Standards conformance 7102b15cb3dSCy Schubert 7112b15cb3dSCy Schubert Previous Libevent versions had no consistent convention for internal 7122b15cb3dSCy Schubert vs external identifiers, and used identifiers starting with the "_" 7132b15cb3dSCy Schubert character throughout the codebase. That's no good, since the C 7142b15cb3dSCy Schubert standard says that identifiers beginning with _ are reserved. I'm not 7152b15cb3dSCy Schubert aware of having any collisions with system identifiers, but it's best 7162b15cb3dSCy Schubert to fix these things before they cause trouble. 7172b15cb3dSCy Schubert 7182b15cb3dSCy Schubert We now avoid all use of the _identifiers in the Libevent source code. 7192b15cb3dSCy Schubert These changes were made *mainly* through the use of automated scripts, 7202b15cb3dSCy Schubert so there shouldn't be any mistakes, but you never know. 7212b15cb3dSCy Schubert 7222b15cb3dSCy Schubert As an exception, the names _EVENT_LOG_DEBUG, _EVENT_LOG_MSG_, 7232b15cb3dSCy Schubert _EVENT_LOG_WARN, and _EVENT_LOG_ERR are still exposed in event.h: they 7242b15cb3dSCy Schubert are now deprecated, but to support older code, they will need to stay 7252b15cb3dSCy Schubert around for a while. New code should use EVENT_LOG_DEBUG, 7262b15cb3dSCy Schubert EVENT_LOG_MSG, EVENT_LOG_WARN, and EVENT_LOG_ERR instead. 7272b15cb3dSCy Schubert 7282b15cb3dSCy Schubert4.6. Event and callback refactoring 7292b15cb3dSCy Schubert 7302b15cb3dSCy Schubert As a simplification and optimization to Libevent's "deferred callback" 7312b15cb3dSCy Schubert logic (introduced in 2.0 to avoid callback recursion), Libevent now 7322b15cb3dSCy Schubert treats all of its deferrable callback types using the same logic it 7332b15cb3dSCy Schubert uses for active events. Now deferred events no longer cause priority 7342b15cb3dSCy Schubert inversion, no longer require special code to cancel them, and so on. 7352b15cb3dSCy Schubert 7362b15cb3dSCy Schubert Regular events and deferred callbacks now both descend from an 7372b15cb3dSCy Schubert internal light-weight event_callback supertype, and both support 7382b15cb3dSCy Schubert priorities and take part in the other anti-priority-inversion 7392b15cb3dSCy Schubert mechanisms in Libevent. 7402b15cb3dSCy Schubert 7412b15cb3dSCy Schubert To avoid starvation from callback recursion (which was the reason we 7422b15cb3dSCy Schubert introduced "deferred callbacks" in the first place) the implementation 7432b15cb3dSCy Schubert now allows an event callback to be scheduled as "active later": 7442b15cb3dSCy Schubert instead of running in the current iteration of the event loop, it runs 7452b15cb3dSCy Schubert in the next one. 7462b15cb3dSCy Schubert 7472b15cb3dSCy Schubert5. Testing 7482b15cb3dSCy Schubert 7492b15cb3dSCy Schubert Libevent's test coverage level is more or less unchanged since before: 750*a466cc55SCy Schubert we still have over 80% line coverage in our tests on Linux, FreeBSD, NetBSD, 751*a466cc55SCy Schubert Windows, OSX. 7522b15cb3dSCy Schubert There are some under-tested modules, though: we need to fix those. 753*a466cc55SCy Schubert 754*a466cc55SCy Schubert And now we have CI: 755*a466cc55SCy Schubert - https://travis-ci.org/libevent/libevent 756*a466cc55SCy Schubert - https://ci.appveyor.com/project/nmathewson/libevent 757*a466cc55SCy Schubert 758*a466cc55SCy Schubert And code coverage: 759*a466cc55SCy Schubert - https://coveralls.io/github/libevent/libevent 760*a466cc55SCy Schubert 761*a466cc55SCy Schubert Plus there is vagrant boxes if you what to test it on more OS'es then 762*a466cc55SCy Schubert travis-ci allows, and there is a wrapper (in python) that will parse logs and 763*a466cc55SCy Schubert provide report: 764*a466cc55SCy Schubert - https://github.com/libevent/libevent-extras/blob/master/tools/vagrant-tests.py 765*a466cc55SCy Schubert 766*a466cc55SCy Schubert6. Contributing 767*a466cc55SCy Schubert 768*a466cc55SCy Schubert From now we have contributing guide and checkpatch.sh. 769