168 Commits

Author SHA1 Message Date
Evan Jones
b63ab1776b EVUTIL_ASSERT: Use sizeof() to avoid "unused variable" warnings. 2010-12-14 00:14:07 -05:00
Nick Mathewson
bb0d2b4e85 Consistentize tabs 2010-12-09 11:47:54 -05:00
Nick Mathewson
7bcace2d54 Fix some irix compilation warnings spotted by Kevin Bowling 2010-11-22 21:02:34 -05:00
Nick Mathewson
a3245afec2 Fix win32 build in response to fixes from win64 build. 2010-11-01 14:23:33 -04:00
Nick Mathewson
545a61145c Fix even more win64 warnings: buffer, event_tagging, http, evdns, evrpc 2010-11-01 14:13:33 -04:00
Nick Mathewson
e4f34e8a0f Correct logic for realigning a chain in evbuffer_add
The old logic was both too eager to realign (it would move a whole
chain to save a byte) and too reluctant to realign (it would only
realign when data would fit into the misaligned portion, without
considering the space at the end of the chain).

The new logic matches that from evbuffer_expand_singlechain: it only
realigns a chain when not much data is to be moved, and there's a
bunch of space to be regained.

Spotted by Yan Lin.
2010-10-25 22:39:29 -04:00
Nick Mathewson
ac7e52d84d Make evbuffer_add_file take ev_off_t, not off_t
This change has no effect on non-windows platforms, since those
either define off_t to 64-bits, or allow you to decide whether
it should be 64-bits yourself via some LARGEFILE-like macro.

On Windows, however, off_t is always 32-bit, so it's a bad choice
for "file size" or "file offset" values.  Instead, I'm adding
an ev_off_t type, and using it in the one place where we used
off_t to mean "the size of a file" or "an offset into a file" in the
API.

This breaks ABI compatibility on Windows.
2010-10-25 14:29:30 -04:00
Nick Mathewson
6be589ae68 Fix signed/unsigned warnings on opensolaris, where iov_len is signed 2010-10-14 13:48:40 -04:00
Nick Mathewson
fdc640b02d Fix an EINVAL on evbuffer_write_iovec on OpenSolaris.
The writev() call is limited to at most IOV_MAX iovecs (or UIO_MAXIOV,
depending on whom you ask).  This isn't a problem anywhere we've
tested except on OpenSolaris, where IOV_MAX was a mere 16.

This patch makes us go from "use up to 128 iovecs when writing" to
"use up to 128 iovecs when writing, or IOV_MAX/UIO_MAXIOV, whichever
is less".  This is still wrong if you somehow find a platform that
defines IOV_MAX < UIO_MAXIOV, but I hereby claim that such a platform
is too stupid to worry about for now.

Found by Michael Herf.
2010-10-06 10:56:49 -04:00
Nick Mathewson
9c8db0f804 Fix all warnings in the main codebase flagged by -Wsigned-compare
Remember, the code
   int is_less_than(int a, unsigned b) {
      return a < b;
   }
is buggy, since the C integer promotion rules basically turn it into
   int is_less_than(int a, unsigned b) {
      return ((unsigned)a) < b;
   }
and we really want something closer to
   int is_less_than(int a, unsigned b) {
      return a < 0 || ((unsigned)a) < b;
   }
.

Suggested by an example from Ralph Castain
2010-09-23 22:45:55 -04:00
Christopher Davis
03afa209de IOCP-related evbuffer fixes.
- Prevent evbuffer_{add,prepend}_buffer from moving read-pinned chains.
- Fix evbuffer_drain to handle read-pinned chains better.
- Raise the limit on WSABUFs from two to MAX_WSABUFS for overlapped reads.
2010-09-08 01:22:21 -07:00
Nick Mathewson
743f866539 Honor NDEBUG; build without warnings with NDEBUG; make NDEBUG always-off in unit test code 2010-08-23 11:49:06 -04:00
Nick Mathewson
ec347b9225 Move event-config.h to include/event2
This change means that all required include files are in event2, and
all files not in event2/* are optional.
2010-08-06 20:21:27 -04:00
niks
65abdc2011 Fix wrong sie calculation of iovec buffers when exact=1
The old code had a bug where the 'exact' flag to 1 in
_evbuffer_read_setup_vecs would never actually make the iov_len field
of the last iovec get truncated.  This patch fixes that.
2010-07-16 09:11:09 -04:00
Nick Mathewson
3467f2fa3b Fix logic in correcting high values from FIONREAD
The old logic made sense back when buffer.c was an enormous linear
buffer, but it doesn't make any sense for the chain-based
implementation.

This patch also refactors the ioctl{socket}? call into its own function.
2010-05-28 15:05:32 -04:00
Nick Mathewson
c44de06c76 Numerous opensolaris compilation fixes
For future note, opensolaris doesn't have sys/sysctl.h, doesn't like
comparing iov_buf to a chain_space_ptr without a cast, and is (predictably)
unforgiving of dumb syntax errors.

Also, we had accidentally broken the devpoll backend test in configure.in
2010-05-08 19:34:09 -04:00
Nick Mathewson
dcdae6b743 Make evbuffer_add_file() work on windows
Right now only the add_file() mode is supported, when it would be
nicer to have mmap support.  Perhaps for Libevent 2.1.x.
2010-05-08 16:34:18 -04:00
Nick Mathewson
d49b92a835 Remove one last bug in last_with_datap logic. Found with valgrind 2010-04-23 23:04:20 -04:00
Giuseppe Scrivano
d469c503c5 Fix compiler warnings under WIN32 2010-04-13 02:00:58 -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
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
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
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
1e7b986827 Fix last_with_data compilation on windows 2010-03-11 14:23: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
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
b2fbeb3f07 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().
2010-02-22 15:38:23 -05:00
Nick Mathewson
e5bbd40ad7 Clean up formatting: use tabs, not 8-spaces, to indent. 2010-02-18 17:44:09 -05:00
Nick Mathewson
7116bf2314 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.
2010-02-15 21:11:41 -05:00
Nick Mathewson
3fe60fdf47 Use off_t for the length parameter of evbuffer_add_file 2010-02-12 23:40:13 -05:00
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
a47d88d7c2 Replace some cases of uint32_t with ev_uint32_t.
Spotted by Roman Puls.
2009-12-23 07:53:19 -05:00
Nick Mathewson
390e056152 Fix up behavior of never-defered callbacks a little 2009-12-22 15:52:12 -05:00
Nick Mathewson
438f9ed26c Add the abilitity to mark some buffer callbacks as never-deferred. 2009-12-04 14:15:17 -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
347952ffe0 Revise the locking API: deprecate the old locking callbacks and add trylock.
Previously, there was no good way to request different kinds of lock
(say, read/write vs writeonly or recursive vs nonrecursive), or for a
lock function to signal failure (which would be important for a
trylock mode).

This patch revises the lock API to be a bit more useful.  The older
lock calls are still supported for now.

We also add a debugging mode to catch common errors in using the
locking APIs.
2009-11-27 17:36:24 -05:00
Niels Provos
f169153956 Remove most calls to event_err() in http and deal with memory errors instead
svn:r1555
2009-11-19 23:08:50 +00:00