1505 Commits

Author SHA1 Message Date
Shuo Chen
755fbf16c3 Add void* arguments to request_new and reply_new evrpc hooks
This makes evprc setup more extensible, and helps with Shuo Chen's
work on implementing Google protocol buffers rpc on top of Libevent 2
evrpc.

This patch breaks binary compatibility with previous versions of
Libevent, since it changes struct evrpc and the signature of
evrpc_register_generic().  Since all compliant code should be calling
evrpc_register_generic via EVRPC_REGISTER, it shouldn't break source
compatibility.

(Code by Shuo Chen; commit message by Nick)
2010-04-14 14:27:29 -04:00
Shuo Chen
07edf784fa Expose the request and reply members of rpc_req_generic()
This code adds two accessor functions to evprc, and helps integrate
evrpc with Google protocol buffers.

(Code by Shuo Chen; commit message by nickm)
2010-04-14 14:23:03 -04:00
Nick Mathewson
a0983b67f9 Initialize last_with_datap correctly in evbuffer_overlapped
Fixes bug 2985406
2010-04-14 01:17:24 -04:00
Giuseppe Scrivano
3cbca8661f Create shared libraries under Windows 2010-04-13 02:01:04 -04:00
Giuseppe Scrivano
10c4c90450 Do not inhibit automake dependencies generation
It fixes make parallel builds.
2010-04-13 02:01:04 -04:00
Giuseppe Scrivano
d469c503c5 Fix compiler warnings under WIN32 2010-04-13 02:00:58 -04:00
Nick Mathewson
ab30e553c4 Merge branch 'evbuffer_copyout' 2010-04-13 01:46:29 -04:00
Nick Mathewson
eb86c8c5ff Add evbuffer_copyout to copy data from an evbuffer without draining
The evbuffer_remove() function copies data from the front of an
evbuffer into an array of char, and removes the data from the buffer.
This function behaves the same, but does not remove the data.  This
behavior can be handy for lots of protocols, where you want the
evbuffer to accumulate data until a complete record has arrived.

Lots of people have asked for a function more or less like this, and
though it isn't too hard to code one from evbuffer_peek(), it is
apparently annoying to do it in every app you write.  The
evbuffer_peek() function is significantly faster, but it requires that
the user be able to handle data in separate extents.

This patch also reimplements evbufer_remove() as evbuffer_copyout()
followed by evbuffer_drain().  I am reasonably confident that this
won't be a performance hit: the memcpy() overhead should dominate the
cost of walking the list an extra time.
2010-04-13 01:42:01 -04:00
Christopher Davis
fd90274056 Merge branch 'safetimevalms' 2010-04-10 11:26:53 -07:00
Christopher Davis
8f9e60c825 Always round up when there's a fractional number of msecs. 2010-04-09 19:16:09 -07:00
Nick Mathewson
819f949f4a Limit the maximum number of events on each socket to 65535
This lets us use less RAM for the evmap_io structure, which in turn
can let us have fewer cache misses for evmap operations.
2010-04-09 19:16:49 -04:00
Nick Mathewson
99210dd9e0 Merge branch 'comment' 2010-04-09 19:14:25 -04:00
Nick Mathewson
c247adc79c Add a few more evmap/changelist comments 2010-04-09 19:09:34 -04:00
Nick Mathewson
1234b95a75 Test another case of evbuffer_prepend 2010-04-09 17:19:39 -04:00
Nick Mathewson
8c83e99579 Add more unit tests for evbuffer_expand 2010-04-09 16:40:53 -04:00
Nick Mathewson
06a4443abe Unit-test every evbuffer_add_file() implementation.
Previously, we'd only test the default one, even if the others were still
compiled in.
2010-04-09 15:28:26 -04:00
Christopher Davis
28bfed47e2 Clean up a mistake in pointer manipulation in evbuffer_remove 2010-04-02 19:08:32 -04:00
Christopher Davis
850c3ff232 Add evutil_tv_to_msec for safe conversion of timevals to milliseconds.
This is useful for backends that require their timeout values be in
milliseconds.
2010-03-31 23:38:34 -07:00
Nick Mathewson
d5ebcf370d 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.
2010-03-31 12:53:20 -04:00
Nick Mathewson
45068a312c Fix a memory leak when appending/prepending to a buffer with unused space. 2010-03-31 12:53:20 -04:00
Nick Mathewson
8e227b04da 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.
2010-03-31 12:52:57 -04:00
Nick Mathewson
96865c4783 Turn the increasingly complex *_CHAIN() macros into functions 2010-03-31 12:50:32 -04:00
Nick Mathewson
b7442f8e83 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.
2010-03-31 12:50:32 -04:00
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