454 Commits

Author SHA1 Message Date
Diego Giagio
b1b69ac7c1 Implemented EV_CLOSED event for epoll backend (EPOLLRDHUP).
- Added new EV_CLOSED event - detects premature connection close
  by clients without the necessity of reading all the pending
  data. Does not depend on EV_READ and/or EV_WRITE.

- Added new EV_FEATURE_EARLY_CLOSED feature for epoll.
  Must be supported for listening to EV_CLOSED event.

- Added new regression test: test-closed.c

- All regression tests passed (test/regress and test/test.sh)

- strace output of test-closed using EV_CLOSED:
    socketpair(PF_LOCAL, SOCK_STREAM, 0, [6, 7]) = 0
    sendto(6, "test string\0", 12, 0, NULL, 0) = 12
    shutdown(6, SHUT_WR)                    = 0
    epoll_ctl(3, EPOLL_CTL_ADD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    epoll_wait(3, {{EPOLLRDHUP, {u32=7, u64=7}}}, 32, 3000) = 1
    epoll_ctl(3, EPOLL_CTL_MOD, 7, {EPOLLRDHUP, {u32=7, u64=7}}) = 0
    fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 4), ...})
    mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYM...
    write(1, "closed_cb: detected connection close "..., 45) = 45
2014-01-17 23:20:42 -02:00
Nick Mathewson
f9e091bf4e Merge remote-tracking branch 'asweeny86/event-count-max' 2014-01-06 12:11:30 -05:00
Andrew Sweeney
efbd3dcf28 Fixed bug using wrong variable in max event compare 2014-01-05 16:29:52 -05:00
Andrew Sweeney
5173bef50f Add access to max event count stats
This commit provides an interface for accessing and resetting the maximum
number of events in a given period.  This information provides better insight
into event queue pressure.
2013-12-30 14:06:20 -05:00
Nick Mathewson
87fa2b004a Unit tests for active_by_fd; unsupport active_by_fd(TIMEOUT)
[It turns out that event_base_active_by_fd(TIMEOUT) didn't actually
work right. Feel free to add it back in as a patch.]
2013-12-23 20:46:38 -05:00
Nick Mathewson
486594337a Add event_base_active_by_signal by analogy 2013-12-21 23:32:10 -05:00
Nick Mathewson
5c9da9a8a8 Sanity-check arguments to event_base_active_by_fd() 2013-12-21 23:21:33 -05:00
Nick Mathewson
93369ff4e9 Merge remote-tracking branch 'ghazel/event_base_active_by_fd' 2013-12-21 23:15:41 -05:00
Nick Mathewson
1c06985a01 Add an assertion for another of the complaints from coverity. See 1b065d07df196 2013-08-06 20:00:53 -04:00
Nick Mathewson
69b5c64704 Move event_debug_note_teardown_ before mm_free.
This isn't a bug, since only the pointer value of ev was used, but
it's probably best not to tempt fate.  Found by coverity.
2013-08-06 19:10:13 -04:00
Nick Mathewson
1b065d07df Add some assertions to please coverity.
In event_process_active_single_queue, EVLIST_INIT must be set on any
event that uses one of the event-only closures, and so "ev" will be
set in those cases.  But coverity's worried here (CIDs numerous).  So
instead, just add the assertions that should make it happy.
2013-08-06 19:10:13 -04:00
Mobai Zhang
0fa107d8cb Added event_base_get_num_events() 2013-07-02 16:01:02 -04:00
Nick Mathewson
3dc2d8ab83 Remove a debugging assert that should not have been left in 2013-05-28 10:14:51 -04:00
Azat Khuzhin
d3d999a116 Missed lock acquire/release in event_base_cancel_single_callback_()
Call backtrace:
...
event_queue_remove_active()
event_callback_cancel_nolock_()
event_base_cancel_single_callback_()
event_base_free_()
event_base_free()
...

Fix for e9ebef83
2013-05-10 21:40:45 -04:00
Nick Mathewson
f2925d78b6 Fix a windows compilation regression
This is github issue #57; reported by "efekty". I assume the compiler
is MSVC.
2013-04-30 22:57:25 -04:00
Nick Mathewson
3555befd1c Merge branch '21_deadlock_fix_v2' 2013-04-26 12:27:05 -04:00
Nick Mathewson
5d11f4f39a Make the event_finalize* functions return an error code 2013-04-26 12:18:38 -04:00
Nick Mathewson
a800b913ac More documentation for finalization feature 2013-04-26 12:18:38 -04:00
Nick Mathewson
e9ebef83a0 Always run pending finalizers when event_base_free() is called
There was actually a bug in the original version of this: it tried to
run the finalizers after (potentially) setting current_base to NULL;
but those finalizers could themselves (potentially) be invoking stuff
that needed to know about the current event_base.  So the right time to
do it is _before_ clearing current_base.
2013-04-26 12:18:07 -04:00
Nick Mathewson
8eedeabe50 Implement event_finalize() and related functions to avoid certain deadlocks 2013-04-26 12:18:07 -04:00
Nick Mathewson
5e6fa2a3ab event_base_update_cache_time should be a no-op if the loop isn't running 2013-04-24 13:23:15 -04:00
Nate Rosenblum
9443868d55 Double-check next timeout when adding events
When resuming the system from a suspended state, the ev_timeout field
of a scheduled timer event may be in the past. This leads to
unexpected behavior when scheduling a short-duration timer event
immediately after returning from suspension, because the new event
does not land on top of the timeout minheap and so the event loop
(blocked on a possibly long-duration timeout) is not notified.

This patch checks for this condition and, if it obtains, notifies the
event loop.
2013-03-05 11:29:33 -08:00
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
Greg Hazel
865a14261c event_base_active_by_fd 2013-01-16 16:31:08 -08: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