381 Commits

Author SHA1 Message Date
Patrick Pelletier
0c6ec5d816 use FormatMessage for winsock errors
as discussed here:
http://archives.seul.org/libevent/users/Feb-2013/msg00004.html
2013-02-14 20:26:38 -08:00
Nick Mathewson
5623e80371 Make event_remove_timer behave correctly with persistent timers 2013-02-13 11:41:11 -05:00
Nick Mathewson
bf7a0ff268 When EWOULDBLOCK is not EAGAIN, treat it as equivalent to it
Acording to http://stackoverflow.com/questions/7003234/which-systems-define-eagain-and-ewouldblock-as-different-values
there are some older unixes that distinguish these error.s
2013-01-11 16:37:34 -08:00
Nick Mathewson
f2703b2e34 Fix a warning when building without threading. 2012-11-18 01:40:13 -05:00
Nick Mathewson
e3b2e0869e Add an event_remove_timer() to remove timer on an event without deleting it 2012-11-16 16:43:17 -05:00
Nick Mathewson
1fda492878 Merge remote-tracking branch 'origin/patches-2.0' 2012-11-16 12:06:40 -05:00
Nick Mathewson
e3cccf380c Avoid crash when event_pending() called with no event_base set on event
Instead, give a warning and return 0.

Reported by Antony Dovgal on github as
   https://github.com/libevent/libevent/issues/19
2012-11-16 11:56:56 -05:00
Nick Mathewson
c17dd59191 Free dangling event_once objects on event_base_free()
This patch makes us keep event_once objects in a doubly linked list
so we can free any once that haven't triggered when we call
event_base_free().
2012-11-16 10:05:04 -05:00
Nick Mathewson
56e48c1019 Fix a few mingw64 incompatibilities introduced since 2.0 2012-11-02 10:58:02 -04:00
Nick Mathewson
2e6a985003 Merge remote-tracking branch 'github/20_win64_compilation' into 21_win64_compilation
Conflicts:
	event.c
	http.c
	sample/event-read-fifo.c
	test/regress_bufferevent.c
2012-11-01 18:12:07 -04:00
Nick Mathewson
94866c2763 Compile without warnings on mingw64
This is mostly a matter of catching cases where we were still
assuming that evutil_socket_t could be used as an int.
2012-11-01 17:56:06 -04:00
Nick Mathewson
ffe1643b98 Add missing return value in event_base_foreach_event
Fix for github issue nmathewson/Libevent #65

Found by Joachim Bauch
2012-09-10 13:43:26 -04:00
Nick Mathewson
232055ef49 Tweak patch for event_base_foreach_event()
* Fix whitespace
* Explain return value from callback function
* Reinstate return value so that caller can tell whether forech
  exited early.
* Rename event_base_foreach_event_() to
  event_base_foreach_event_nolock_().
* Use event_base_foreach_event_cb_fn typedef in more places
* Be more dire about undefined behavior.
2012-09-07 09:58:24 -04:00
Roman Puls
84fd6d7506 Expose event_base_foreach_event() as a public API. 2012-09-07 09:47:50 -04:00
Nick Mathewson
6c14d56430 Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	event.c
	win32select.c
2012-07-16 15:44:07 -04:00
Nick Mathewson
9cd5acb511 Make th_base_lock nonrecursive
This is necessary for making some thread libraries work with
event.c, and might get better performance with others.

The biggest change required here was that we needed to make some
internal code that had previously called event_add and event_del
call the nolock variants.
2012-06-28 12:01:38 -04:00
Simon Liu
be7a95c629 Make event_pending() threadsafe.
(Commit message by Nick)
2012-06-14 13:38:33 -04:00
Nick Mathewson
7d6aa5ee68 Add an event_base_loopcontinue() to tell libevent to rescan right away 2012-05-09 12:06:00 -04:00
Nick Mathewson
c0e425abdc Restore our priority-inversion-prevention code with deferreds
Back when deferred_cb stuff had its own queue, the queue was always
executed, but we never ran more than 16 callbacks per iteration.
That made for two problems:

1: Because deferred_cb stuff would always run, and had no priority,
it could cause priority inversion.

2: It doesn't respect the max_dispatch_interval code.

Then, when I refactored deferred_cb to be a special case of
event_callback, that solved the above issues, but made for two more
issues:

3: Because deferred_cb stuff would always get the default priority,
it could could low-priority bufferevents to get too much priority.

4: With code like bufferevent_pair, it's easy to get into a
situation where two deferreds keep adding one another, preventing
the event loop from ever actually scanning for more events.

This commit fixes the above by giving deferreds a better notion of
priorities, and by limiting the number of deferreds that can be
added to the _current_ loop iteration's active queues.  (Extra
deferreds are put into the active_later state.)

That isn't an all-purpose priority inversion solution, of course: for
that, you may need to mess around with max_dispatch_interval.
2012-05-09 12:06:00 -04:00
Nick Mathewson
581b5beb98 Give event_base_process_active a single exit path 2012-05-09 12:06:00 -04:00
Nick Mathewson
c46cb9c3a2 Make event_base_getnpriorities work with old "implicit base" code 2012-05-09 12:06:00 -04:00
Nick Mathewson
f90e25593c New event_get_priority() function to return an event's priority 2012-05-09 12:06:00 -04:00
Nick Mathewson
a4079aa88a Replace more deferred_cb names with event_callback 2012-05-09 12:05:59 -04:00
Nick Mathewson
ae2b84b257 Replace deferred_cbs with event_callback-based implementation. 2012-05-09 12:05:53 -04:00
Nick Mathewson
fec8bae267 event_base_assert_ok: check value of event_active_count for correctness 2012-05-09 12:05:53 -04:00
Nick Mathewson
745a63dba3 Add "active later" event_callbacks to supersede deferred
An event or event callback can now be in an additional state: "active
later".  When an event is in this state, it will become active the
next time we run through the event loop.  This lets us do what we
wanted to with deferred callbacks: make a type of active thing that
avoids infinite circular regress in a way that starves other events or
exhausts the stack.  It improves on deferred callbacks by respecting
priorities, and by having a non-kludgy way to avoid event starvation.
2012-05-09 12:05:53 -04:00
Nick Mathewson
cba59e5325 Refactor the callback part of an event into its own event_callback type
This shouldn't have any visible effect, but it's necessary or
advisible for a few changes and cleanups I would like to make,
including:
   * Replacing the deferred queue with a type that works more as if it
     were an event.
   * Introducing a useful "activate this on the next round through the
     event loop" state for events and deferreds.
   * Adding an "on until further notice" status for events, to allow a
     saner win32-hybrid approach.
   * Eventually, making all user callbacks first-class things with
     event-like semantics.
2012-05-09 12:05:53 -04:00
Nick Mathewson
a163026099 Merge branch '21_robust_monotonic' 2012-05-01 13:22:56 -04:00
Nick Mathewson
2e882a071b Merge remote-tracking branch 'origin/patches-2.0'
Conflicts:
	event.c
2012-04-30 22:00:05 -04:00
Nick Mathewson
2bfda4012c If a higher-priority event becomes active, don't continue running events of the current priority.
Bug found by Ralph Castain.
2012-04-30 17:30:48 -04:00
Nick Mathewson
630f077c29 Simple unit tests for monotonic timers 2012-04-26 16:42:21 -04:00
Nick Mathewson
a2598ec6bd Add EVENT_PRECISE_TIMER environment var for selecting precise-but-slow timer 2012-04-26 15:44:37 -04:00
Nick Mathewson
f5e4eb05e5 Refactor monotonic timer handling into a new type and set of functions; add a gettimeofday-based ratcheting implementation
Now, event.c can always assume that we have a monotonic timer; this
makes event.c easier to write.
2012-04-26 15:44:31 -04:00
Nick Mathewson
d992d911a6 Merge remote-tracking branch 'origin/patches-2.0' 2012-04-20 11:51:33 -04:00
Nick Mathewson
dfd808cbad If time has jumped so we'd reschedule a periodic event in the past, schedule it for the future instead
Fixes an issue reported on libevent-users in the thread "a dead
looping bug when changing system time backward". Previously, if time
jumped forward 1 hour[*] and we had a one-second periodic timer event,
that event would get invoked 3600 times.  That's almost certainly not
what anybody wants.

In a future version of Libevent, we should expose the amount of time
that the callbac kwould have been invoked somehow.

[*] Forward time jumps can happen with nonmonotonic clocks, or with
clocks that jump on suspend/resume.  It can also happen from
Libevent's point of view if the user exits from event_base_loop() and
doesn't call it again for a while.
2012-04-19 18:25:59 -04:00
Nick Mathewson
bec22b4176 Refactor event_persist_closure: raise and extract some common logic 2012-04-19 18:15:12 -04:00
Nick Mathewson
d5e1d5ad99 Implement a GetTickCount-based monotonic timer for Windows 2012-04-17 15:37:12 -04:00
Nick Mathewson
55780a70e2 On Linux, use CLOCK_MONOTONIC_COARSE by default
You can make it use CLOCK_MONOTONIC again by setting the
EVENT_BASE_FLAG_PRECISE_TIMER flag in the event_config.
2012-04-17 13:09:49 -04:00
Nick Mathewson
1fbef7d538 Move use_monotonic and friends into event_base
The use_monotonic field used to be a static field set up at library
setup.  Unfortunately, this makes it hard to give the user a way to
make speed/accuracy tradeoffs about time.  Moving it into event_base
should let the clock implementation become configurable.
2012-04-17 12:44:39 -04:00
Nick Mathewson
53a07fe2f9 Replace pipe-based notification with EVFILT_USER where possible
Sufficiently recent kqueue implementations have an EVFILT_USER filter
that we can use to wake up an event base from another thread.  When
it's supported, we now use this mechanism rather than our old
(pipe-based) mechanism.  This should save some time and complications
on newer OSX and freebsds.
2012-04-11 16:14:09 -04:00
Nick Mathewson
cb653a0027 Do not track use_monotonic field when is no monotonic clock 2012-04-09 18:29:30 -04:00
Nick Mathewson
b8fd6f918b Use mach_absolute_time() for monotonic clock support on OSX. 2012-04-09 18:29:30 -04:00
Nick Mathewson
2449e0c508 Fix some compilation warnings with msvc 2012-04-03 16:15:49 -04:00
Nick Mathewson
13dad99c2f make event_base_get_running_event build with threads disabled. 2012-04-03 14:53:00 -04:00
Nick Mathewson
09cbc3dcfb Temporarily disable event_queue_reinsert_timeout
Apparently, now that we have tests for it in main/common_timeout, we
can now see that it sometimes breaks referential integrity somehow.
Since I'd like to get 2.1.1-alpha out the door soon, I'm turning it
off for now.
2012-03-26 23:28:21 -04:00
Nick Mathewson
55e991b27c Make libevent_global_shutdown() idempotent
Two calls to libevent_global_shutdown on your exit path shouldn't
result in a crash.
2012-03-26 17:35:21 -04:00
Nick Mathewson
c5732fddb0 Add event_base_get_running_event() to get the event* whose cb we are in 2012-03-25 18:54:40 -04:00
Nick Mathewson
8c36acd0b0 Fix a nasty bug in event_queue_reinsert_timeout()
What was I thinking?  The old function could handle heap-to-heap
transitions, and transitions within the same common timeout queue, but
it completely failed to handle heap/queue transitions, or transitions
between timeout queues.

Now, alas, it's complicated.  I should look hard at the assembly here
to see if it's actually better than the alternatives.
2012-03-23 18:42:56 -04:00
Nick Mathewson
0343d8fec5 event_base_dump_events: Report active events tersely, and note internal events 2012-03-23 17:53:08 -04:00
Mark Ellzey
041ca00c75 Add a new libevent_global_shutdown() to free all globals before exiting.
Mark Ellzey added a function libevent_shutdown() which calls a set of
private functions:

       * event_free_globals()
       * event_free_debug_globals()
       * event_free_debug_globals_locks()
       * event_free_evsig_globals()
       * evsig_free_globals()
       * evsig_free_globals_locks()
       * evutil_free_globals()
       * evutil_free_secure_rng_globals()
       * evutil_free_secure_rng_globals_lock()

Nick tweaked this libevent global shutdown code:

  - rename the function to emphasize that it's for global resources
  - write more in the doxygen
  - make function brace style consistent
  - add a missing void in a function definition.
2012-03-22 11:57:04 -04:00