Nick Mathewson [Tue, 28 Jul 2009 17:11:03 +0000 (17:11 +0000)]
Fix segfault during failed allocatino of locked evdns base.
We need to comb the rest of the code to make sure that we don't blindly wrap
functions in LOCK(x), UNLOCK(x) when those functions might contain a FREE(x)
in the middle.
Nick Mathewson [Tue, 28 Jul 2009 04:03:57 +0000 (04:03 +0000)]
Bufferevent support for openssl.
This code adds a new Bufferevent type that is only compiled when the
openssl library is present. It supports using an SSL object and an
event alert mechanism, which can either be an fd or an underlying
bufferevent.
There is still more work to do: the unit tests are incomplete, and we
need to support flush and shutdown much better. Sometimes events are
generated needlessly: this will hose performance.
There's a new encrypting proxy in sample/le-proxy.c.
This code has only been tested on OSX, and nowhere else.
Nick Mathewson [Sat, 25 Jul 2009 03:35:32 +0000 (03:35 +0000)]
Fix the main/methods unit test to pass from "make verify".
The problem was introduced when we changed the semantics of
get_supported_methods() to reflect all the methods that exist.
Previously, it had not returned methods disabled from the environment,
but the test didn't know that.
Nick Mathewson [Fri, 17 Jul 2009 17:46:17 +0000 (17:46 +0000)]
Always hold a reference to a bufferevent when calling its callbacks.
Rationale: we hold a lock on the bufferevent when its callbacks are
executing, so we need to release the lock afterwards. But the
callback might free the bufferevent, so unless we're holding a
reference on the bufferevent, the lock might not be there for us to
release.
Nick Mathewson [Tue, 14 Jul 2009 19:19:45 +0000 (19:19 +0000)]
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.
Nick Mathewson [Tue, 14 Jul 2009 16:54:48 +0000 (16:54 +0000)]
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.
Nick Mathewson [Mon, 13 Jul 2009 20:02:49 +0000 (20:02 +0000)]
Use -version-info, not -release.
Patch from Zack Weinberg. His description:
This one might be a little more controversial. Libtool's -release and
-version-info options are supposed to be mutually exclusive, but it doesn't
either enforce that or make it sufficiently clear in the manual. Using
both makes the -version-info switch ineffective; you will get sonames like
"libevent-2.0.so.1", "libevent-2.1.so.1", etc., even though version 2.1
will presumably be backward ABI compatible with 2.0.
This patch just takes out the -release switches and bumps the -version-info
value to 2:0:0 so that people looking at the files in /usr/lib will not be
confused (it'll be "libevent.so.2"). This does change the soname, but the
current release is labeled an alpha, and it would be better to stop using
both switches as soon as possible, before someone over at libtool
headquarters decides to enforce the mutual exclusivity here...
Note that libevent_pthreads is not being linked with any versioning
switches I didn't change that because I wasn't sure whether it was
intentional.
Nick Mathewson [Fri, 10 Jul 2009 19:38:16 +0000 (19:38 +0000)]
Change use of AC_CHECK_LIB to AC_SEARCH_LIBS.
Patch from Zack Weinberg. His message:
This one eliminates all use of AC_CHECK_LIB in the configure script.
AC_CHECK_LIB has a serious flaw: if the library you mention *exists*
but is not *necessary* for the function you want, it adds it to
$(LIBS) anyway. This was fine in the days of static libraries,
because the linker would ignore an .a library that didn't contain
anything you needed. However, ELF shared libraries are different
(let's not get into why): the linker will by default record a
DT_NEEDED entry for every shared object mentioned on the link
command line. Thus, every use of AC_CHECK_LIB is a potential
unnecessary DT_NEEDED, making extra work for the dynamic loader. The
cure is simply to use AC_SEARCH_LIBS instead; it first tries to find
the function you ask for in libc, and only if that doesn't work does
it try to use the extra library you mention.
For the same reasons, pkg-config .pc files should distinguish
between the libraries to use for shared linkage (Libs:) and the
additional libraries needed for static linkage (Libs.private:). I
have also made that correction in this patch. I also took the
opportunity to clean up the substitution variables a little and make
absolutely sure that the core library does not get linked against
zlib.
While commas at the end of enumerator lists are valid in c99, they
are not valid +in c89 nor in c++. When using gcc/g++ with the
-pedantic flag, users will +receive a warning (gcc) or an
error(g++) when including the event2/event.h and
+event2/bufferevent.h. The errors look something like
event2/event.h:159: error: comma at end of enumerator list
Nick Mathewson [Wed, 27 May 2009 15:35:00 +0000 (15:35 +0000)]
Activate fd events in a pseudorandom order on older backends.
New backends like poll and kqueue and so on add fds to the queue in
the order that they are triggered. But the select backend currently
activates low-numbered fds first, whereas the poll and win32 backends
currently favor whatever fds have been on for the longest. This is no
good for fairness.
Nick Mathewson [Mon, 25 May 2009 23:10:23 +0000 (23:10 +0000)]
Add a generic mechanism to implement timeouts in bufferevents.
Paired and asynchronous bufferevents didn't do timeouts, and filtering
bufferevents gave them funny semantics. Now they all should all work
in a way consistent with what socket bufferevents do now: a [read/write]
timeout triggers if [reading/writing] is enabled, and if the timeout is
set, and the right amount of time passes without any data getting
[added to the input buffer/drained from the output buffer].
Nick Mathewson [Fri, 22 May 2009 18:20:59 +0000 (18:20 +0000)]
Fix a potentially very annoying evdns bug that we found in Tor.
Generally speaking, it way better to event_assign() an event when you
allocate it than to assign it before every time you event_add it: if
it is already event_add()ed, the assign will mess it up so that it
doesn't _look_ added, and event_add() will insert a second copy.
Later, event_del() will only delete the second copy. Eventually, the
event_base will have a dangling pointer to freed memory. Ouch!
Nick Mathewson [Fri, 22 May 2009 14:48:40 +0000 (14:48 +0000)]
Try to contain the failure when we are running without socketpair().
Some win32 systems (mostly those using Kaspersky, it would seem)
prevent us from faking socketpair(). This makes our signal
notification code just not work. Our response since 1.4 has been to
assert. For users who would rather work without signals than not work
at all, this has been a regression from 1.3e.
This patch makes adding signal events fail in this case; there's no
reason to kill the whole process.
Nick Mathewson [Fri, 15 May 2009 20:23:59 +0000 (20:23 +0000)]
New semantics for evbuffer_cb_set_flags().
Previously, set_flags() would replace all previous user-visible flags.
Now it just sets the flags, and there is a clear_flags() function to
clear other flags.
Nick Mathewson [Wed, 13 May 2009 20:37:21 +0000 (20:37 +0000)]
Add a "ctrl" mechanism to bufferevents for property access.
OpenSSL uses something like this to implement get/set access for
properties on its BIOs, so that it doesn't need to add a pair of
get/set functions to the vtable struct for every new abstract property
it provides an accessor for.
Doing this lets us make bufferevent_setfd abstract, and implement an
abstract bufferevent_getfd.
Nick Mathewson [Wed, 13 May 2009 20:36:56 +0000 (20:36 +0000)]
Do not use the "evbuffer_" prefix to denote parts of bufferevents.
This is a bit of an interface doozy, but it's really needed in order
to be able to document this stuff without apologizing it. This patch
does the following renamings:
Nick Mathewson [Tue, 5 May 2009 16:52:37 +0000 (16:52 +0000)]
Make unit tests for bufferevent_async compile and _almost_ work.
Either I need to make the callbacks get deferred in a base with no events (doable), or I need to make it okay to call launch_read from inside the callback for read (tricky).
Nick Mathewson [Tue, 5 May 2009 02:59:26 +0000 (02:59 +0000)]
Add new code to make and accept connections.
This is stuff that it's easy to get wrong (as I noticed when writing
bench_http), and that takes up a fair amount of space (see http.c).
Also, it's something that we'll eventually want to abstract to use
IOCP, where available.