37 Commits

Author SHA1 Message Date
Nick Mathewson
29151e65b7 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.
2010-01-06 18:42:59 -05:00
Nick Mathewson
390e056152 Fix up behavior of never-defered callbacks a little 2009-12-22 15:52:12 -05:00
Nick Mathewson
0cd3bb9f3a Improved optional lock debugging.
There were a couple of places in the code where we manually kept lock
counts to make sure we never accessed resources without holding a
lock, and that we never released a lock we didn't have.  The
lock-debugging code already puts counts on _every_ lock when lock
debugging is enabled, so there is no need to keep these counts around
otherwise.  This patch rewrites the ASSERT_FOO_LOCKED macros to all
use a common EVLOCK_ASSERT_LOCKED().

We also teach the lock debugging code to keep track of who exactly
holds each lock, so that EVLOCK_ASSERT_LOCKED() means "locked by this
thread."
2009-11-27 17:36:51 -05:00
Nick Mathewson
76cd2b70bb Stop passing EVTHREAD_READ and EVTHREAD_WRITE to non-rw locks.
Previously, our default lock model kind of assumed that every lock was
potentially a read-write lock.  This was a poor choice, since
read-write locks are far more expensive than regular locks, and so the
lock API should only use them when we can actually take advantage of
them.  Neither our pthreads or win32 lock implementation provided rw
locks.

Now that we have a way (not currently used!) to	indicate that we
really want a read-write lock, we shouldn't actually say "lock this
for reading" or "lock this for writing" unless we mean it.
2009-11-27 17:36:51 -05:00
Nick Mathewson
d7d1f1da09 Move responsibility for IOCP callback into bufferevent_async.
This patch from Chris Davis saves some callback depth, and adds proper
ref-counting to bufferevents when there's a deferred evbuffer callback
inflight.  It could use a couple more comments to really nail down what
its invariants are.

svn:r1543
2009-11-17 20:31:09 +00:00
Nick Mathewson
2e36dbe1a6 Use EVUTIL_ASSERT() consistently instead of assert.
svn:r1464
2009-10-26 20:00:43 +00:00
Nick Mathewson
b812563a6e Add a note that we should change previous_to_last to last_with_space
svn:r1447
2009-10-16 13:20:16 +00:00
Nick Mathewson
e3fd294a6d Spelling fixes in comments and strings.
svn:r1445
2009-10-16 13:19:57 +00:00
Nick Mathewson
b06b2649b4 Make "deferred callback queue" independent of event_base.
This way, we can more easily have an IOCP bufferevent implementation
that does not need an event_base at all.  Woot.

svn:r1381
2009-07-26 01:29:39 +00:00
Nick Mathewson
0b22ca1929 Use ev_ssize_t in place of ssize_t *everywhere*.
svn:r1309
2009-05-22 19:11:48 +00:00
Nick Mathewson
8997f234f2 Use the native "struct iovec" as our "struct evbuffer_iovec" when available, so we do not need to copy more pointers than necessary.
svn:r1299
2009-05-21 20:59:00 +00:00
Nick Mathewson
23243b8a98 Replace reserve/commit with new iovec-based interface. Add a new evbuffer_peek.
svn:r1296
2009-05-19 21:39:35 +00:00
Nick Mathewson
dc4c7b9570 Change the interface of evbuffer_add_reference: give the cleanup function more info.
svn:r1294
2009-05-15 22:44:18 +00:00
Nick Mathewson
e865eb938c More msvc build tweaks.
svn:r1262
2009-05-01 00:54:14 +00:00
Nick Mathewson
838d0a81c3 Document many internal functions and pieces of code.
svn:r1181
2009-04-17 06:55:08 +00:00
Nick Mathewson
93d4f884aa Make buffer iocp stuff compile happily
svn:r1174
2009-04-14 20:11:10 +00:00
Nick Mathewson
9f1a94ecec add pin/unpin functions, and a deref-and-free pair.
svn:r1165
2009-04-13 03:06:47 +00:00
Nick Mathewson
dcda7915ac Add a reference count to evbuffers.
svn:r1164
2009-04-13 03:06:27 +00:00
Nick Mathewson
829b52b6c1 Refactor the code that sets up iovecs for reading into its own function. iocp needs this.
svn:r1162
2009-04-13 03:05:46 +00:00
Nick Mathewson
b29b875d84 Facility to make evbuffers get their callbacks deferred.
svn:r1154
2009-04-10 20:43:08 +00:00
Nick Mathewson
747331d164 Add freeze support to evbuffers.
From the documentation:
   Prevent calls that modify an evbuffer from succeeding. A buffer may
   frozen at the front, at the back, or at both the front and the back.

   If the front of a buffer is frozen, operations that drain data from
   the front of the buffer, or that prepend data to the buffer, will
   fail until it is unfrozen.   If the back a buffer is frozen, operations
   that append data from the buffer will fail until it is unfrozen.

We'll use this to ensure correctness on an evbuffer when we're waiting
for an overlapped IO call to finish.

svn:r1143
2009-04-08 03:04:39 +00:00
Nick Mathewson
d9086fc007 Add a new facility to "pin" the memory in an evbuffer chain.
For overlapped IO (and possibly other stuff) we need to be able to
label an evbuffer_chain as "pinned", meaning that every byte in it
must remain at the same address as it is now until it unpinned. This
differs from being "immutable": it is okay to add data to the end
of a pinned chain, so long as existing data is not moved.

svn:r1142
2009-04-08 03:03:59 +00:00
Nick Mathewson
60e0d59b33 Add locking to evbuffers.
svn:r1134
2009-04-05 02:44:17 +00:00
Nick Mathewson
f1b1bad415 Make the new evbuffer callbacks use a new struct-based interface.
The old interface would fail pretty hard when we had to batch up
multiple adds and drains in a single call.

svn:r1131
2009-04-03 14:27:03 +00:00
Nick Mathewson
98b7046b97 A few more comments on evbuffer-internal structures.
svn:r1106
2009-02-10 19:38:43 +00:00
Nick Mathewson
8d3a10f8f1 Support temporarily suspending an evbuffer callback. This is different from disabling the callback, since we want to process changes, but not just yet.
svn:r1091
2009-02-01 01:43:58 +00:00
Nick Mathewson
b85b710cf5 Update copyright statements to reflect the facts that:
a) this is 2009
b) niels and nick have been comaintainers for a while
c) saying "all rights reserved" when you then go on to explicitly
   disclaim some rights is sheer cargo-cultism.

svn:r1065
2009-01-27 22:34:36 +00:00
Nick Mathewson
8889a77039 Replace all use of config.h with event-config.h.
svn:r1064
2009-01-27 22:30:46 +00:00
Niels Provos
fdf694933c sendfile/mmap and memory reference implementation for evbuffers
svn:r1057
2009-01-27 06:05:38 +00:00
Nick Mathewson
81dd04a726 Add a "flags" field to evbuffer callbacks.
For now, there is just one: enabled.  This lets us avoid lots of
mallocs/frees/tailq-manipulations just to turn a callback on and off.
The revised bufferevent code wants this.

svn:r1047
2009-01-23 18:04:34 +00:00
Nick Mathewson
de7f7a84a3 Remove in_callbacks check: allow full recursion in evbuffer callbacks. If you get yourself in an infinite loop, that's not our fault. Note this in the docs. Also reindent some docs now that my tabs match Niels's.
svn:r1046
2009-01-23 18:03:45 +00:00
Nick Mathewson
c735f2b45a Code to allow multiple callbacks per evbuffer.
svn:r1042
2009-01-23 01:11:13 +00:00
Nick Mathewson
6d3ed0657d Simplify evbuffer_write logic: combine nearly all of WSASend and writev cases.
svn:r1004
2009-01-14 14:58:48 +00:00
Nick Mathewson
3ca22aa837 r19739@catbus: nickm | 2008-05-14 23:05:03 -0400
Use our offsetof; do not rely on platform offsetof


svn:r825
2008-05-15 03:05:10 +00:00
Niels Provos
193c06a7ed fix a bug in which evbuffer_add_vfprintf would loop forever; avoid
fragmentation in evbuffer_expand by increasing the size of the last buffer
in the chain; as a result with have to keep track of the previous_to_last
chain;   provide a evbuffer_validate() function in the regression test to
make sure that all evbuffer are internally consistent.


svn:r699
2008-03-31 02:04:34 +00:00
Nick Mathewson
0322ce0a3b r18486@catbus: nickm | 2008-02-28 13:35:53 -0500
Make offsetof into evutil_offsetof.  Be a little more willing to call evbuffer_chain_align() from evbuffer_expand().  Clarify some docs, and add some XXX comments to note questionable areas.


svn:r677
2008-02-28 18:36:03 +00:00
Niels Provos
5c70ea4c9d improved code for evbuffer; avoids memcpy
svn:r674
2008-02-28 02:47:43 +00:00