]> granicus.if.org Git - libevent/log
libevent
14 years agoMerge remote branch 'github/split_free_from_decref'
Nick Mathewson [Tue, 23 Feb 2010 05:39:02 +0000 (00:39 -0500)]
Merge remote branch 'github/split_free_from_decref'

14 years agoExpose view of current rate limit as constrained by group limit
Nick Mathewson [Tue, 23 Feb 2010 05:38:30 +0000 (00:38 -0500)]
Expose view of current rate limit as constrained by group limit

14 years agoMake bufferevent_free() clear all callbacks immediately.
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().

14 years agoSuspend read/write on bufferevents during hostname lookup
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.

14 years agoClean up formatting: function/keyword spacing consistency.
Nick Mathewson [Fri, 19 Feb 2010 08:39:50 +0000 (03:39 -0500)]
Clean up formatting: function/keyword spacing consistency.

- Keywords always have a space before a paren.  Functions never do.

- No more than 3 blank lines in a row.

14 years agoClean up formatting: remove trailing spaces
Nick Mathewson [Thu, 18 Feb 2010 22:46:56 +0000 (17:46 -0500)]
Clean up formatting: remove trailing spaces

14 years agoClean up formatting: use tabs, not 8-spaces, to indent.
Nick Mathewson [Thu, 18 Feb 2010 22:41:15 +0000 (17:41 -0500)]
Clean up formatting: use tabs, not 8-spaces, to indent.

14 years agoClean up formatting: Disallow space-before-tab.
Nick Mathewson [Thu, 18 Feb 2010 22:08:50 +0000 (17:08 -0500)]
Clean up formatting: Disallow space-before-tab.

14 years agoWhen connect() succeeds immediately, don't invoke the callback immediately.
Nick Mathewson [Thu, 18 Feb 2010 19:50:44 +0000 (14:50 -0500)]
When connect() succeeds immediately, don't invoke the callback immediately.

We need this to get unit tests to pass on freebsd.

14 years agoAdd some headers to fix freebsd compilation
Nick Mathewson [Thu, 18 Feb 2010 18:52:04 +0000 (13:52 -0500)]
Add some headers to fix freebsd compilation

14 years agoAdd the "compile" script to gitignore.
Nick Mathewson [Thu, 18 Feb 2010 18:50:15 +0000 (13:50 -0500)]
Add the "compile" script to gitignore.

14 years agoAdd a unit test for secure rng.
Nick Mathewson [Thu, 18 Feb 2010 06:43:37 +0000 (01:43 -0500)]
Add a unit test for secure rng.

Mostly, this is just to make sure our arc4random_buf() implementation isn't
dumb.

14 years agoFix getpid() usage on Windows
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.

14 years agoWhen working without a current event base, don't try to use IOCP listeners
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.

14 years agoConstruct Windows locks using InitializeCriticalSectionAndSpinCount
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.

14 years agoMerge branch 'arc4random'
Nick Mathewson [Thu, 18 Feb 2010 04:02:28 +0000 (23:02 -0500)]
Merge branch 'arc4random'

14 years agoAdd the arc4random.c license to the LICENSE file.
Nick Mathewson [Thu, 18 Feb 2010 03:54:43 +0000 (22:54 -0500)]
Add the arc4random.c license to the LICENSE file.

14 years agoFix two unlocked reads in evbuffer.
Nick Mathewson [Tue, 16 Feb 2010 02:03:52 +0000 (21:03 -0500)]
Fix two unlocked reads in evbuffer.

Some initializers (in evbuffer_read and evbuffer_commit) were reading
the last and/or previous_to_last fields without grabbing the evbuffer
lock.

This may fix a hard-to-trigger race condition or two.

14 years agoUpdate event-config.h version number to match configure.in
Nick Mathewson [Mon, 15 Feb 2010 22:53:24 +0000 (17:53 -0500)]
Update event-config.h version number to match configure.in

14 years agoMerge commit 'niels/http_close_connection'
Nick Mathewson [Mon, 15 Feb 2010 22:07:26 +0000 (17:07 -0500)]
Merge commit 'niels/http_close_connection'

14 years agoIncrement the submicro version number.
Nick Mathewson [Mon, 15 Feb 2010 21:45:19 +0000 (16:45 -0500)]
Increment the submicro version number.

We've changed a couple of APIs introduced in 2.0.1-alpha, so it
behooves us to give high-needs apps (like Tor) a way to tell we've
done this.

Sensible apps will just say "is it 2.0.3-alpha or 2.0.4-alpha" and
ignore the existence of 2.0.3-alpha-dev, which is just as it should
be.

14 years agovalidate close cb on server when client connection closes
Niels Provos [Sun, 14 Feb 2010 01:04:17 +0000 (17:04 -0800)]
validate close cb on server when client connection closes

14 years agoclean up terminate_chunked test
Niels Provos [Sun, 14 Feb 2010 00:59:37 +0000 (16:59 -0800)]
clean up terminate_chunked test

14 years agoMake RNG work when we have arc4random() but not arc4random_buf()
Nick Mathewson [Sat, 13 Feb 2010 05:11:44 +0000 (00:11 -0500)]
Make RNG work when we have arc4random() but not arc4random_buf()

14 years agoUse off_t for the length parameter of evbuffer_add_file
Nick Mathewson [Sat, 13 Feb 2010 04:40:13 +0000 (23:40 -0500)]
Use off_t for the length parameter of evbuffer_add_file

14 years agoAdd an arc4random implementation for use by evdns
Nick Mathewson [Wed, 10 Feb 2010 22:19:18 +0000 (17:19 -0500)]
Add an arc4random implementation for use by evdns

Previously, evdns was at the mercy of the user for providing a good
entropy source; without one, it would be vulnerable to various
active attacks.

This patch adds a port of OpenBSD's arc4random() calls to Libevent
[port by Chris Davis], and wraps it up a little bit so we can use it
more safely.

14 years agoRemove the 'flags' argument from evdns_base_set_option()
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.

14 years agoAlways use our own gai_strerror() replacement.
Nick Mathewson [Fri, 5 Feb 2010 18:50:51 +0000 (13:50 -0500)]
Always use our own gai_strerror() replacement.

This is necessary if we have any errors that the platform gai_strerror()
doesn't know how to handle.

14 years agoAdd a check to make soure our EVUTIL_AI flags do not conflict with the native ones
Nick Mathewson [Fri, 5 Feb 2010 06:09:01 +0000 (01:09 -0500)]
Add a check to make soure our EVUTIL_AI flags do not conflict with the native ones

14 years agoMerge remote branch 'niels/http_chunk'
Nick Mathewson [Thu, 4 Feb 2010 15:15:39 +0000 (10:15 -0500)]
Merge remote branch 'niels/http_chunk'

14 years agoFix some additional -DUNICODE issues on win32.
Nick Mathewson [Thu, 4 Feb 2010 04:49:22 +0000 (23:49 -0500)]
Fix some additional -DUNICODE issues on win32.

Brodie's patch didn't catch the ones that were new since 1.4.

14 years agoMake Libevent 1.4.12 build on win32 with Unicode enabled.
Brodie Thiesfield [Thu, 4 Feb 2010 04:27:40 +0000 (23:27 -0500)]
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.

14 years agomake evhttp_send() safe against terminated connections, too
Niels Provos [Thu, 4 Feb 2010 00:54:18 +0000 (16:54 -0800)]
make evhttp_send() safe against terminated connections, too

14 years agoMerge remote branch 'niels/http_chunk'
Nick Mathewson [Wed, 3 Feb 2010 22:52:55 +0000 (17:52 -0500)]
Merge remote branch 'niels/http_chunk'

14 years agodo not fail while sending on http connections the client closed.
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.

14 years agoAdd the rest of the integer limits, and add a test for them.
Nick Mathewson [Wed, 3 Feb 2010 22:01:45 +0000 (17:01 -0500)]
Add the rest of the integer limits, and add a test for them.

14 years agoMerge remote branch 'github/http_listener'
Nick Mathewson [Wed, 3 Feb 2010 21:25:34 +0000 (16:25 -0500)]
Merge remote branch 'github/http_listener'

Conflicts:
http.c

14 years agoFunctions to view and manipulate rate-limiting buckets.
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.

14 years agoAdd EV_*_MAX macros to event2/util.h to expose limits for ev_* types.
Nick Mathewson [Wed, 3 Feb 2010 19:37:42 +0000 (14:37 -0500)]
Add EV_*_MAX macros to event2/util.h to expose limits for ev_* types.

14 years agoReduce windows header includes in our own headers.
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.

14 years agoFix a dumb typo in ev_intptr_t definitions.
Nick Mathewson [Wed, 3 Feb 2010 07:08:08 +0000 (02:08 -0500)]
Fix a dumb typo in ev_intptr_t definitions.

We said "#define ev_uintptr_t" twice instead of ever saying
"#define ev_intptr_t".

14 years agoAdd the msvc-generated .lib files to .gitignore.
Nick Mathewson [Wed, 3 Feb 2010 06:26:07 +0000 (01:26 -0500)]
Add the msvc-generated .lib files to .gitignore.

14 years agoRemove EVUTIL_CHECK_FMT.
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.

14 years agoDeprecate EVENT_FD and EVENT_SIGNAL.
Nick Mathewson [Wed, 3 Feb 2010 06:16:47 +0000 (01:16 -0500)]
Deprecate EVENT_FD and EVENT_SIGNAL.

These are old aliases for event_get_fd and event_get_signal, and they
haven't been the preferred way of doing things since 2.0.1-alpha.

For a while, we made them use struct event if it was included, but call
event_get_(fd|signal) if it wasn't.  This was entirely too cute.

14 years agoconst-ify a few more functions in event.h
Nick Mathewson [Tue, 2 Feb 2010 20:44:10 +0000 (15:44 -0500)]
const-ify a few more functions in event.h

14 years agoUpdate time-test.c to use event2
Nick Mathewson [Wed, 27 Jan 2010 06:47:36 +0000 (01:47 -0500)]
Update time-test.c to use event2

time-test.c wasn't crazy, but it used some old interfaces.

There are probably more cleanups and explanations to do beyond the
ones here.

14 years agoClarify status of example programs
Nick Mathewson [Wed, 27 Jan 2010 06:46:41 +0000 (01:46 -0500)]
Clarify status of example programs

(That is, add comments to say that dns-example and le-proxy are recent and
ugly; event-test is old and ugly.)

14 years agoAdd a new "hello world" sample program
Nick Mathewson [Wed, 27 Jan 2010 06:46:23 +0000 (01:46 -0500)]
Add a new "hello world" sample program

14 years agoTry to fix a warning in hash_debug_entry
Nick Mathewson [Tue, 26 Jan 2010 17:08:34 +0000 (12:08 -0500)]
Try to fix a warning in hash_debug_entry

Apparently some 64-bit platforms don't like it when you say

   unsigned hash(void *p)
   {
      return (unsigned)p;
   }

even if you really honestly don't want the high bits of p.  Perhaps
they will tolerate it if I say the equivalent of

   unsigned hash(void *p)
   {
      return (unsigned) (uintptr_t) p;
   }

14 years agoUse ev_[u]intptr_t types in place of [u]intptr_t
Nick Mathewson [Tue, 26 Jan 2010 17:08:17 +0000 (12:08 -0500)]
Use ev_[u]intptr_t types in place of [u]intptr_t

14 years agoAdd ev_[u]intptr_t to include/event2/util.h
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.

14 years agoTry to untangle the logic in server_port_flush().
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.

14 years agoNote a missing ratelim function
Nick Mathewson [Mon, 25 Jan 2010 18:54:14 +0000 (13:54 -0500)]
Note a missing ratelim function

14 years agoUse less memory for each entry in a hashtable
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.

14 years agoCall event_debug_unassign on internal events
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.

14 years agoAdd support for a "debug mode" to try to catch common errors.
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.

14 years agoRemove a needless include of rpc_compat.h
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.

14 years agoFix windows and msvc build
Nick Mathewson [Sun, 24 Jan 2010 01:07:05 +0000 (20:07 -0500)]
Fix windows and msvc build

14 years agoMinimize epoll_ctl calls by using changelist
Nick Mathewson [Sat, 16 Jan 2010 20:24:58 +0000 (15:24 -0500)]
Minimize epoll_ctl calls by using changelist

The logic here is a little complex, since epoll_add must used called exactly
when no events were previously set, epoll_mod must be used when any events
were previously set, and epoll_del only called when the removing all events.

14 years agoFix a number of warnings from gcc -pedantic
Nick Mathewson [Sat, 23 Jan 2010 21:38:36 +0000 (16:38 -0500)]
Fix a number of warnings from gcc -pedantic

14 years agoMake it compile under gcc --std=c89.
Nick Mathewson [Sat, 23 Jan 2010 21:23:45 +0000 (16:23 -0500)]
Make it compile under gcc --std=c89.

14 years agoCheck more internal event_add() calls for failure
Nick Mathewson [Fri, 22 Jan 2010 21:14:49 +0000 (16:14 -0500)]
Check more internal event_add() calls for failure

Most of these should be unable to fail, since adding a timeout
generally always works.  Still, it's better not to try to be "too
smart for our own good here."

There are some remaining event_add() calls that I didn't add checks
for; I've marked those with "XXXX" comments.

14 years agoDetect setenv/unsetenv; skip main/base_environ test if we can't fake them.
Nick Mathewson [Tue, 29 Dec 2009 21:38:03 +0000 (16:38 -0500)]
Detect setenv/unsetenv; skip main/base_environ test if we can't fake them.

Previously, we assumed that we would have setenv/unsetenv everywhere
but WIN32, where we could fake them with putenv.  This isn't so: some
other non-windows systems lack setenv/unsetenv, and some of them lack
putenv too.

The first part of the solution, then, is to detect setenv/unsetenv/
putenv from configure.in, and to fake setenv/unsetenv with putenv
whenever we have the latter but not one of the former.

But what should we do when we don't even have putenv?  We could do
elaborate tricks to manipulate the environ pointer, but since we're
only doing this for the unit tests, let's just skip the one test in
question that uses setenv/unsetenv.

14 years agoFix compilation of rate-limit code when threading support is disabled
Nick Mathewson [Fri, 22 Jan 2010 05:34:21 +0000 (00:34 -0500)]
Fix compilation of rate-limit code when threading support is disabled

14 years agoRemove some commented-out code in evutil
Nick Mathewson [Thu, 21 Jan 2010 06:51:40 +0000 (01:51 -0500)]
Remove some commented-out code in evutil

14 years agoDon't use a bind address for nameservers on loopback
Nick Mathewson [Wed, 20 Jan 2010 17:56:54 +0000 (12:56 -0500)]
Don't use a bind address for nameservers on loopback

If the user sets a bind address to use for nameservers, and a
nameserver happens to be on 127.0.0.1, the nameserver will generally
fail.  This patch alters this behavior so that the bind address is
only applied when the nameserver is on a non-loopback address.

14 years agoFunctions to access more fields of struct event.
Nick Mathewson [Tue, 19 Jan 2010 19:01:36 +0000 (14:01 -0500)]
Functions to access more fields of struct event.

Once event_assign() or event_new() had been called, there was no way
to get at a copy of the event's callback, callback argument, or
configured events.  This patch adds an accessor function for each, and
an all-fields accessor for code that wants to re-assign one field of
an event.

This patch also adds a function to return sizeof(struct event), so
that code with intense RAM needs can still retain ABI compatibility
between versions of Libevent without having to heap-allocate every
struct event individually.

The code here was first proposed by Pavel Pisa.

14 years agoAdd a LICENSE file so people can find our license easily
Nick Mathewson [Tue, 19 Jan 2010 18:55:53 +0000 (13:55 -0500)]
Add a LICENSE file so people can find our license easily

For what it's worth, we are aware that "Copyright $YEAR $NAME" is
sufficient notice of copyright on software under US law and
Internationally, and saying Copyright (c) $YEAR $NAME is a bit nutty.
The character sequence (c) has never been ruled to have the same force
in US law as the actual copyright symbol, and that neither of these
US-specific symbols adds anything of value beyond saying "Copyright"
since the Berne convention took effect in the US back in 1989.

Similarly, saying "all rights reserved" doesn't do anything magical
unless your software goes in a time-warp back to when the Buenos Aires
Convention was the general rule.  (And what will they run it on back
then?)  And what would even lead you to say "All Rights Reserved" when
you're explicitly granting most of those rights to anybody receiving
the work in accordance with the 3-clause BSD license?

But still the FOSS community retains these ritual notations out of a
kind of cargo-cult lawyering.  Who knows?  Perhaps one day, if we
write our copyright notices ineptly enough, John Frum will come and
give us a DFSG-compatible license that everybody can get behind.

(Also, I am not a lawyer.  The above should not be taken as legal
advice.  -- Nick)

14 years agoAdd a forgotten header (changelist-internal.h)
Nick Mathewson [Fri, 15 Jan 2010 15:26:25 +0000 (10:26 -0500)]
Add a forgotten header (changelist-internal.h)

14 years agoMerge commit 'niels/http_dns'
Nick Mathewson [Fri, 15 Jan 2010 04:28:16 +0000 (23:28 -0500)]
Merge commit 'niels/http_dns'

14 years agoforgot to add void to test function
Niels Provos [Fri, 15 Jan 2010 01:39:54 +0000 (17:39 -0800)]
forgot to add void to test function

14 years agoadd a test for evhttp_connection_base_new with a dns_base
Niels Provos [Fri, 15 Jan 2010 01:05:00 +0000 (17:05 -0800)]
add a test for evhttp_connection_base_new with a dns_base

14 years agomove dns utility functions into a separate file so that we can use them for http...
Niels Provos [Fri, 15 Jan 2010 00:53:25 +0000 (16:53 -0800)]
move dns utility functions into a separate file so that we can use them for http testing

14 years agodo not use a function to assign the evdns base; instead assign it via evhttp_connecti...
Niels Provos [Thu, 14 Jan 2010 23:42:07 +0000 (15:42 -0800)]
do not use a function to assign the evdns base; instead assign it via evhttp_connection_base_new() which is a new function introduced in 2.0

14 years agoRemove kqueue->pend_changes.
Nick Mathewson [Thu, 14 Jan 2010 22:04:08 +0000 (17:04 -0500)]
Remove kqueue->pend_changes.

Since we're no longer writing directly to it from add/del, we don't
need to worry about it changing as kq_dispatch releases the lock.  We
would make it a local variable, except that we wouldn't want to malloc
and free it all the time.

14 years agoMake kqueue use changelists.
Nick Mathewson [Thu, 14 Jan 2010 21:31:05 +0000 (16:31 -0500)]
Make kqueue use changelists.

This fixes a bug in kqueue identified by Charles Kerr and various
Transmission users, where adding and deleting an event in succession
would make the event get reported, even if we didn't actually want to
see it.

Of course, this also makes the array of changes passed to kevent
smaller, which could help performance.

14 years agoChangelist code to defer event changes until just before dispatch
Nick Mathewson [Thu, 14 Jan 2010 21:30:40 +0000 (16:30 -0500)]
Changelist code to defer event changes until just before dispatch

This is necessary or useful for a few reasons:

    1) Sometimes applications will add and delete the same event more
       than once between calls to dispatch.  Processing these changes
       immediately is needless, and potentially expensive (especially
       if we're on a system that makes one syscall per changed event).

       Yes, this actually happens in practice for nonpathological
       code, such as in cases where the user's callback conditionally
       re-adds a non-persistent event, or where draining a buffer
       turns off writing and invokes a user callback which adds more
       data which in turn re-enabled writing.

    2) Sometimes we can coalesce multiple changes on the same fd into
       a single syscall if we know about them in advance.  For
       example, epoll can do an add and a delete at the same time, but
       only if we have found out about both of them before we tell
       epoll.

    3) Sometimes adding an event that we immediately delete can cause
       unintended consequences: in kqueue, this makes pending events
       get reported spuriously.

14 years agoMake http use evconnlistener.
Nick Mathewson [Wed, 30 Dec 2009 05:41:03 +0000 (00:41 -0500)]
Make http use evconnlistener.

Now that we have a generic listen-on-a-socket mechanism, there's no
longer any reason to have a separate listen-on-a-socket implementation
in http.c.

This also lets us use IOCP and AcceptEx() when they're enabled.

Possibly, we should have a new mechanism to add a socket given only a
listener.

14 years agoAllow http connections to use evdns for hostname looksups.
Nick Mathewson [Wed, 30 Dec 2009 05:11:27 +0000 (00:11 -0500)]
Allow http connections to use evdns for hostname looksups.

This was as simple as using bufferevent_connect_hostname instead of
calling connect() ourself, which already knows how to use an
evdns_base if it gets one.

Untangling the bind code might be a little trickier.

14 years agoMore unit tests for getaddrinfo_async: v4timeout and cancel.
Nick Mathewson [Thu, 14 Jan 2010 19:46:16 +0000 (14:46 -0500)]
More unit tests for getaddrinfo_async: v4timeout and cancel.

One covers the case where the v4 request times out but the v6 request
doesn't.  The other makes sure that cancelling a request actually works.

14 years agoFix test.sh on shells without echo -n
Nick Mathewson [Tue, 12 Jan 2010 20:58:36 +0000 (15:58 -0500)]
Fix test.sh on shells without echo -n

Some systems have a version of /bin/sh whose builtin echo doesn't
support the -n option used in test/test.sh.  /bin/echo, however,
usually does.  This patch makes us use /bin/echo for echo -n whenever
it is present.

Also, our use of echo -n really only made sense when suppressing all
test output.  Since test output isn't suppressed when logging to a
file, this pach makes us stop using echo -n when logging to a file.

14 years agoAdd a comment on evthread_enable_lock_debuging.
Nick Mathewson [Tue, 12 Jan 2010 01:47:36 +0000 (20:47 -0500)]
Add a comment on evthread_enable_lock_debuging.

14 years agoAdd unit-test for bad_request bug fixed in 1.4 recently.
Pavel Plesov [Tue, 12 Jan 2010 00:04:11 +0000 (19:04 -0500)]
Add unit-test for bad_request bug fixed in 1.4 recently.

This is a partial forward-port from 4fd2dd9d83a000b6.  There's no need
to forward-port the bugfix, since the test passes with http.c as-is.
I believe we fixed this while we were porting evhttp to bufferevent.
--nickm

14 years agoComestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_inv...
Jardel Weyrich [Wed, 30 Dec 2009 21:24:39 +0000 (19:24 -0200)]
Comestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_invoke_user_cb() and iocp_listener_enable().

14 years agoImproved error handling in evconnlistener_new_async(). Also keeping the fd open becau...
Jardel Weyrich [Wed, 30 Dec 2009 21:22:23 +0000 (19:22 -0200)]
Improved error handling in evconnlistener_new_async(). Also keeping the fd open because it is not opened by this function, so the caller is responsible for closing it. Additionally, since evconnlistener_new_bind() creates a socket and passes it to the function above, it required error checking to close the same socket.

14 years agoFixed a fd leak in start_accepting(), plus cosmetic changes
Jardel Weyrich [Wed, 30 Dec 2009 21:09:14 +0000 (19:09 -0200)]
Fixed a fd leak in start_accepting(), plus cosmetic changes

14 years agoFixed a memory leak on windows threads implementation. The CRITICAL_SECTION was not...
Jardel Weyrich [Fri, 1 Jan 2010 06:13:05 +0000 (04:13 -0200)]
Fixed a memory leak on windows threads implementation. The CRITICAL_SECTION was not being free'd in evthread_win32_lock_free().

14 years agoLook at the proper /etc/hosts file on windows.
Nick Mathewson [Fri, 8 Jan 2010 09:02:19 +0000 (04:02 -0500)]
Look at the proper /etc/hosts file on windows.

This is harder than it might initially seem, since the proper filename
depends on what the admin has decided to call the windows system directory,
which for all we know might be Q:\tralfamidore\slartibartfast.  And of course,
this being windows, there are twelve ways to do it, where you can pick a
nice one or a portable one, but not a really nice portable one.

14 years agoevdns_getaddrinfo() now supports the /etc/hosts file.
Nick Mathewson [Mon, 7 Dec 2009 22:21:41 +0000 (17:21 -0500)]
evdns_getaddrinfo() now supports the /etc/hosts file.

The regular blocking evutil_getaddrinfo() already supported /etc/hosts
by falling back to getaddrinfo() or gethostbyname().  But
evdns_getaddrinfo() had no such facility.  Now it does.

The data structure here isn't very clever.  I guess people with huge
/etc/hosts files will either need to get out of the 1980s, or submit a
patch to this code so that it uses a hashtable instead of a linked
list.

Includes basic unit tests.

14 years agoRefactor code from evdns into a new internal "read a file" function.
Nick Mathewson [Mon, 7 Dec 2009 22:21:13 +0000 (17:21 -0500)]
Refactor code from evdns into a new internal "read a file" function.

14 years agoEnable branch-prediction hints with EVUTIL_UNLIKELY.
Nick Mathewson [Wed, 6 Jan 2010 23:41:46 +0000 (18:41 -0500)]
Enable branch-prediction hints with EVUTIL_UNLIKELY.

This had been accidentally disabled.  Since it seems to work with GCC, I'm
turning it back on when GCC is present.

14 years agoFix byte counts when mixing deferred and non-deferred evbuffer callbacks.
Nick Mathewson [Wed, 6 Jan 2010 23:42:59 +0000 (18:42 -0500)]
Fix byte counts when mixing deferred and non-deferred evbuffer callbacks.

This patch finishes 390e0561, which was somehow committed in a half-finished
state.  It solves a failing unit test on windows.

14 years agoMerge branch 'ratelimit'
Nick Mathewson [Wed, 6 Jan 2010 22:59:44 +0000 (17:59 -0500)]
Merge branch 'ratelimit'

Conflicts:
bufferevent_async.c

14 years agoEradicated the last free() call. Let mm_free() take care of deallocation.
Jardel Weyrich [Wed, 30 Dec 2009 07:03:54 +0000 (05:03 -0200)]
Eradicated the last free() call. Let mm_free() take care of deallocation.

14 years agoFix compilation of rate-limiting code on win32.
Nick Mathewson [Wed, 30 Dec 2009 19:29:56 +0000 (14:29 -0500)]
Fix compilation of rate-limiting code on win32.

14 years agoFix test-ratelim compilation on Linux.
Nick Mathewson [Wed, 30 Dec 2009 18:50:52 +0000 (13:50 -0500)]
Fix test-ratelim compilation on Linux.

I'd forgotten to include time.h, and to link against libm.

14 years agoNever believe that we have pthreads on win32, even if gcc thinks we do.
Nick Mathewson [Wed, 30 Dec 2009 16:58:36 +0000 (11:58 -0500)]
Never believe that we have pthreads on win32, even if gcc thinks we do.

Apparently some newer versions of mingw provide a fake pthreads api to
let applications work even if they don't know about windows threading.
That's nice, but we aren't one of those.

14 years agoFix crash bugs when a bufferevent's eventcb is not set.
Nick Mathewson [Wed, 30 Dec 2009 00:50:03 +0000 (19:50 -0500)]
Fix crash bugs when a bufferevent's eventcb is not set.

In many places throughout the code, we called _bufferevent_run_eventcb
without checking whether the eventcb was actually set.  This would
work fine when the bufferevent's callbacks were deferred, but
otherwise the code would segfault.  Strangely, we always remembered to
check before calling the _bufferevent_run_{read,write}cb functions.

To prevent similar errors in the future, all of
_buferevent_run_{read,write,event}cb now check to make sure the
callback is actually set before invoking or deferring the callback.
This patch also removes the now-redundant checks for {read,write}cb.

14 years agoWhitespace fixes in test.sh
Nick Mathewson [Tue, 29 Dec 2009 23:11:52 +0000 (18:11 -0500)]
Whitespace fixes in test.sh

14 years agoAllow test.sh to be run as ./test/test.sh
Nick Mathewson [Tue, 29 Dec 2009 23:07:51 +0000 (18:07 -0500)]
Allow test.sh to be run as ./test/test.sh