Nick Mathewson [Fri, 12 Mar 2010 19:16:30 +0000 (14:16 -0500)]
Switch to using AM conditionals in place of AC_LIBOBJ
AC_LIBOBJ is really only meant for defining missing library functions,
not conditional code compilation. Sticking our conditionally compiled
modules in SYS_SRC should make stuff easier to maintain.
Nick Mathewson [Thu, 11 Mar 2010 04:39:30 +0000 (23:39 -0500)]
Allow evbuffer_read() to split across more than 2 iovecs
Previously it would only accept 2 iovecs at most, because our
previous_to_last nonsense didn't let it take any more. This forced us
to do more reallocations in some cases when an extra small malloc
would have sufficed.
Nick Mathewson [Thu, 11 Mar 2010 04:24:14 +0000 (23:24 -0500)]
Use last_with_data in place of previous_to_last
This actually makes some of the code a lot simpler. The only
ones that actually used previous_to_last for anything were reserving
and committing space.
Nick Mathewson [Thu, 11 Mar 2010 03:16:14 +0000 (22:16 -0500)]
Revise evbuffer to add last_with_data
This is the first patch in a series to replace previous_to_last with
last_with_data. Currently, we can only use two partially empty chains
at the end of an evbuffer, so if we have one with 511 bytes free, and
another with 512 bytes free, and we try to do a 1024 byte read, we
can't just stick another chain on the end: we need to reallocate the
last one. That's stupid and inefficient.
Instead, this patch adds a last_with_data pointer to eventually
replace previous_to_last. Instead of pointing to the penultimated
chain (if any) as previous_to_last does, last_with_data points to the
last chain that has any data in it, if any. If all chains are empty,
last_with_data points to the first chain. If there are no chains,
last_with_data is NULL.
The next step is to start using last_with_data everywhere that we
currently use previous_to_last. When that's done, we can remove
previous_to_last and the code that maintains it.
Nick Mathewson [Wed, 10 Mar 2010 21:25:16 +0000 (16:25 -0500)]
Make evdns use the regular logging system by default
Once, for reasons that made sense at the time, we had evdns.c use its
own logging subsystem with two levels, "warn" and "debug". This leads
to problems, since setting a log handler for Libevent wouldn't actually
trap these messages, since they weren't on by default, and since some of
the warns should really be msgs.
This patch changes the default behavior of evdns.c to log to
event_(debugx,warnx,msgx) by default, and adds a new (internal-use-only)
log level of EVDNS_LOG_MSG. Programs that set a evdns logging
function will see no change. Programs that don't will now see evdns
warnings reported like other warnings.
Nick Mathewson [Tue, 2 Mar 2010 22:00:06 +0000 (17:00 -0500)]
Improve the speed of evbuffer_readln()
This makes some cases of bench_http about 5% faster.
Our internal evbuffer_strpbrk() function was overly general (it tried
to handle all character sets when we only used it for "\r\n"), and
not very efficient (it called memchr once for each character in the
buffer until it found a \r or a \n). It actually showed up in some
profiles for HTTP testing, since evbuffer_readln() calls it when doing
loose CRLF detection. This patch replaces it with a faster
implementation.
Nick Mathewson [Wed, 3 Mar 2010 17:15:15 +0000 (12:15 -0500)]
Remove signal_assign() and signal_new() macros.
These were introduced and deprecated in the same version (2.0.1-alpha),
presumably in two-stage process. Everybody sane should be using
evsignal_assign() and evsignal_new() instead.
It looks like I accidentally removed most of WIN32-Code/event-config.h
when I was bumping the version. Fortunately, this happened when I
bumped to 2.0.4-alpha-dev rather than when I bumped to 2.0.4-alpha. :)
This patch restores the deleted parts of WIN32-Code/event-config.h
Nick Mathewson [Sun, 28 Feb 2010 03:27:13 +0000 (22:27 -0500)]
Small cleanups on freebsd-connect-refused patch.
There should be no need to call be_socket_enable: that does an
event_add(). What we really want to do is event_active(), to make
sure that the writecb is executed.
Also, there was one "} if () {" that was missing an else.
I've noted that the return value for evutil_socket_connect() is
getting screwy, but since that isn't an exported function, we can fix
it whenever.
Nick Mathewson [Sat, 20 Feb 2010 23:44:35 +0000 (18:44 -0500)]
Provide consistent, tested semantics for bufferevent timeouts
The different bufferevent implementations had different behavior for
their timeouts. Some of them kept re-triggering the timeouts
indefinitely; some disabled the event immediately the first time a
timeout triggered. Some of them made the timeouts only count when
the bufferevent was actively trying to read or write; some did not.
The new behavior is modeled after old socket bufferevents, since
they were here first and their behavior is relatively sane.
Basically, each timeout disables the bufferevent's corresponding
read or write operation when it fires. Timeouts are stopped
whenever we suspend writing or reading, and reset whenever we
unsuspend writing or reading. Calling bufferevent_enable resets a
timeout, as does changing the timeout value.
Nick Mathewson [Tue, 23 Feb 2010 19:24:10 +0000 (14:24 -0500)]
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 [Mon, 22 Feb 2010 20:38:23 +0000 (15:38 -0500)]
Make bufferevent_free() clear all callbacks immediately.
This should end the family of bugs where we call bufferevent_free()
while a pending callback is holding a reference on the bufferevent,
and the callback tries to invoke the user callbacks before it releases
its own final reference.
This means that bufferevent_decref() is now a separate function from
bufferevent_free().
Nick Mathewson [Sat, 20 Feb 2010 17:55:59 +0000 (12:55 -0500)]
Suspend read/write on bufferevents during hostname lookup
When we're doing a lookup in preparation for doing a connect, we
might have an unconnected socket on hand, and mustn't actually do
any reading or writing with it.
Nick Mathewson [Thu, 18 Feb 2010 05:54:44 +0000 (00:54 -0500)]
Fix getpid() usage on Windows
On Windows, getpid() is _getpid(), and requires that we first include
<process.h>. arc4random.c previously didn't know that.
Actually, I question whether arc4random needs to do its getpid() tricks
on Windows. They exist only so that we remember to re-seed the ARC4
cipher whenever we fork... but Windows has no fork(), so I think we're
in the clear.
Nick Mathewson [Thu, 18 Feb 2010 05:27:35 +0000 (00:27 -0500)]
When working without a current event base, don't try to use IOCP listeners
This fixes a bug turned up with the http unit tests, where we create
the evhttp object using an implicit (NULL) event_base. This failed
pretty badly when we tried to use IOCP-based listeners. We could
hunt for the current base from inside listener.c in the future, or
get the iocp base some other way, but for now this is probably the safest
solution.
Nick Mathewson [Tue, 16 Feb 2010 00:54:15 +0000 (19:54 -0500)]
Construct Windows locks using InitializeCriticalSectionAndSpinCount
Previously we were using InitializeCriticalSection, which creates a
lock that blocks immediately on contention and waits to be
rescheduled. This is inefficient; it's better to wait for a little
while before telling the US to reschedule us, in case the lock becomes
available again really soon (since most locks mostly do).
Good pthreads implementations do this automatically. On Windows,
though, we need to call this magic function, and we need to pick the
spin count ourselves.
Nick Mathewson [Fri, 5 Feb 2010 06:16:23 +0000 (01:16 -0500)]
Remove the 'flags' argument from evdns_base_set_option()
The 'flags' argument made sense when passed to
evdns_(base_)?parse_resolv_conf when it said which parts of the
resolv.conf file to obey. But for evdns_set_option(), it was really
silly, since you wouldn't be calling evdns_set_option() unless you
actually wanted to set the option. Its meaning was basically, "set
this to DNS_OPTIONS_ALL unless you want a funny surprise."
evdns_base_set_option was new in 2.0.1-alpha, so we aren't committed
to keeping it source-compatible.
Make Libevent 1.4.12 build on win32 with Unicode enabled.
This patch fixes calls to the win32 api to explicitly call the char* versions
of the functions. This fixes build failures when libevent is built with the
UNICODE define.
Niels Provos [Wed, 3 Feb 2010 22:34:56 +0000 (14:34 -0800)]
do not fail while sending on http connections the client closed.
when sending chunked requests via multiple calls to evhttp_send_reply_chunk,
the client may close the connection before the server is done sending. this
used to cause a crash.
we introduce a new function evhttp_request_get_connection() that allows the
server to determine if the request is still associated with a connection.
If it's not, evhttp_request_free() needs to be called explicitly or the user
can call evhttp_send_reply_end() which just frees the request, too.
Nick Mathewson [Wed, 3 Feb 2010 20:12:04 +0000 (15:12 -0500)]
Functions to view and manipulate rate-limiting buckets.
We need these for Tor, and other projects probably need them too. Uses
include:
- Checking whether bandwidth is mostly-used, and only taking some
actions when there's plenty of bandwidth.
- Deducting some non-bufferevent activities from a rate-limit group.
Nick Mathewson [Wed, 3 Feb 2010 07:09:19 +0000 (02:09 -0500)]
Reduce windows header includes in our own headers.
It turns out that absolutely everything that was including
windows.h was doing so needlessly; our headers don't need it,
so we should just include winsock2.h (since that's where
struct timeval is defined).
Pre-2.0 code will use the old headers, which include windows.h
for them, so we aren't breaking source compatibility with 1.4.
This solves the bug where we were leaving WIN32_LEAN_AND_MEAN
defined, in roughly the same way that buying an automobile
solves the question of what to give your coachman for boxing
day.
Nick Mathewson [Wed, 3 Feb 2010 06:22:44 +0000 (01:22 -0500)]
Remove EVUTIL_CHECK_FMT.
This was never supposed to be an exposed API, so its name should have been
more like _EVUTIL_CHECK_FMT. But it was only used in one place, so let's
just eliminate it.
Nick Mathewson [Tue, 26 Jan 2010 17:06:41 +0000 (12:06 -0500)]
Add ev_[u]intptr_t to include/event2/util.h
We already emulate most of the other useful bits of stdint.h, and
we seem to have started to use uintptr_t in a few places throughout
the code. Let's make sure we can continue to do so even on backwards
platforms that don't do C99.
Nick Mathewson [Mon, 25 Jan 2010 19:07:01 +0000 (14:07 -0500)]
Try to untangle the logic in server_port_flush().
The logic that prevented the first loop in this function from being
infinite was rather confusing and hard to follow. It seems to confuse
some automatic analysis tools as well as me. Let's try to replace it
with something more comprehensible.
Nick Mathewson [Mon, 25 Jan 2010 18:44:56 +0000 (13:44 -0500)]
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 [Mon, 25 Jan 2010 18:38:07 +0000 (13:38 -0500)]
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 [Fri, 22 Jan 2010 05:34:37 +0000 (00:34 -0500)]
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 [Sat, 23 Jan 2010 21:47:54 +0000 (16:47 -0500)]
Remove a needless include of rpc_compat.h
Nothing in evrpc.c was using rpc_compat.h, so it's best to take it
out, especially since it polluted our build process with GCC variadic
macros.
While we're at it, this patch puts an extra restriction on when the
variadic macros in rpc_compat.h are defined. Not only must GCC be the
compiler, but GCC must not be running in -ansi mode.