1371 Commits

Author SHA1 Message Date
Nick Mathewson
da1718b289 Fix a locking bug in event_base_loop()
We previously were releasing the lock when we exited the main loop
in some ways, but not in others.
2009-11-27 17:36:51 -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
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
Nick Mathewson
e1ffbb82e3 Fix memory-leak of signal handler array with kqueue.
It turns out that kqueue_dealloc wasn't calling evsig_dealloc()
(because it doesn't use the main signal handler logic) so the sh_old
array was leaking.

This patch also introduces a fix in evsig_dealloc() where we set
the sh_old array to NULL when we free it, so that main/fork can pass.
2009-11-21 23:57:44 -05:00
Nick Mathewson
07e9e9b4b1 Parenthesize macro arguments more aggressively 2009-11-20 16:50:55 -05:00
Nick Mathewson
f32b57505e Add a warning about the use of event_initialized. 2009-11-20 16:38:01 -05:00
Nick Mathewson
91fe23fc08 Tolerate code that returns from a fatal_cb.
Also, replace more abort() calls with EVUTIL_ASSERT() or event_errx.
2009-11-20 15:46:04 -05:00
Nick Mathewson
94d00651f4 Add stub header for 2.0.4-alpha changelog. 2009-11-20 12:56:29 -05:00
Nick Mathewson
0af10d5695 Add more people who wrote patches to the acknowledgments
The names came from grepping ChangeLog for 'patch/code from/by'.
2009-11-20 12:47:21 -05:00
Nick Mathewson
0b4272681f Improve the README with more information and links.
(Also, try to test out the new commit script.)
2009-11-20 12:37:47 -05:00
Nick Mathewson
ba3407142b Add a .gitignore file.
.gitignore plays the same role in Git as the svn:ignore property does in
subversion.
2009-11-20 12:17:14 -05:00
Niels Provos
505040a2b5 call it 2.0.3-alpha
svn:r1556
2009-11-20 00:18:35 +00:00
Niels Provos
f169153956 Remove most calls to event_err() in http and deal with memory errors instead
svn:r1555
release-2.0.3-alpha
2009-11-19 23:08:50 +00:00
Niels Provos
986500de4d nick found a race condition in the pthreads test case
svn:r1554
2009-11-19 22:02:33 +00:00
Niels Provos
b8f222e055 On FreeBSD and other OSes, connect can return ECONREFUSED immediately; instead of failing the function call, pretend with faileld in the callback.
svn:r1553
2009-11-19 21:14:31 +00:00
Nick Mathewson
bdfe72f3c5 Documentation adjustments
svn:r1552
2009-11-19 00:21:48 +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
f070a4aed2 Do the proper hack for the (Open)BSD getaddrinfo quirk.
From evutil.c:

   Some older BSDs (like OpenBSD up to 4.6) used to believe that
   giving a numeric port without giving an ai_socktype was verboten.
   We test for this so we can apply an appropriate workaround.  If it
   turns out that the bug is present, then:

    - If nodename==NULL and servname is numeric, we build an answer
      ourselves using evutil_getaddrinfo_common().

    - If nodename!=NULL and servname is numeric, then we set
      servname=NULL when calling getaddrinfo, and post-process the
      result to set the ports on it.

   We test for this bug at runtime, since otherwise we can't have the
   same binary run on multiple BSD versions.

svn:r1550
2009-11-18 23:18:55 +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
cf749e227c Add a temporary workaround for an ssl bug found on FreeBSD.
Basically, we only want to report the 'connected' event because of
the socket connect() finishing when we have an actual socket
bufferevent; on an SSL bufferevent, 'connected' means 'SSL
connection finished.'

This isn't FreeBSD's fault: it just has a connect() that tends to
succeed pretty early.

svn:r1548
2009-11-18 21:16:53 +00:00
Nick Mathewson
9bf124bff6 Build correctly with mm replacement turned off.
svn:r1547
2009-11-18 21:16:47 +00:00
Nick Mathewson
767eb70f50 Fix compilation with threading disabled.
svn:r1546
2009-11-18 21:16:33 +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
201d8d0baf Clarify even more about various system-specific problems with getaddrinfo
svn:r1542
2009-11-17 18:29:44 +00:00
Nick Mathewson
9151d000e6 Use the common-case code from getaddrinfo_common *always*; OS differences are just too huge.
svn:r1541
2009-11-17 03:36:43 +00:00
Nick Mathewson
3451c870da Never pass our weird flags to the system getaddrinfo. Make sure there is no overlap between flag values.
svn:r1540
2009-11-17 02:57:32 +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
f9de8670fd Fix a declaration of __func__ in rpcgen.
svn:r1535
2009-11-16 22:23:06 +00:00
Nick Mathewson
18a8cfac39 Prefer calloc(a,b) to malloc(a*b). via openbsd.
svn:r1531
2009-11-15 19:00:12 +00:00
Nick Mathewson
629a613398 When running set[ug]id, don't check the environment.
Idea from OpenBSD, but made a bit more generic to handle uncivilized lands
that do not define issetugid.

svn:r1530
2009-11-15 18:59:59 +00:00
Nick Mathewson
e2b2de79bf Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD
svn:r1528
2009-11-15 18:59:48 +00:00
Nick Mathewson
c79a45e009 Fix a couple of event_debug calls.
svn:r1527
2009-11-14 21:54:30 +00:00
Nick Mathewson
74871cacb8 Change event_base.activequeues to "array of eventlist".
Previously, event_base.activequeues was of type "array of pointers to
eventlist."  This was pointless: none of the eventlists were allowed
to be NULL.  Worse, it was inefficient:

  - It made looking up an active event queue take two pointer
    deferences instead of one, thus risking extra cache misses.
  - It used more RAM than it needed to, because of the extra pointer
    and the malloc overhead.

Also, this patch fixes a bug where we were saying
calloc(N,N*sizeof(X)) instead of calloc(N,sizeof(X)) when allocating
activequeues.  That part, I'll backport.

Also, we warn and return -1 on failure to allocate activequeues,
rather than calling event_err.

svn:r1525
2009-11-09 19:37:27 +00:00
Nick Mathewson
cdf58009fc Change an OOM err to a warn in event_tagging.c
svn:r1524
2009-11-09 19:37:21 +00:00
Nick Mathewson
26573d3de3 Change an err to a warn in bufferevent_openssl
svn:r1523
2009-11-09 19:37:15 +00:00
Nick Mathewson
37e23f806b Patch from Ryan Phillips: accept ipv6 addresses returned by getaddrinfo in http.c
svn:r1522
2009-11-09 18:50:20 +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
e88079a82c Make persistent timeouts more accurate.
Previously, if the user scheduled a persistent timeout for {1,0}, we
would schedule the first one at "now+one second", and then when we
were about to run its callback, we would schedule it again for one
second after that.  This would introduce creeping delays to the event
that was supposed to run every second.

Now, we schedule the event for one second after it was _last
scheduled_.  To do this, we introduce internal code to add an event at
an _absolute_ tv rather than at now+tv.

svn:r1520
2009-11-09 18:30:57 +00:00
Nick Mathewson
59be8942c9 Make sure that common timeouts are inserted in-order.
This code should be a no-op, except under strange thread contention
situations.

svn:r1519
2009-11-09 18:30:48 +00:00
Nick Mathewson
ab96b5f3f5 Add an option to disable the timeval cache.
svn:r1518
2009-11-09 18:30:33 +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
4d48cf61a2 Fix kqueue.c build on GNU/kFreeBSD systems.
Yes, some people like to have a BSD-family kernel (thus getting
kqueue) with a GNU-family libc (thus occasionally mandating
_GNU_SOURCE).

Thanks to Debian for noticing this.

svn:r1514
2009-11-06 21:13:25 +00:00
Nick Mathewson
5ec43fe446 Fix a miscalculated realloc() size in win32select.c.
This bug was introduced by the code to make the backend able to safely release the base lock while calling select().

Also, we change win32select.c to the same 32-fds-to-start default as the rest of the backends, so that the main/many_events test can test it.  It was at 64-to-start, so the test wasn't hitting it.

svn:r1513
2009-11-06 17:12:39 +00:00
Nick Mathewson
ae5fbf492f Actually add the new dns-example.c code. :p
svn:r1512
2009-11-05 22:24:21 +00:00
Nick Mathewson
d2e7e65d21 Move the evdns sample code into the sample directory and fix it not to use any deprecated APIs.
svn:r1511
2009-11-05 22:19:09 +00:00