Nick Mathewson [Fri, 30 Oct 2009 21:08:29 +0000 (21:08 +0000)]
Keep openssl errors associated with the right bufferevent object.
OpenSSL has a per-thread error stack, and really doesn't like you
leaving errors on the stack. Rather than discard the errors or force
the user to handle them, this patch pulls them off the openssl stack
and puts them on a stack associated with the bufferevent_openssl. If
the user leaves them on the stack then, it won't affect any other
connections.
Nick Mathewson [Tue, 27 Oct 2009 06:47:25 +0000 (06:47 +0000)]
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.
Nick Mathewson [Mon, 26 Oct 2009 20:00:08 +0000 (20:00 +0000)]
Add an EVUTIL_ASSERT() to replace our calls to assert().
The big difference here is that EVUTIL_ASSERT() passes its message on
via event_errx() before aborting, so that the application has a prayer
of noticing and recording it.
Nick Mathewson [Wed, 21 Oct 2009 19:21:05 +0000 (19:21 +0000)]
Make the bufferevent_connect_fail test faster on OSX.
It seems that connecting to a listener that is bound but not accepting
or listening doesn't give a 'connection refused' error on OSX, but
rather makes the connect() time out after 75 seconds. I couldn't find
any way to make the timout shorter. Fortunately, closing the listener
after a second or so makes the desired error occur after another
second or so.
Nick Mathewson [Wed, 21 Oct 2009 18:48:22 +0000 (18:48 +0000)]
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.
Nick Mathewson [Wed, 21 Oct 2009 07:00:14 +0000 (07:00 +0000)]
Fix win32 connect() event handling.
Christopher Davis reported:
Connection failures aren't reported on Windows when
using bufferevent_socket_connect, because Windows uses
select's exceptfds to notify of failure, and libevent
treats them like read events. Only the write event
handler is currently used to handle connection events.
We should think hard about this one, since it changes
behavior from 1.4.x. Anything that worked on Mac/Unix before
will work more consistently on Windows now... but this might
break stuff that worked only on Windows, but nowhere else.
Nick Mathewson [Wed, 21 Oct 2009 03:54:00 +0000 (03:54 +0000)]
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().
Nick Mathewson [Fri, 2 Oct 2009 03:03:58 +0000 (03:03 +0000)]
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.
Nick Mathewson [Fri, 11 Sep 2009 18:47:35 +0000 (18:47 +0000)]
Make epoll use less RAM.
We do this by not allocating the maximum epoll_event array for the epoll
backend at startup. Instead, we start out accepting 32 events at a time, and
double the array's size when it seems that the OS is generating events faster
than we're requesting them. This saves up to 374K per epoll-based
event_base. Resolves bug 2839240.
Nick Mathewson [Wed, 19 Aug 2009 20:55:25 +0000 (20:55 +0000)]
On connect, call only one of BEV_EVENT_CONNECTED or writecb.
Previously, if we had a socket bufferevent in connect state, we'd send
both of these to indicate that the connection was done. That was broken
since the point of adding BEV_EVENT_CONNECTED was so that we could
distinguish "we're connected" and "we wrote something".
Now, writecb is called only when
A) the connection finished but the user never put the socket into a
"connecting" state, or
B) data was actually written.
Nick Mathewson [Fri, 7 Aug 2009 17:16:52 +0000 (17:16 +0000)]
Add an evbuffer_search_range() to search a bounded range of a buffer
This can be handy when you have one search to find the end of a header
section, and then you want to find a substring within the header
section without looking at the body.
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.