event.c


Log

Author Commit Date CI Message
Nick Mathewson c16e6844 2010-05-04T13:27:36 Rename current_base symbol to event_global_current_base_ The "current_base" symbol was never actually declared in an exported header; it's hideously deprecated, and it was the one remaining exported symbol (fwict) that was prefixed with neither ev nor bufferevent nor _ev nor _bufferevent. codesearch.google.com turns up no actual attempts to use our current_base from outside libevent.
Nick Mathewson 99e50e90 2010-05-04T12:57:40 Fix symbol conflict between mm_*() macros and libmm Our mm_malloc, mm_calloc, etc functions were all exported, since C hasn't got a nice portable way to say "we want to use this function inside our library but not export it to others". But they apparently conflict with anything else that calls its symbols mm_*, as libmm does. This patch renames the mm_*() functions to event_mm_*_(, and defines maros in mm_internal so that all the code we have that uses mm_*() will still work. New code should also prefer the mm_*() macro names. Reported by Gernot Tenchio. Fixes sf bug 2996541
Frank Denis 71afc525 2010-05-03T11:37:16 Fix nonstandard TAILQ_FOREACH_REVERSE() definition Every current BSD system providing TAILQ_* macros define TAILQ_FOREACH_REVERSE in this order: TAILQ_FOREACH_REVERSE(var, head, field, headname) However, libevent defines it in another order: TAILQ_FOREACH_REVERSE(var, head, headname, field) Here's a trivial patch to have libevent compatible with stock queue.h headers. -Frank. [From sourceforge patch 2995179. codesearch.google.com confirms that the only people defining TAILQ_FOREACH_REVERSE our way are people using it in a compatibility header like us. Did we copy this from OpenSSH or something?] -Nick
Nick Mathewson 9ecf0d48 2010-04-28T12:03:08 Catch attempts to enable debug_mode too late Debug mode needs to be enabled before any event is setup or any event_base is created. Otherwise, we will not have recorded when events were first setup or added, and so it will look like a bug later when we delete or free them. I have already confused myself because of this requirement, so let's make Libevent catch it for the next poor forgetful developer like me.
Nick Mathewson 06a4443a 2010-04-09T15:28:26 Unit-test every evbuffer_add_file() implementation. Previously, we'd only test the default one, even if the others were still compiled in.
Nick Mathewson b557b175 2010-03-21T13:28:48 Detect and refuse reentrant event_base_loop() calls Calling event_base_loop on a base from inside a callback invoked by that same base, or from two threads at once, has long been a way to get exceedingly hard-to-diagnose errors. This patch adds code to detect such reentrant invocatinos, and exit quickly with a warning that should explain what went wrong.
Nick Mathewson 70a44b61 2010-03-12T18:35:15 Avoid a spurious close(-1) on Linux On Linux, we use only one fd to do main-thread signaling (since we have eventfd()), so we don't need to close th_notify_fd[1] as we would if we were using a socketpair.
Nick Mathewson cdd4c490 2010-03-11T00:38:46 Try to comment some of the event code more
Nick Mathewson 2c2618d8 2010-03-05T13:00:15 more whitespace normalization
Nick Mathewson c7cf6f00 2010-03-05T12:47:46 Replace users of "int fd" with "evutil_socket_t fd" in portable code Remeber, win32 has a socket type that's actually a handle, so if there's a chance that code is run on win32, we can't use "int" as the socket type. This isn't a blind search-and-replace: sometimes an fd is really in fact for a file, and not a socket at all.
Nick Mathewson 17efc1cd 2010-03-04T01:25:51 Update all our copyright notices to say "2010"
Nick Mathewson ad85908a 2010-02-28T12:52:39 Fix compilation with --disable-debug-mode
Nick Mathewson 38ec0a77 2010-02-23T14:24:10 Fix a bug in resetting timeouts on persistent events when IO triggers. When we fixed persistent timeouts to make them reset themselves based on the previous scheduled time rather than the current time... we made them do so regardless of whether the event was triggering because of a timeout or not! This was of course bogus. When a _timeout_ triggers, we should schedule the event for N seconds based on the last _schedule_ time... but when IO triggers, we should reset the timeout for N seconds after now.
Nick Mathewson e2642f0a 2010-02-23T15:14:57 Fix some race conditions in persistent events and event_reinit I found these by adding an EVENT_BASE_ASSERT_LOCKED() call to most of the functions in event.c that can only be called while holding the lock. event_reinit() never grabbed the lock, but it needed to. event_persist_closure accessed the base to call event_add_internal() and gettime() when its caller had already dropped the lock. event_pending() called gettime() without grabbing the lock.
Nick Mathewson e5cf9879 2010-02-18T17:46:56 Clean up formatting: remove trailing spaces
Nick Mathewson e5bbd40a 2010-02-18T17:41:15 Clean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson 8fdf09c0 2010-02-18T17:08:50 Clean up formatting: Disallow space-before-tab.
Nick Mathewson d38a7a19 2010-02-02T15:44:10 const-ify a few more functions in event.h
Nick Mathewson 137f2c60 2010-01-26T12:08:34 Try to fix a warning in hash_debug_entry Apparently some 64-bit platforms don't like it when you say unsigned hash(void *p) { return (unsigned)p; } even if you really honestly don't want the high bits of p. Perhaps they will tolerate it if I say the equivalent of unsigned hash(void *p) { return (unsigned) (uintptr_t) p; }
Nick Mathewson a66e947b 2010-01-25T13:44:56 Use less memory for each entry in a hashtable Our hash-table implementation stored a copy of the hash code in each element. But as we were using it, all of our hash codes were ridiculously easy to calculate: most of them were just a matter of a load and a shift. This patch lets ht-internal be built in either of two ways: one caches the hash-code for each element, and one recalculates it each time it's needed. This patch also chooses a slightly better hash code for event_debug_entry.
Nick Mathewson a19b4a05 2010-01-25T13:38:07 Call event_debug_unassign on internal events I don't expect that many users will be so religious about calling unassign, but we need to be so that it's at least possible to use debug mode without eating memory.
Nick Mathewson cd17c3ac 2010-01-22T00:34:37 Add support for a "debug mode" to try to catch common errors. Right now it only catches cases where we aren't initializing events, or where we are re-initializing events without deleting them first. These are however shockingly common.
Nick Mathewson 06839503 2010-01-19T14:01:36 Functions to access more fields of struct event. Once event_assign() or event_new() had been called, there was no way to get at a copy of the event's callback, callback argument, or configured events. This patch adds an accessor function for each, and an all-fields accessor for code that wants to re-assign one field of an event. This patch also adds a function to return sizeof(struct event), so that code with intense RAM needs can still retain ABI compatibility between versions of Libevent without having to heap-allocate every struct event individually. The code here was first proposed by Pavel Pisa.
Nick Mathewson 27308aae 2010-01-14T16:30:40 Changelist code to defer event changes until just before dispatch This is necessary or useful for a few reasons: 1) Sometimes applications will add and delete the same event more than once between calls to dispatch. Processing these changes immediately is needless, and potentially expensive (especially if we're on a system that makes one syscall per changed event). Yes, this actually happens in practice for nonpathological code, such as in cases where the user's callback conditionally re-adds a non-persistent event, or where draining a buffer turns off writing and invokes a user callback which adds more data which in turn re-enabled writing. 2) Sometimes we can coalesce multiple changes on the same fd into a single syscall if we know about them in advance. For example, epoll can do an add and a delete at the same time, but only if we have found out about both of them before we tell epoll. 3) Sometimes adding an event that we immediately delete can cause unintended consequences: in kqueue, this makes pending events get reported spuriously.
Nick Mathewson 47854a80 2009-12-28T01:40:37 Expose our cached gettimeofday value with a new interface I've got a two use case that wants this for a fairly sensible purpose: one external and on internal.
Nick Mathewson da1718b2 2009-11-27T16:00:59 Fix a locking bug in event_base_loop() We previously were releasing the lock when we exited the main loop in some ways, but not in others.
Nick Mathewson 76cd2b70 2009-11-27T16:44:47 Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks. Previously, our default lock model kind of assumed that every lock was potentially a read-write lock. This was a poor choice, since read-write locks are far more expensive than regular locks, and so the lock API should only use them when we can actually take advantage of them. Neither our pthreads or win32 lock implementation provided rw locks. Now that we have a way (not currently used!) to indicate that we really want a read-write lock, we shouldn't actually say "lock this for reading" or "lock this for writing" unless we mean it.
Nick Mathewson 347952ff 2009-11-27T15:20:43 Revise the locking API: deprecate the old locking callbacks and add trylock. Previously, there was no good way to request different kinds of lock (say, read/write vs writeonly or recursive vs nonrecursive), or for a lock function to signal failure (which would be important for a trylock mode). This patch revises the lock API to be a bit more useful. The older lock calls are still supported for now. We also add a debugging mode to catch common errors in using the locking APIs.
Nick Mathewson 91fe23fc 2009-11-20T15:46:04 Tolerate code that returns from a fatal_cb. Also, replace more abort() calls with EVUTIL_ASSERT() or event_errx.
Nick Mathewson 767eb70f 2009-11-18T21:16:33 Fix compilation with threading disabled. svn:r1546
Nick Mathewson 18a8cfac 2009-11-15T19:00:12 Prefer calloc(a,b) to malloc(a*b). via openbsd. svn:r1531
Nick Mathewson 629a6133 2009-11-15T18:59:59 When running set[ug]id, don't check the environment. Idea from OpenBSD, but made a bit more generic to handle uncivilized lands that do not define issetugid. svn:r1530
Nick Mathewson 74871cac 2009-11-09T19:37:27 Change event_base.activequeues to "array of eventlist". Previously, event_base.activequeues was of type "array of pointers to eventlist." This was pointless: none of the eventlists were allowed to be NULL. Worse, it was inefficient: - It made looking up an active event queue take two pointer deferences instead of one, thus risking extra cache misses. - It used more RAM than it needed to, because of the extra pointer and the malloc overhead. Also, this patch fixes a bug where we were saying calloc(N,N*sizeof(X)) instead of calloc(N,sizeof(X)) when allocating activequeues. That part, I'll backport. Also, we warn and return -1 on failure to allocate activequeues, rather than calling event_err. svn:r1525
Nick Mathewson e88079a8 2009-11-09T18:30:57 Make persistent timeouts more accurate. Previously, if the user scheduled a persistent timeout for {1,0}, we would schedule the first one at "now+one second", and then when we were about to run its callback, we would schedule it again for one second after that. This would introduce creeping delays to the event that was supposed to run every second. Now, we schedule the event for one second after it was _last scheduled_. To do this, we introduce internal code to add an event at an _absolute_ tv rather than at now+tv. svn:r1520
Nick Mathewson 59be8942 2009-11-09T18:30:48 Make sure that common timeouts are inserted in-order. This code should be a no-op, except under strange thread contention situations. svn:r1519
Nick Mathewson ab96b5f3 2009-11-09T18:30:33 Add an option to disable the timeval cache. svn:r1518
Nick Mathewson 693c24ef 2009-11-09T17:16:30 Implement queued timeouts for case where many timeouts are the same. Libevent's current timeout code is relatively optimized for the randomly scattered timeout case, where events are added with their timeouts in no particular order. We add and remove timeouts with O(lg n) behavior. Frequently, however, an application will want to have many timeouts of the same value. For example, we might have 1000 bufferevents, each with a 2 second timeout on reading or writing. If we knew this were always the case, we could just put timeouts in a queue and get O(1) add and remove behavior. Of course, a queue would give O(n) performance for a scattered timeout pattern, so we don't want to just switch the implementation. This patch gives the user the ability to explicitly tag certain timeout values as being "very common". These timeout values have a cookie encoded in the high bits of their tv_usec field to indicate which queue they belong on. The queues themselves are each triggered by an entry in the minheap. See the regress_main.c code for an example use. svn:r1517
Nick Mathewson 784b8773 2009-11-06T21:46:57 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H svn:r1516
Nick Mathewson 0fd0255f 2009-11-03T19:54:56 Remove compat/sys/_time.h I've gone through everything that it declared to see where it was used, and it seems that we probably don't need it anywhere. Here's what it declared, and why I think we're okay dropping it. o struct timeval {} (Used all over, and we can't really get away with declaring it ourselves; we need the same definition the system uses. If we can't find struct timeval, we're pretty much sunk.) o struct timespec {} (Used in event.c, evdns.c, kqueue.c, evport.c. Of these, kqueue.c and event.c include sys/_time.h. event.c conditions its use on _EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.) o TIMEVAL_TO_TIMESPEC (Used in kqueue.c, but every place with kqueue has sys/time.h) o struct timezone {} (event2/util.h has a forward declaration; only evutil.c references it and doesn't look at its contents.) o timerclear, timerisset, timercmp, timeradd, timersub (Everything now uses the evutil_timer* variants.) o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval (These are only used in test/regress.c, which does not include _time.h) o CLOCK_REALTIME (Only used in evdns.c, which does not include _time.h) o TIMESPEC_TO_TIMEVAL o DST_* o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub o struct clockinfo {} o CLOCK_VIRTUAL, CLOCK_PROF o TIMER_RELTIME, TIMER_ABSTIME (unused) svn:r1494
Nick Mathewson 904b5721 2009-10-27T06:47:25 Avoid calling exit() during event_base_new*() Previously, each of the three make-an-event-base functions would exit under different, weird circumstances, but return NULL on others. - All three would exit on OOM sometimes. - event_base_new() and event_init() would die if all backends were disabled. - None of them would die if the socketpair() call failed. Now, only event_init() exits on failure, and it exits on every kind of failure. event_base_new() and event_base_new_with_config() never do. svn:r1472
Nick Mathewson a2a7d1d1 2009-10-27T05:16:32 Do not call the locking variant of event_add or event_active in some cases when we know we have the lock. svn:r1471
Nick Mathewson d386dc89 2009-10-27T05:16:23 Refactor event_assing even more to avoid unnecessary calls svn:r1470
Nick Mathewson e9ee1057 2009-10-27T04:25:45 Give event_assign a return value, and make it less inclined to exit(). We also refactor event_assign so that it is the core function, and event_set() is only the wrapper. svn:r1469
Nick Mathewson 2e36dbe1 2009-10-26T20:00:43 Use EVUTIL_ASSERT() consistently instead of assert. svn:r1464
Nick Mathewson 38aec9ec 2009-10-23T22:38:35 Tweaks to IOCP interface. svn:r1461
Nick Mathewson 879420a7 2009-10-23T22:00:29 Expose a narrow window to the IOCP code. svn:r1459
Nick Mathewson b73ad7bc 2009-10-21T18:48:22 Treat the bitwise OR of two enum values as an int. This makes our interfaces usable from C++, which doesn't believe you can say "bufferevent_socket_nase(base, -1, BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS)" but which instead would demand "static_cast<bufferevent_options>(BEV_OPT_CLOSE_ON_FREE| BEV_OPT_DEFER_CALLBACKS))" for the last argument. Diagnosis and patch from Chris Davis. svn:r1456
Nick Mathewson c9c4ec26 2009-10-21T05:36:27 Remove an EVBASE_RELEASE_LOCK that I missed. svn:r1452
Nick Mathewson 6b22e74a 2009-10-21T03:54:00 Add locking to event_base_loop. This is harder than it sounds, since we need to make sure to release the lock around the key call to the kernel (e.g., select, epoll_wait, kevent), AND we need to make sure that none of the fields that are used in that call are touched by anything that might be running concurrently in another thread. I managed to do this pretty well for everything but poll(). With poll, I needed to introduce a copy of the event_set structure. This patch also fixes a bug in win32.c where we called realloc() instead of mm_realloc(). svn:r1450
Nick Mathewson e3fd294a 2009-10-16T13:19:57 Spelling fixes in comments and strings. svn:r1445
Nick Mathewson ba8a1771 2009-10-02T03:03:58 Do not notify the main thread more than needed. Basically, we suppress the notification when an event is added or deleted and: - The event has no fd, or there is no change in whether we are reading/writing on the event's fd. - The event has no timeout, or adding the event did not make the earliest timeout become earlier. This should be a big efficiency win in applications with multiple threads and lots of timeouts. svn:r1439
Nick Mathewson d5b640fc 2009-10-01T15:29:08 Apply Ka-Hing Cheung's event_base_got_[break|exit] patch, with locking and whitespace fixes. svn:r1438
Nick Mathewson e3f89fa2 2009-09-11T18:21:57 Add a trivial race-fix from Chromium: do not try to re-detect whether we have a monotonic clock every time we make a new event_base. svn:r1427
Nick Mathewson f8b527e6 2009-07-28T05:09:06 Fix a dumb bug where we would allocate too little memory in event_get_supported_methods(). svn:r1383
Nick Mathewson b06b2649 2009-07-26T01:29:39 Make "deferred callback queue" independent of event_base. This way, we can more easily have an IOCP bufferevent implementation that does not need an event_base at all. Woot. svn:r1381
Nick Mathewson 59e8e959 2009-07-21T19:20:25 Add clarifying "static" to definitions of fns in event.c svn:r1372
Nick Mathewson 1fb2e818 2009-07-17T21:47:45 Use a uniform strategy when a function is not working: do not expose it. Rather than failing at runtime, it is better to fail at compile or link time. svn:r1363
Nick Mathewson 69601fc2 2009-07-17T18:59:22 Update event_tv when time jumps backwards, so that we only note each jump once. Fix for 1939984 svn:r1353
Nick Mathewson 638116ca 2009-07-17T18:38:14 Add a check for event_add failure to evthread_make_base_notifiable() svn:r1348
Nick Mathewson 9fcd84d1 2009-07-14T19:19:45 Include disabled methods in event_get_supported_methods() output. Previously, events that were disabled using EVENT_NO* were left out of event_get_supported_methods(). This was wrong, broke unit tests (under some circumstances) and left the user with no good way to tell which methods were actually compiled in. Fixes bug 2821015. svn:r1344
Nick Mathewson 043515bc 2009-07-14T18:50:06 Stop using C++ style comments. svn:r1343
Nick Mathewson 6b4b77a2 2009-07-14T16:54:48 Make event_del(E) block while E is running in another thread. This gives you the property that once you have called event_del(E), you know that E is no longer running or pending or active at all, and so it is safe to delete the resource used by E's callback. svn:r1341
Nick Mathewson 59cd4936 2009-05-22T14:31:07 Do not free the event base lock until we are done removing all the events. Spotted by Joachim Bauch; fixes bug 2795402. svn:r1302
Nick Mathewson b4886ec8 2009-05-15T18:44:44 Trim 22 bytes from struct event on 32 bit platforms, more on 64-bit platforms. svn:r1292
Nick Mathewson 0fd70978 2009-05-05T01:09:03 Add an event_get_base() function to remove one more reason to include event_struct.h svn:r1271
Nick Mathewson 0e63e72a 2009-05-03T18:56:08 Nothing ever sets event_sigcb or event_gotsig any more: remove them. svn:r1270
Nick Mathewson ebf29455 2009-04-30T23:49:15 Compilation fixes for vc++ 2008 express. Not the end of them. svn:r1260
Nick Mathewson 37bc3466 2009-04-29T20:48:28 Catch attempts to event_base_once a persistent event. svn:r1250
Nick Mathewson 9ad45eef 2009-04-28T19:08:36 Patch from Eric Hopper: the test for EVENT_BASE_FLAG_IGNORE_ENV was inverted. svn:r1248
Nick Mathewson 2ebfd3ba 2009-04-28T19:08:17 Oops. We never actually defined event_config_set_flag(). svn:r1246
Nick Mathewson faa756c7 2009-04-23T21:34:37 Oops. event_config.flags was never initialized. Bugfix on 2.0.1-alpha. Found by Victor Goya. svn:r1236
Nick Mathewson 253151c5 2009-04-22T20:28:30 Detect and reject n_priorities less than 1. svn:r1222
Nick Mathewson 11ff74cf 2009-04-22T19:41:23 Add a flag to disable checking the EVENT_* environment variables. svn:r1220
Nick Mathewson d047b323 2009-04-17T17:22:32 Increment version to 2.0.1-alpha, and add a numeric version facility svn:r1193
Nick Mathewson 7fa8451d 2009-04-17T06:56:57 Add a configure flag to hardcode all of our mm functions. svn:r1186
Nick Mathewson fe95df15 2009-04-13T18:32:24 Fix typo in mm_free svn:r1173
Nick Mathewson 81616620 2009-04-10T14:58:15 A couple of tweaks for deferred callbacks. svn:r1151
Nick Mathewson 4868f4d2 2009-04-10T14:22:33 Initial support for a lightweight 'deferred callbacks'. A 'deferred callback' is just a function that we've queued in the event base. This ability is needed for some mt stuff, and for complex callback chains. For internal use only. svn:r1150
Nick Mathewson e3d82497 2009-04-10T14:21:53 Don't allow internal events to starve lower-priority events. This is exceptionally important with multithreaded stuff, where we use an event to notify the base that other events have been made active. If the activated events have a prioirty number greater than that of the notification event, it will starve them, and that's no good. svn:r1149
Nick Mathewson f98385a4 2009-04-08T16:57:38 add a missing "static" to timeout_process. svn:r1145
Nick Mathewson ec35eb55 2009-02-12T22:19:54 Make threading functions global, like the mm_ functions. Use the libevent_pthread.la library in regress_pthread. svn:r1121
Nick Mathewson b85b710c 2009-01-27T22:34:36 Update copyright statements to reflect the facts that: a) this is 2009 b) niels and nick have been comaintainers for a while c) saying "all rights reserved" when you then go on to explicitly disclaim some rights is sheer cargo-cultism. svn:r1065
Nick Mathewson 8889a770 2009-01-27T22:30:46 Replace all use of config.h with event-config.h. svn:r1064
Nick Mathewson 9993137c 2009-01-27T21:10:31 Remove all trailing whitespace in all the source files. svn:r1063
Niels Provos 1c927b7d 2009-01-27T16:29:48 fix memory leak whens etting up priorities; reported by Alexander Drozdov svn:r1061
Nick Mathewson f20902a2 2009-01-22T17:56:15 Remove evperiodic_assign and its related parts: its functionality is subsumed by EV_PERSIST timeouts. svn:r1040
Nick Mathewson 5e6f6dcd 2009-01-22T17:48:55 Use EV_PERSIST on notify event for efficiency and simplicity. svn:r1039
Niels Provos 56ea4687 2009-01-22T02:33:38 Change the semantics of timeouts in conjunction with EV_PERSIST; timeouts in that case will now repeat until deleted. svn:r1032
Niels Provos ed7e0e77 2009-01-19T23:40:11 bug fix and potentital race condition from Alexander Drozdov svn:r1025
Nick Mathewson a5901991 2009-01-19T20:37:24 Use eventfd for main-thread notification where available (i.e., linux). svn:r1023
Nick Mathewson c3e9fcf6 2009-01-19T20:22:47 Change the semantics of notify so we can implement it with eventfd or (given a different backend for win32) a windows Event. svn:r1022
Nick Mathewson 34d2fd06 2009-01-19T19:46:03 Debug and enable pipe notification svn:r1021
Nick Mathewson ec4cfa33 2009-01-19T01:34:14 Make event_break threadsafe; make notify-thread mechanism a little more generic; let it use pipes where they work. svn:r1019
Nick Mathewson 6bb2f842 2009-01-14T18:38:03 Add initializer functions for evmap types. svn:r1005
Nick Mathewson 169321c9 2009-01-13T20:26:37 Rename four internal headers to follow the -internal.h convention. svn:r1000
Nick Mathewson 55bcd7d2 2009-01-09T13:42:21 On win32, use a hashtable to map sockets to events rather than using an array. svn:r988
Niels Provos d776f846 2008-12-23T22:23:37 deprecate the usage of signal_{add,del,set} and name it evsignal_{add,del,set} instead; move the old definitions to compat svn:r973
Niels Provos 02b2b4d1 2008-12-23T16:37:01 Restructure the event backends so that they do not need to keep track of events themselves, as a side effect multiple events can use the same fd or signal. svn:r972
Niels Provos 77867244 2008-12-19T21:02:36 memory leak: forgot to free the configuration object svn:r961
Niels Provos 808f00e1 2008-12-13T06:11:12 constify structs; from Andrei Nigmatulin svn:r959