]> granicus.if.org Git - libevent/log
libevent
14 years agoClean up a mistake in pointer manipulation in evbuffer_remove
Christopher Davis [Fri, 2 Apr 2010 23:08:32 +0000 (19:08 -0400)]
Clean up a mistake in pointer manipulation in evbuffer_remove

14 years agoRewrite evbuffer_expand and its users
Nick Mathewson [Tue, 30 Mar 2010 20:47:37 +0000 (16:47 -0400)]
Rewrite evbuffer_expand and its users

The previous evbuffer_expand was not only incorrect; it was
inefficient too.  On all questions of time vs memory tradeoffs, it
chose to burn time in order to avoid wasting memory.  The new code
tries to be a little more balanced: it only resizes an existing chain
when doing so doesn't require too much copying, and when failing to do
so would waste a lot of the chain's space.

This patch also rewrites evbuffer_chain_insert to work properly with
last_with_datap, and adds a few convenience functions to buffer.c.

14 years agoFix a memory leak when appending/prepending to a buffer with unused space.
Nick Mathewson [Wed, 31 Mar 2010 16:03:43 +0000 (12:03 -0400)]
Fix a memory leak when appending/prepending to a buffer with unused space.

14 years agoMake the no_iovecs case of write_atmost compile
Nick Mathewson [Sat, 27 Mar 2010 04:09:25 +0000 (00:09 -0400)]
Make the no_iovecs case of write_atmost compile

Apparently nobody had tested it before on a system that had sendfile.
Why would you have sendfile and not writev?  Perhaps you're trying to
test the no-iovecs code to make sure it still works.

14 years agoTurn the increasingly complex *_CHAIN() macros into functions
Nick Mathewson [Tue, 30 Mar 2010 16:48:56 +0000 (12:48 -0400)]
Turn the increasingly complex *_CHAIN() macros into functions

14 years agoReplace last_with_data with a slightly smarter version
Nick Mathewson [Sat, 27 Mar 2010 03:18:40 +0000 (23:18 -0400)]
Replace last_with_data with a slightly smarter version

To implement evbuffer_expand() properly, you need to be able to
replace the last chunk that has data, which means that we need to keep
track of the the next pointer pointing to the last_with_data chunk,
not the last_with_data chunk itself.

14 years agoFix critical bug in evbuffer_write when writev is not available
Nick Mathewson [Wed, 31 Mar 2010 16:29:26 +0000 (12:29 -0400)]
Fix critical bug in evbuffer_write when writev is not available

evbuffer_pullup() returns NULL if you try to pull up more bytes than
are there.  But evbuffer_write_atmost would sometimes ask for more
bytes to be pulled up than it had, get a NULL, and fail.

14 years agoMake evbuffer_prepend handle empty buffers better
Nick Mathewson [Fri, 26 Mar 2010 18:51:39 +0000 (14:51 -0400)]
Make evbuffer_prepend handle empty buffers better

If the first chunk of a buffer is empty, and we're told to prepend to
the buffer, we should be willing to use the entire first chunk.
Instead, we were dependent on the value of chunk->misalign.

14 years agoDo not use evbuffer_expand() to add the first chain to a buffer
Nick Mathewson [Fri, 26 Mar 2010 18:50:45 +0000 (14:50 -0400)]
Do not use evbuffer_expand() to add the first chain to a buffer

(It's a big function, and using it this way is overkill.)

14 years agoIncrease MIN_BUFFER_SIZE to 512 (1024 on 64-bit)
Nick Mathewson [Fri, 26 Mar 2010 18:30:14 +0000 (14:30 -0400)]
Increase MIN_BUFFER_SIZE to 512 (1024 on 64-bit)

This constant decides the smallest (and typical) size of each evbuffer
chain.  Since this number includes sizeof(evbuffer_chain) overhead,
the old value (256) was just too low: on 64-bit platforms, it would
spend nearly 20% of the allocations on overhead.  The new values mean
that we'll be spending closer to 5% of evbuffer allocations on overhead.

It would be nice to get this number even lower if we can.

14 years agoFix a free(NULL) in minheap-internal.h
Nick Mathewson [Fri, 26 Mar 2010 18:20:10 +0000 (14:20 -0400)]
Fix a free(NULL) in minheap-internal.h

14 years agoFix minheap code to use replacement malloc functions
Nick Mathewson [Fri, 26 Mar 2010 17:56:01 +0000 (13:56 -0400)]
Fix minheap code to use replacement malloc functions

minheap-internal.h still had an extra realloc and an extra free that
needed to be replaced with mm_realloc and mm_free().

14 years agoRemove a needless min_heap_shift_up_() call
Nick Mathewson [Fri, 26 Mar 2010 17:46:29 +0000 (13:46 -0400)]
Remove a needless min_heap_shift_up_() call

Previously, every call to min_heap_shift_down_() would invoke
min_heap_shift_up_() at the end.  This used to be necessary in the
first version of the minheap code, since min_heap_erase() would call
min_heap_shift_down_() unconditionally.  But when patch 8b7a3b36763
from Marko Kreen fixed min_heap_erase() to be more sensible, we left
the weird behavior of min_heap_shift_down_() in place.

Fortunately, "cui" noticed this and reported it on Niels's blog.

14 years agoMake evutil_signal_active() match declaration.
Patrick Galbraith [Tue, 23 Mar 2010 20:04:59 +0000 (16:04 -0400)]
Make evutil_signal_active() match declaration.

14 years agoNever test for select() on windows
Trond Norbye [Tue, 23 Mar 2010 17:27:10 +0000 (13:27 -0400)]
Never test for select() on windows

On 64-bit windows, configure actually _finds_ select when it tests for
it, and due to the ordering of the io implementations in event.c it is
chosen over the win32select implementation.

This modification skips the test for select on win32 (we don't want
that anyway, because Windows has its own), causing my windows box to
get the win32select implementation.

(edited by Nick)

14 years agoMerge branch 'build'
Nick Mathewson [Mon, 22 Mar 2010 17:37:39 +0000 (13:37 -0400)]
Merge branch 'build'

14 years agoUse dist_bin_SCRIPTS, not EXTRA_DIST, to distribute scripts
Nick Mathewson [Mon, 22 Mar 2010 17:27:47 +0000 (13:27 -0400)]
Use dist_bin_SCRIPTS, not EXTRA_DIST, to distribute scripts

14 years agoFix infrequent memory leak in bufferevent_init_common().
Jardel Weyrich [Fri, 12 Mar 2010 09:04:56 +0000 (06:04 -0300)]
Fix infrequent memory leak in bufferevent_init_common().

14 years agoDetect and refuse reentrant event_base_loop() calls
Nick Mathewson [Sun, 21 Mar 2010 17:28:48 +0000 (13:28 -0400)]
Detect and refuse reentrant event_base_loop() calls

Calling event_base_loop on a base from inside a callback invoked by
that same base, or from two threads at once, has long been a way to
get exceedingly hard-to-diagnose errors.  This patch adds code to
detect such reentrant invocatinos, and exit quickly with a warning
that should explain what went wrong.

14 years agoFunctions to track the total bytes sent over a rate limit group.
Nick Mathewson [Sun, 21 Mar 2010 17:16:31 +0000 (13:16 -0400)]
Functions to track the total bytes sent over a rate limit group.

14 years agoMake 'main/many_events' test 70 fds, not 64.
Nick Mathewson [Tue, 16 Mar 2010 17:37:15 +0000 (13:37 -0400)]
Make 'main/many_events' test 70 fds, not 64.

This is mainly intended to ensure that we don't get hung up on
the 64-handle limit that lots of O(n) Windows functions (but FWICT
not select) like to enforce.

14 years agoSet mem_offset for every bufferevent type
Nick Mathewson [Sat, 13 Mar 2010 06:06:57 +0000 (01:06 -0500)]
Set mem_offset for every bufferevent type

14 years agoAvoid an (untriggerable so far) crash bug in bufferevent_free()
Nick Mathewson [Sat, 13 Mar 2010 06:04:30 +0000 (01:04 -0500)]
Avoid an (untriggerable so far) crash bug in bufferevent_free()

We were saying
     mm_free(bufev - bufev->be_ops->mem_offset);
when we should have said
     mm_free(((char*)bufev) - bufev->be_ops->mem_offset);

In other words, if mem_offset had ever been nonzero, then instead of
backing up mem_offset bytes to find the thing we were supposed to free, we
would have backed up mem_offset*sizeof(struct bufferevent) bytes, and freed
something completely crazy.

Spotted thanks to a conversation with Jardel Weyrich

14 years agoFix some memory leaks in the unit tests
Nick Mathewson [Sat, 13 Mar 2010 05:55:39 +0000 (00:55 -0500)]
Fix some memory leaks in the unit tests

These don't matter except inasmuch as they give real memory leaks
a place to hide.

Found with valgrind

14 years agoFree evdns_base->req_heads on evdns_base_free
Nick Mathewson [Sat, 13 Mar 2010 05:53:54 +0000 (00:53 -0500)]
Free evdns_base->req_heads on evdns_base_free

It looks like when we moved from one big inflight-requests list to an
n-heads structure, we didn't make evdns_base_free() free the array of
heads.  This patch should fix that.

Found with valgrind

14 years agoFix a write of uninitialized RAM in regression tests
Nick Mathewson [Sat, 13 Mar 2010 01:38:25 +0000 (20:38 -0500)]
Fix a write of uninitialized RAM in regression tests

Not actually harmful, but not something we should be doing.

Found by valgrind.

14 years agoDo not close(-1) when freeing an uninitialized socket bufferevent
Nick Mathewson [Fri, 12 Mar 2010 23:36:18 +0000 (18:36 -0500)]
Do not close(-1) when freeing an uninitialized socket bufferevent

14 years agoAvoid a spurious close(-1) on Linux
Nick Mathewson [Fri, 12 Mar 2010 23:35:15 +0000 (18:35 -0500)]
Avoid a spurious close(-1) on Linux

On Linux, we use only one fd to do main-thread signaling (since we have
eventfd()), so we don't need to close th_notify_fd[1] as we would if we were
using a socketpair.

14 years agoFix a possible double-free bug in SSL bufferevents with CLOSE_ON_FREE
Nick Mathewson [Sat, 13 Mar 2010 05:23:06 +0000 (00:23 -0500)]
Fix a possible double-free bug in SSL bufferevents with CLOSE_ON_FREE

With CLOSE_ON_FREE set, we were telling the BIO to free the bufferevent when
it was closed, and also freeing it ourselves.

14 years agoFix an obnoxious typo in the bufferevent_timeout_filter test
Nick Mathewson [Sat, 13 Mar 2010 05:29:15 +0000 (00:29 -0500)]
Fix an obnoxious typo in the bufferevent_timeout_filter test

We were using the same bufferevent as the child of two filtering parents,
orphaning another.  This made one get freed twice, and the other not at all.

Possible fix for bug 2963306 spotted by Doug Cuthbertson.

14 years agoImprove robustness for refcounting
Nick Mathewson [Sat, 13 Mar 2010 04:00:49 +0000 (23:00 -0500)]
Improve robustness for refcounting

Document that we do intend to double-decref underlying bufferevents under
some circumstances.  Check to make sure that we don't decref past 0.

14 years agoGive a better warning for bad automake versions.
Nick Mathewson [Fri, 12 Mar 2010 19:37:54 +0000 (14:37 -0500)]
Give a better warning for bad automake versions.

If you tried to build with automake-1.6 or earlier, we would
previously spit out pages and pages of garbage output.  Now, automake
should just say "Hey, I'm not new enough for this."

14 years agoRemove an orphaned RELEASE flag in Makefile.am
Nick Mathewson [Fri, 12 Mar 2010 19:21:52 +0000 (14:21 -0500)]
Remove an orphaned RELEASE flag in Makefile.am

14 years agoSwitch to using AM conditionals in place of AC_LIBOBJ
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.

14 years agoRemove redundant stuff from EXTRA_DIST
Nick Mathewson [Fri, 12 Mar 2010 18:22:47 +0000 (13:22 -0500)]
Remove redundant stuff from EXTRA_DIST

To a first approximation, sources that are mentioned anywhere in an
automake file don't need to get mentioned in EXTRA_DIST.

14 years agoSupport the standard 'make check' target in place of 'make verify'
Nick Mathewson [Fri, 12 Mar 2010 18:09:28 +0000 (13:09 -0500)]
Support the standard 'make check' target in place of 'make verify'

Based on patch 2816088 from Zack Weinberg

14 years agoMerge branch 'evbuffer_insert_point'
Nick Mathewson [Fri, 12 Mar 2010 17:26:06 +0000 (12:26 -0500)]
Merge branch 'evbuffer_insert_point'

14 years agoFunctions to manipulate existing rate limiting groups.
Nick Mathewson [Fri, 12 Mar 2010 05:46:39 +0000 (00:46 -0500)]
Functions to manipulate existing rate limiting groups.

This patch adds a function to change the current rate limit of a rate
limiting group, and another to free an empty rate limiting group.

14 years agoTry to comment some of the event code more
Nick Mathewson [Thu, 11 Mar 2010 05:38:46 +0000 (00:38 -0500)]
Try to comment some of the event code more

14 years agoAdd some glass-box tests for the last_with_data code.
Nick Mathewson [Thu, 11 Mar 2010 20:39:44 +0000 (15:39 -0500)]
Add some glass-box tests for the last_with_data code.

14 years agoFix last_with_data compilation on windows
Nick Mathewson [Thu, 11 Mar 2010 19:23:02 +0000 (14:23 -0500)]
Fix last_with_data compilation on windows

14 years agoClarify Christopher Clark's status as writer of original ht code.
Nick Mathewson [Thu, 11 Mar 2010 05:18:02 +0000 (00:18 -0500)]
Clarify Christopher Clark's status as writer of original ht code.

14 years agoAllow evbuffer_read() to split across more than 2 iovecs
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.

14 years agoRemove previous_to_last from evbuffer
Nick Mathewson [Thu, 11 Mar 2010 04:28:51 +0000 (23:28 -0500)]
Remove previous_to_last from evbuffer

14 years agoUse last_with_data in place of previous_to_last
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.

14 years agoRevise evbuffer to add last_with_data
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.

14 years agoMerge branch 'evport'
Nick Mathewson [Thu, 11 Mar 2010 02:21:33 +0000 (21:21 -0500)]
Merge branch 'evport'

14 years agoMake evdns use the regular logging system by default
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.

14 years agoAvoid errors in http.c when building with VC 2003 .NET
Brodie Thiesfield [Mon, 8 Mar 2010 18:46:48 +0000 (13:46 -0500)]
Avoid errors in http.c when building with VC 2003 .NET

14 years agoAvoid errors in evutil.c when building with _UNICODE defined
Brodie Thiesfield [Mon, 8 Mar 2010 18:46:04 +0000 (13:46 -0500)]
Avoid errors in evutil.c when building with _UNICODE defined

14 years agomore whitespace normalization
Nick Mathewson [Fri, 5 Mar 2010 18:00:15 +0000 (13:00 -0500)]
more whitespace normalization

14 years agoReplace users of "int fd" with "evutil_socket_t fd" in portable code
Nick Mathewson [Fri, 5 Mar 2010 17:47:46 +0000 (12:47 -0500)]
Replace users of "int fd" with "evutil_socket_t fd" in portable code

Remeber, win32 has a socket type that's actually a handle, so if
there's a chance that code is run on win32, we can't use "int" as the
socket type.

This isn't a blind search-and-replace: sometimes an fd is really in
fact for a file, and not a socket at all.

14 years agoAdd Christopher Clark and Maxim Yegorushkin to the LICENSE file
Nick Mathewson [Thu, 4 Mar 2010 06:40:32 +0000 (01:40 -0500)]
Add Christopher Clark and Maxim Yegorushkin to the LICENSE file

14 years agoUpdate all our copyright notices to say "2010"
Nick Mathewson [Thu, 4 Mar 2010 06:25:51 +0000 (01:25 -0500)]
Update all our copyright notices to say "2010"

14 years agoImprove the speed of evbuffer_readln()
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.

14 years agoRemove signal_assign() and signal_new() macros.
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.

14 years agoVC has no getopt(), so do without in bench_http.
Christopher Davis [Tue, 2 Mar 2010 23:16:28 +0000 (15:16 -0800)]
VC has no getopt(), so do without in bench_http.

14 years agoGet bench_http to work on Windows; add a switch to enable IOCP.
Christopher Davis [Tue, 2 Mar 2010 22:34:30 +0000 (14:34 -0800)]
Get bench_http to work on Windows; add a switch to enable IOCP.

14 years agoRevert the broken part of 2cffd6c937
Nick Mathewson [Tue, 2 Mar 2010 03:12:04 +0000 (22:12 -0500)]
Revert the broken part of 2cffd6c937

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

14 years agoDistribute libevent.pc.in, not libevent.pc
Nick Mathewson [Tue, 2 Mar 2010 03:06:12 +0000 (22:06 -0500)]
Distribute libevent.pc.in, not libevent.pc

14 years agoBump version to 2.0.4-alpha-dev
Nick Mathewson [Sun, 28 Feb 2010 21:53:42 +0000 (16:53 -0500)]
Bump version to 2.0.4-alpha-dev

14 years agoBump the version to 2.0.4-alpha release-2.0.4-alpha
Nick Mathewson [Sun, 28 Feb 2010 17:55:29 +0000 (12:55 -0500)]
Bump the version to 2.0.4-alpha

14 years agoAdd a changelog for 2.0.4-alpha from Git, sorted by hand
Nick Mathewson [Sun, 28 Feb 2010 17:49:03 +0000 (12:49 -0500)]
Add a changelog for 2.0.4-alpha from Git, sorted by hand

14 years agoFix compilation with --disable-debug-mode
Nick Mathewson [Sun, 28 Feb 2010 17:52:39 +0000 (12:52 -0500)]
Fix compilation with --disable-debug-mode

14 years agoSmall cleanups on freebsd-connect-refused patch.
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.

14 years agodeal with connect() failing immediately
Niels Provos [Sun, 28 Feb 2010 02:59:06 +0000 (18:59 -0800)]
deal with connect() failing immediately

14 years agoFix arc4random compilation on MSVC.
Nick Mathewson [Thu, 25 Feb 2010 22:14:41 +0000 (17:14 -0500)]
Fix arc4random compilation on MSVC.

14 years agoTry to define a sane _EVENT_SIZEOF_SIZE_T for msvc compilation
Nick Mathewson [Thu, 25 Feb 2010 22:11:28 +0000 (17:11 -0500)]
Try to define a sane _EVENT_SIZEOF_SIZE_T for msvc compilation

14 years agoFix mingw compilation
Nick Mathewson [Thu, 25 Feb 2010 21:57:57 +0000 (16:57 -0500)]
Fix mingw compilation

14 years agoDelete stack-alloced event in new unit test before returning.
Nick Mathewson [Wed, 24 Feb 2010 18:40:06 +0000 (13:40 -0500)]
Delete stack-alloced event in new unit test before returning.

14 years agoUse new timeval diff comparison function in bufferevent test
Nick Mathewson [Wed, 24 Feb 2010 04:59:26 +0000 (23:59 -0500)]
Use new timeval diff comparison function in bufferevent test

14 years agoAdd test for periodic timers that get activated for other reasons
Nick Mathewson [Wed, 24 Feb 2010 04:55:32 +0000 (23:55 -0500)]
Add test for periodic timers that get activated for other reasons

This was already independently verified by the new bufferevent
timeout tests, but it's good to explicitly check that our code
does what it should.

14 years agoAdd a test for timeouts on filtering bufferevents.
Nick Mathewson [Tue, 23 Feb 2010 21:36:52 +0000 (16:36 -0500)]
Add a test for timeouts on filtering bufferevents.

14 years agoProvide consistent, tested semantics for bufferevent timeouts
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.

14 years agoFix a bug in resetting timeouts on persistent events when IO triggers.
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.

14 years agoFix some race conditions in persistent events and event_reinit
Nick Mathewson [Tue, 23 Feb 2010 20:14:57 +0000 (15:14 -0500)]
Fix some race conditions in persistent events and event_reinit

I found these by adding an EVENT_BASE_ASSERT_LOCKED() call to most
of the functions in event.c that can only be called while holding
the lock.

event_reinit() never grabbed the lock, but it needed to.

event_persist_closure accessed the base to call event_add_internal()
and gettime() when its caller had already dropped the lock.

event_pending() called gettime() without grabbing the lock.

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()