622 Commits

Author SHA1 Message Date
Pavel Plesov
6cc79c6b40 Add unit-test for bad_request bug fixed in 1.4 recently.
This is a partial forward-port from 4fd2dd9d83a000b6.  There's no need
to forward-port the bugfix, since the test passes with http.c as-is.
I believe we fixed this while we were porting evhttp to bufferevent.
--nickm
2010-01-11 19:04:11 -05:00
Nick Mathewson
72dd666777 evdns_getaddrinfo() now supports the /etc/hosts file.
The regular blocking evutil_getaddrinfo() already supported /etc/hosts
by falling back to getaddrinfo() or gethostbyname().  But
evdns_getaddrinfo() had no such facility.  Now it does.

The data structure here isn't very clever.  I guess people with huge
/etc/hosts files will either need to get out of the 1980s, or submit a
patch to this code so that it uses a hashtable instead of a linked
list.

Includes basic unit tests.
2010-01-08 19:36:37 -05:00
Nick Mathewson
ba2945f931 Merge branch 'ratelimit'
Conflicts:
	bufferevent_async.c
2010-01-06 17:59:44 -05:00
Nick Mathewson
165d30e31a Fix compilation of rate-limiting code on win32. 2009-12-30 14:29:56 -05:00
Nick Mathewson
885b42734c Fix test-ratelim compilation on Linux.
I'd forgotten to include time.h, and to link against libm.
2009-12-30 13:50:52 -05:00
Nick Mathewson
0b151a9fa1 Whitespace fixes in test.sh 2009-12-29 18:11:52 -05:00
Nick Mathewson
7dfbe94aa3 Allow test.sh to be run as ./test/test.sh 2009-12-29 18:07:51 -05:00
Nick Mathewson
c382de6421 Allow the user to redirect the verbose output of test/test.sh to a file
By default, the test.sh script still suppresses the output of all the
tests it invokes.  Now, however, you can have that output written to
a file specified in the TEST_OUTPUT_FILE shell variable.
2009-12-29 17:59:55 -05:00
Nick Mathewson
1e56a32d08 Make the initial nameserver probe timeout configurable.
When we decide that a nameserver is down, we stop sending queries to
it, except to periodically probe it to see if it has come back up.
Our previous probe sechedule was an ad-hoc and hard-wired "10 seconds,
one minute, 5 minues, 15 minutes, 1 hour, 1 hour, 1 hour...".  There
was nothing wrong with having it be ad-hoc, but making it hard-wired
served no good purpose.

Now the user can set the initial timeout via a new
"initial-probe-timeout:" option; future timeouts back off by a factor
of 3 on every failure to a maximum of 1 hour.

As a side-benefit, this lets us cut the runtime of the dns/retry test
from about 40 seconds to about 3 seconds.  Faster unit tests are
always a good thing.
2009-12-29 16:04:16 -05:00
Nick Mathewson
f0c0124e60 Testing code for bufferevent rate-limiting.
This is not part of the regression tests, since running it necessarily
takes a while.  There is a new test-ratelim test; run it with '-h'
for an argument to see its options.
2009-12-28 16:58:22 -05:00
Nick Mathewson
4a5b53432b Do not ignore bufferevent_enable(EV_READ) before bufferevent_connect().
Previously, we weren't remembering that we wanted to re-add the read
event once the connect was finished.  Now we are.
2009-12-23 07:48:43 -05:00
unknown
c51bb3c342 Fix a few locking issues on windows. 2009-12-21 16:36:40 -05:00
Sebastian Hahn
70cdfe49fa Fix compile on Snow Leopard with gcc warnings enabled 2009-12-06 02:59:19 +01:00
Nick Mathewson
7ae94450fd Fix a snow leopard compile warning in the unit tests.
Reported by Sebastian Hahn.
2009-12-04 16:37:47 -05:00
unknown
31687b4d8a Fix regress_iocp.c usage of old lock allocation macros. 2009-12-02 01:22:07 -05:00
Nick Mathewson
d84d8385cd Fix two use-after-free bugs in unit tests spoted by lock debugging 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
986500de4d nick found a race condition in the pthreads test case
svn:r1554
2009-11-19 22:02:33 +00:00
Nick Mathewson
7511b6a97c Fix a spelling error and remove some dead code
svn:r1551
2009-11-19 00:21:38 +00:00
Nick Mathewson
07ce7f9991 Make our failing-connection bufferevent test more tolerant.
I thought we had a way to do connect() that would never fail
immediately, but always wait for a moment before failing.  It
turns out that on FreeBSD it can fail immediately.  This is not
FreeBSD's fault, or even a real bug anywhere but in the unit test.

svn:r1549
2009-11-18 21:17:00 +00:00
Nick Mathewson
9bf124bff6 Build correctly with mm replacement turned off.
svn:r1547
2009-11-18 21:16:47 +00: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
625a261a53 OpenBSD demands that sys/types.h be included before sys/socket.h
svn:r1539
2009-11-17 02:40:14 +00:00
Nick Mathewson
888007f9a4 Windows *does* have getservbyname, no matter what autoconf says.
TODO: figure out why autoconf is confused about this.

svn:r1538
2009-11-17 02:38:19 +00:00
Nick Mathewson
86f5742015 Add two implementations of getaddrinfo: one blocking and one nonblocking.
The entry points are evutil_getaddrinfo and evdns_getaddrinfo respectively.
There are fairly extensive unit tests.

I believe this code conforms to RFC3493 pretty closely, but there are
probably more issues.  It should get tested on more platforms.

This code means we can dump the well-intentioned but weirdly-implemented
bufferevent_evdns and evutil_resolve code.

svn:r1537
2009-11-16 22:25:46 +00:00
Nick Mathewson
72bafc175a Remove the stupid brokenness where DNS option names needed to end with a
colon.

svn:r1536
2009-11-16 22:23:55 +00:00
Nick Mathewson
c79a45e009 Fix a couple of event_debug calls.
svn:r1527
2009-11-14 21:54:30 +00:00
Nick Mathewson
b2fe4aedaa Unit tests for got_break and got_exit.
svn:r1521
2009-11-09 18:36:34 +00:00
Nick Mathewson
693c24ef9d Implement queued timeouts for case where many timeouts are the same.
Libevent's current timeout code is relatively optimized for the
randomly scattered timeout case, where events are added with their
timeouts in no particular order.  We add and remove timeouts with
O(lg n) behavior.

Frequently, however, an application will want to have many timeouts
of the same value.  For example, we might have 1000 bufferevents,
each with a 2 second timeout on reading or writing.  If we knew this
were always the case, we could just put timeouts in a queue and get
O(1) add and remove behavior.  Of course, a queue would give O(n)
performance for a scattered timeout pattern, so we don't want to
just switch the implementation.

This patch gives the user the ability to explicitly tag certain
timeout values as being "very common".  These timeout values have a
cookie encoded in the high bits of their tv_usec field to indicate
which queue they belong on.  The queues themselves are each
triggered by an entry in the minheap.

See the regress_main.c code for an example use.

svn:r1517
2009-11-09 17:16:30 +00:00
Nick Mathewson
784b8773a4 We do not work any more without an event-config.h; stop pretending that it is meaningful to check for HAVE_CONFIG_H
svn:r1516
2009-11-06 21:46:57 +00:00
Nick Mathewson
ac633aebdf Fix some build warnings on MSVC, mostly related to signed/unsigned comparisons.
svn:r1510
2009-11-05 21:22:23 +00:00
Nick Mathewson
4ca9efeaef Add nmake files to build with MSVC.
Right now, they just make static libraries and unit tests.  They probably set lots of options wrong.

svn:r1507
2009-11-05 20:40:11 +00:00
Nick Mathewson
25a5e6819d Build fixes for MSVC
svn:r1506
2009-11-05 20:37:19 +00:00
Nick Mathewson
47bad8abb7 Implement size limits on HTTP header length and body length.
Patch from Constantine Verutin, simplified a little.

svn:r1500
2009-11-04 20:17:32 +00:00
Nick Mathewson
86db1c851b Commit ConnectEx code to get connect working with async bufferevents.
This is code by Chris Davis, with changes to get the unit tests failing less aggressively.

The unit tests for this code do not completely pass yet; Chris is looking into that.  If they aren't passing by the next release, I'll turn off this code.

svn:r1499
2009-11-04 05:19:26 +00:00
Nick Mathewson
0b9eb1bffb Add a bufferevent function to resolve a name then connect to it.
This function, bufferevent_socket_connect_hostname() can either use
evdns to do the resolve, or use a new function (evutil_resolve) that
uses getaddrinfo or gethostbyname, like http.c does now.

This function is meant to eventually replace the hostname resolution mess in
http.c.

svn:r1496
2009-11-03 20:40:48 +00:00
Nick Mathewson
fcc7668c00 Fix one IOCP-callback signature I missed
svn:r1495
2009-11-03 20:05:06 +00:00
Nick Mathewson
0fd0255fa4 Remove compat/sys/_time.h
I've gone through everything that it declared to see where it was used,
and it seems that we probably don't need it anywhere.

Here's what it declared, and why I think we're okay dropping it.

o struct timeval {}
  (Used all over, and we can't really get away with declaring it ourselves;
  we need the same definition the system uses.  If we can't find struct
  timeval, we're pretty much sunk.)

o struct timespec {}
  (Used in event.c, evdns.c, kqueue.c, evport.c.  Of these,
   kqueue.c and event.c include sys/_time.h.  event.c conditions its use on
   _EVENT_HAVE_CLOCK_GETTIME, and kqueue() only works if timespec is defined.)

o TIMEVAL_TO_TIMESPEC
  (Used in kqueue.c, but every place with kqueue has sys/time.h)

o struct timezone {}
  (event2/util.h has a forward declaration; only evutil.c references it and
   doesn't look at its contents.)

o timerclear, timerisset, timercmp, timeradd, timersub
  (Everything now uses the evutil_timer* variants.)

o ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF, struct itemerval
  (These are only used in test/regress.c, which does not include _time.h)

o CLOCK_REALTIME
  (Only used in evdns.c, which does not include _time.h)

o TIMESPEC_TO_TIMEVAL
o DST_*
o timespecclear, timespecisset, timespeccmp, timespecadd, timespecsub
o struct clockinfo {}
o CLOCK_VIRTUAL, CLOCK_PROF
o TIMER_RELTIME, TIMER_ABSTIME
  (unused)

svn:r1494
2009-11-03 19:54:56 +00:00
Nick Mathewson
0aa6f5136a Fix remaining AcceptEx issues.
svn:r1492
2009-11-02 20:59:13 +00:00
Nick Mathewson
e794d716a3 Clean up acceptex code some more: add locking, single-threading, enable/disable.
svn:r1491
2009-11-02 20:20:40 +00:00
Nick Mathewson
9a772148f2 Compilation and correctness fixes for IOCP listener code.
svn:r1489
2009-11-02 19:31:29 +00:00
Nick Mathewson
8283b2f0dc Fix a major parenthesis bug in EVUTIL_UPCAST.
Fortunately, this didn't hurt anything previously, since we had no actual users of the macro where the offset of the base type wasn't 0.

svn:r1488
2009-11-02 19:30:25 +00:00
Nick Mathewson
5f1d6e640f Add more IOCP tests. They might not pass yet.
svn:r1487
2009-11-02 17:42:16 +00:00
Nick Mathewson
96c6956e02 Add a "many events" regression test.
This is a glass-box test to get more coverage on the event loop
backends.  We've run into bugs here before with fencepost errors, and
it turns out that none of our unit tests had enough events to
exercise the resize code.

Most of the backends have some kind of logic that resizes an array
when:
    - The highest fd is too high
    - The number of events added since the last iteration of the loop
      is too high
    - The number of active events is too high.

This test hits all 3 cases, and increases coverage in select.c by 7%,
in poll by 1%, and in kqueue by 9%.

svn:r1482
2009-10-30 22:43:30 +00:00
Nick Mathewson
9976f1e74c reformat weird indentation in dns tests
svn:r1478
2009-10-29 17:11:12 +00:00
Nick Mathewson
3c2198cb48 Unit test for reverse ipv6 lookup
svn:r1477
2009-10-29 17:10:36 +00:00
Nick Mathewson
5b3fb5bfa5 More documentation and unit tests for event_tagging.
svn:r1476
2009-10-29 16:35:20 +00:00
Nick Mathewson
c70c25937e Unit test for strlcpy
svn:r1474
2009-10-29 16:35:09 +00:00
Nick Mathewson
e9098203f7 Fix from Chris Davis: get error-logging to be happy on win32.
svn:r1473
2009-10-27 18:25:19 +00:00
Nick Mathewson
904b5721cb Avoid calling exit() during event_base_new*()
Previously, each of the three make-an-event-base functions would exit
under different, weird circumstances, but return NULL on others.
  - All three would exit on OOM sometimes.
  - event_base_new() and event_init() would die	if all backends	were
    disabled.
  - None of them would die if the socketpair() call failed.

Now, only event_init() exits on failure, and it exits on every kind of
failure.  event_base_new() and event_base_new_with_config() never do.

svn:r1472
2009-10-27 06:47:25 +00:00