1632 Commits

Author SHA1 Message Date
Nick Mathewson
cda56abf19 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.
2010-03-31 12:50:32 -04:00
Nick Mathewson
c87272b7b9 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.
2010-03-26 14:51:39 -04:00
Nick Mathewson
5c0ebb33f4 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.)
2010-03-26 14:50:45 -04:00
Nick Mathewson
2014ae4ac6 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.
2010-03-26 14:30:14 -04:00
Nick Mathewson
6f20492fa2 Fix a free(NULL) in minheap-internal.h 2010-03-26 14:20:10 -04:00
Nick Mathewson
a5276180b7 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().
2010-03-26 13:56:01 -04:00
Nick Mathewson
7204b91666 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.
2010-03-26 13:46:29 -04:00
Patrick Galbraith
e1e703d2f5 Make evutil_signal_active() match declaration. 2010-03-23 16:04:59 -04:00
Trond Norbye
3eb044d0a9 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)
2010-03-23 13:27:10 -04:00
Nick Mathewson
7960af5113 Merge branch 'build' 2010-03-22 13:37:39 -04:00
Nick Mathewson
9eb2fd75be Use dist_bin_SCRIPTS, not EXTRA_DIST, to distribute scripts 2010-03-22 13:27:47 -04:00
Jardel Weyrich
83986414b0 Fix infrequent memory leak in bufferevent_init_common(). 2010-03-21 13:34:32 -04:00
Nick Mathewson
b557b175c0 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.
2010-03-21 13:28:48 -04:00
Nick Mathewson
fb366c1d88 Functions to track the total bytes sent over a rate limit group. 2010-03-21 13:16:31 -04:00
Nick Mathewson
33874b0528 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.
2010-03-16 13:37:15 -04:00
Nick Mathewson
657d1b6d3f Set mem_offset for every bufferevent type 2010-03-13 01:06:57 -05:00
Nick Mathewson
0cf1431e5d 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
2010-03-13 01:04:30 -05:00
Nick Mathewson
274a7bd9a1 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
2010-03-13 00:56:07 -05:00
Nick Mathewson
859af6772c 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
2010-03-13 00:53:54 -05:00
Nick Mathewson
68dc742bf1 Fix a write of uninitialized RAM in regression tests
Not actually harmful, but not something we should be doing.

Found by valgrind.
2010-03-13 00:31:14 -05:00
Nick Mathewson
b34abf3069 Do not close(-1) when freeing an uninitialized socket bufferevent 2010-03-13 00:31:14 -05:00
Nick Mathewson
70a44b61bb 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.
2010-03-13 00:31:14 -05:00
Nick Mathewson
75018951ec 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.
2010-03-13 00:30:34 -05:00
Nick Mathewson
0d047c3f11 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.
2010-03-13 00:29:15 -05:00
Nick Mathewson
f1bc125eb4 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.
2010-03-13 00:28:50 -05:00
Nick Mathewson
77c917ded0 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."
2010-03-12 14:37:54 -05:00
Nick Mathewson
0794b0d29c Remove an orphaned RELEASE flag in Makefile.am 2010-03-12 14:21:52 -05:00
Nick Mathewson
2e898f542b 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.
2010-03-12 14:16:30 -05:00
Nick Mathewson
b660edf9db 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.
2010-03-12 13:22:47 -05:00
Nick Mathewson
426c8fbe93 Support the standard 'make check' target in place of 'make verify'
Based on patch 2816088 from Zack Weinberg
2010-03-12 13:09:28 -05:00
Nick Mathewson
6c83e6c972 Merge branch 'evbuffer_insert_point' 2010-03-12 12:26:06 -05:00
Nick Mathewson
ee41aca63e 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.
2010-03-12 00:47:39 -05:00
Nick Mathewson
cdd4c4905b Try to comment some of the event code more 2010-03-12 00:38:50 -05:00
Nick Mathewson
17da042db6 Add some glass-box tests for the last_with_data code. 2010-03-11 15:39:44 -05:00
Nick Mathewson
1e7b986827 Fix last_with_data compilation on windows 2010-03-11 14:23:02 -05:00
Nick Mathewson
78772c3503 Clarify Christopher Clark's status as writer of original ht code. 2010-03-11 00:18:02 -05:00
Nick Mathewson
e470ad3c35 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.
2010-03-10 23:39:30 -05:00
Nick Mathewson
6f47bd12ed Remove previous_to_last from evbuffer 2010-03-10 23:28:51 -05:00
Nick Mathewson
c8ac57f1f5 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.
2010-03-10 23:24:14 -05:00
Nick Mathewson
2a6d2a1e4b 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.
2010-03-10 22:16:14 -05:00
Nick Mathewson
c7f1b820fc Merge branch 'evport' 2010-03-10 21:21:33 -05:00
Nick Mathewson
b2f2be6edc 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.
2010-03-10 16:25:16 -05:00
Brodie Thiesfield
13e4f3bd89 Avoid errors in http.c when building with VC 2003 .NET 2010-03-08 13:46:48 -05:00
Brodie Thiesfield
b677032ba2 Avoid errors in evutil.c when building with _UNICODE defined 2010-03-08 13:46:04 -05:00
Nick Mathewson
2c2618d858 more whitespace normalization 2010-03-05 13:00:15 -05:00
Nick Mathewson
c7cf6f0049 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.
2010-03-05 12:47:46 -05:00
Nick Mathewson
38b7b571c8 Add Christopher Clark and Maxim Yegorushkin to the LICENSE file 2010-03-04 01:42:04 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
cc1600afef 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.
2010-03-03 16:45:32 -05:00
Nick Mathewson
2fac0f70a3 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.
2010-03-03 12:15:15 -05:00