506 Commits

Author SHA1 Message Date
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
Nick Mathewson
e9ee1057e6 Give event_assign a return value, and make it less inclined to exit().
We also refactor event_assign so that it is the core function, and
event_set() is only the wrapper.

svn:r1469
2009-10-27 04:25:45 +00:00
Nick Mathewson
ed0e91e02a New test flag to suppress logging for one test.
svn:r1466
2009-10-27 04:03:50 +00:00
Nick Mathewson
a8267663de API to replace all calls to exit() with a user-supplied fatal-error handler.
Also, add unit tests for logging.

svn:r1462
2009-10-26 19:59:51 +00:00
Nick Mathewson
38aec9ec7c Tweaks to IOCP interface.
svn:r1461
2009-10-23 22:38:35 +00:00
Nick Mathewson
7b10724901 Fix my fix for the bufferevent_connect_fail() test.
svn:r1460
2009-10-23 22:07:05 +00:00
Nick Mathewson
879420a711 Expose a narrow window to the IOCP code.
svn:r1459
2009-10-23 22:00:29 +00:00
Nick Mathewson
fdd11c00bb Make the bufferevent_connect_fail test faster on OSX.
It seems that connecting to a listener that is bound but not accepting
or listening doesn't give a 'connection refused' error on OSX, but
rather makes the connect() time out after 75 seconds.  I couldn't find
any way to make the timout shorter.  Fortunately, closing the listener
after a second or so makes the desired error occur after another
second or so.

svn:r1457
2009-10-21 19:21:05 +00:00
Nick Mathewson
4fbac2a5ae Test failing case of bufferevent_connect().
Code by Chris Davis.

svn:r1455
2009-10-21 07:00:19 +00:00
Nick Mathewson
5082546682 Fix windows compilation warnings.
svn:r1449
2009-10-21 02:14:16 +00:00
Nick Mathewson
ba8a17714e Do not notify the main thread more than needed.
Basically, we suppress the notification when an event is added or deleted
and:
  - The event has no fd, or there is no change in whether we are
    reading/writing on the event's fd.
  - The event has no timeout, or adding the event did not make the earliest
    timeout become earlier.

This should be a big efficiency win in applications with multiple threads and
lots of timeouts.

svn:r1439
2009-10-02 03:03:58 +00:00
Niels Provos
8e8d94a3e0 Do not drop data from evbuffer when out of memory; reported by Jacek Masiulaniec
svn:r1436
2009-09-24 22:18:19 +00:00
Nick Mathewson
d17c720c05 Remove an extraneous puts().
svn:r1415
2009-08-14 20:07:01 +00:00
Nick Mathewson
8a99083f01 Add an evbuffer_search_range() to search a bounded range of a buffer
This can be handy when you have	one search to find the end of a	header
section, and then you want to find a substring within the header
section without looking at the body.

svn:r1410
2009-08-07 17:16:52 +00:00
Nick Mathewson
0c09fe5ada Add a couple more evdns tests. Libevent is now, for me, at 80.02% coverage.
svn:r1409
2009-08-03 20:50:56 +00:00
Nick Mathewson
94e8f9b901 Another DNS unit tests, to handle reissues.
The evdns module is now up to ~72% coverage; Libevent is up to nearly 80%.

svn:r1408
2009-08-03 20:15:45 +00:00
Nick Mathewson
dc1f5b1ee0 why say fprintf(stdout, X) when you can say printf?
svn:r1407
2009-08-03 20:15:39 +00:00