1371 Commits

Author SHA1 Message Date
Nick Mathewson
da6135e356 Reduce windows header includes in our own headers.
It turns out that absolutely everything that was including
windows.h was doing so needlessly; our headers don't need it,
so we should just include winsock2.h (since that's where
struct timeval is defined).

Pre-2.0 code will use the old headers, which include windows.h
for them, so we aren't breaking source compatibility with 1.4.

This solves the bug where we were leaving WIN32_LEAN_AND_MEAN
defined, in roughly the same way that buying an automobile
solves the question of what to give your coachman for boxing
day.
2010-02-03 02:09:19 -05:00
Nick Mathewson
27c9a40f15 Fix a dumb typo in ev_intptr_t definitions.
We said "#define ev_uintptr_t" twice instead of ever saying
"#define ev_intptr_t".
2010-02-03 02:08:08 -05:00
Nick Mathewson
e244a2ea74 Add the msvc-generated .lib files to .gitignore. 2010-02-03 01:26:59 -05:00
Nick Mathewson
6c21c895d9 Remove EVUTIL_CHECK_FMT.
This was never supposed to be an exposed API, so its name should have been
more like _EVUTIL_CHECK_FMT.  But it was only used in one place, so let's
just eliminate it.
2010-02-03 01:22:44 -05:00
Nick Mathewson
f6b269498a Deprecate EVENT_FD and EVENT_SIGNAL.
These are old aliases for event_get_fd and event_get_signal, and they
haven't been the preferred way of doing things since 2.0.1-alpha.

For a while, we made them use struct event if it was included, but call
event_get_(fd|signal) if it wasn't.  This was entirely too cute.
2010-02-03 01:16:47 -05:00
Nick Mathewson
d38a7a1931 const-ify a few more functions in event.h 2010-02-02 15:44:10 -05:00
Nick Mathewson
f4190bfb85 Update time-test.c to use event2
time-test.c wasn't crazy, but it used some old interfaces.

There are probably more cleanups and explanations to do beyond the
ones here.
2010-01-27 01:47:36 -05:00
Nick Mathewson
d60a1bd50c Clarify status of example programs
(That is, add comments to say that dns-example and le-proxy are recent and
ugly; event-test is old and ugly.)
2010-01-27 01:46:41 -05:00
Nick Mathewson
becb9f9cd3 Add a new "hello world" sample program 2010-01-27 01:46:23 -05:00
Nick Mathewson
137f2c602f Try to fix a warning in hash_debug_entry
Apparently some 64-bit platforms don't like it when you say

   unsigned hash(void *p)
   {
      return (unsigned)p;
   }

even if you really honestly don't want the high bits of p.  Perhaps
they will tolerate it if I say the equivalent of

   unsigned hash(void *p)
   {
      return (unsigned) (uintptr_t) p;
   }
2010-01-26 12:08:34 -05:00
Nick Mathewson
cef61a2f1b Use ev_[u]intptr_t types in place of [u]intptr_t 2010-01-26 12:08:17 -05:00
Nick Mathewson
1fa4c81c71 Add ev_[u]intptr_t to include/event2/util.h
We already emulate most of the other useful bits of stdint.h, and
we seem to have started to use uintptr_t in a few places throughout
the code.  Let's make sure we can continue to do so even on backwards
platforms that don't do C99.
2010-01-26 12:06:41 -05:00
Nick Mathewson
439aea0d07 Try to untangle the logic in server_port_flush().
The logic that prevented the first loop in this function from being
infinite was rather confusing and hard to follow.  It seems to confuse
some automatic analysis tools as well as me.  Let's try to replace it
with something more comprehensible.
2010-01-25 14:07:01 -05:00
Nick Mathewson
361da8f202 Note a missing ratelim function 2010-01-25 13:54:14 -05:00
Nick Mathewson
a66e947b8b Use less memory for each entry in a hashtable
Our hash-table implementation stored a copy of the hash code in each
element.  But as we were using it, all of our hash codes were
ridiculously easy to calculate: most of them were just a matter of a
load and a shift.

This patch lets ht-internal be built in either of two ways: one caches
the hash-code for each element, and one recalculates it each time it's
needed.

This patch also chooses a slightly better hash code for
event_debug_entry.
2010-01-25 13:53:17 -05:00
Nick Mathewson
a19b4a05e6 Call event_debug_unassign on internal events
I don't expect that many users will be so religious about calling
unassign, but we need to be so that it's at least possible to use
debug mode without eating memory.
2010-01-25 13:53:17 -05:00
Nick Mathewson
cd17c3acd5 Add support for a "debug mode" to try to catch common errors.
Right now it only catches cases where we aren't initializing events,
or where we are re-initializing events without deleting them first.
These are however shockingly common.
2010-01-25 13:53:13 -05:00
Nick Mathewson
70a4a3ef14 Remove a needless include of rpc_compat.h
Nothing in evrpc.c was using rpc_compat.h, so it's best to take it
out, especially since it polluted our build process with GCC variadic
macros.

While we're at it, this patch puts an extra restriction on when the
variadic macros in rpc_compat.h are defined.  Not only must GCC be the
compiler, but GCC must not be running in -ansi mode.
2010-01-23 23:12:29 -05:00
Nick Mathewson
5c7a7bca4c Fix windows and msvc build 2010-01-23 20:07:05 -05:00
Nick Mathewson
c8c6a8978e Minimize epoll_ctl calls by using changelist
The logic here is a little complex, since epoll_add must used called exactly
when no events were previously set, epoll_mod must be used when any events
were previously set, and epoll_del only called when the removing all events.
2010-01-23 17:02:11 -05:00
Nick Mathewson
918e9c5e72 Fix a number of warnings from gcc -pedantic 2010-01-23 16:38:36 -05:00
Nick Mathewson
e2ca403fae Make it compile under gcc --std=c89. 2010-01-23 16:23:45 -05:00
Nick Mathewson
ff3f6cd42b Check more internal event_add() calls for failure
Most of these should be unable to fail, since adding a timeout
generally always works.  Still, it's better not to try to be "too
smart for our own good here."

There are some remaining event_add() calls that I didn't add checks
for; I've marked those with "XXXX" comments.
2010-01-22 16:14:49 -05:00
Nick Mathewson
7296971b10 Detect setenv/unsetenv; skip main/base_environ test if we can't fake them.
Previously, we assumed that we would have setenv/unsetenv everywhere
but WIN32, where we could fake them with putenv.  This isn't so: some
other non-windows systems lack setenv/unsetenv, and some of them lack
putenv too.

The first part of the solution, then, is to detect setenv/unsetenv/
putenv from configure.in, and to fake setenv/unsetenv with putenv
whenever we have the latter but not one of the former.

But what should we do when we don't even have putenv?  We could do
elaborate tricks to manipulate the environ pointer, but since we're
only doing this for the unit tests, let's just skip the one test in
question that uses setenv/unsetenv.
2010-01-22 15:03:01 -05:00
Nick Mathewson
97a8c79006 Fix compilation of rate-limit code when threading support is disabled 2010-01-22 00:34:21 -05:00
Nick Mathewson
26e1b6f298 Remove some commented-out code in evutil 2010-01-21 01:51:40 -05:00
Nick Mathewson
8d4aaf9086 Don't use a bind address for nameservers on loopback
If the user sets a bind address to use for nameservers, and a
nameserver happens to be on 127.0.0.1, the nameserver will generally
fail.  This patch alters this behavior so that the bind address is
only applied when the nameserver is on a non-loopback address.
2010-01-20 12:56:54 -05:00
Nick Mathewson
0683950384 Functions to access more fields of struct event.
Once event_assign() or event_new() had been called, there was no way
to get at a copy of the event's callback, callback argument, or
configured events.  This patch adds an accessor function for each, and
an all-fields accessor for code that wants to re-assign one field of
an event.

This patch also adds a function to return sizeof(struct event), so
that code with intense RAM needs can still retain ABI compatibility
between versions of Libevent without having to heap-allocate every
struct event individually.

The code here was first proposed by Pavel Pisa.
2010-01-19 14:01:36 -05:00
Nick Mathewson
706700674c Add a LICENSE file so people can find our license easily
For what it's worth, we are aware that "Copyright $YEAR $NAME" is
sufficient notice of copyright on software under US law and
Internationally, and saying Copyright (c) $YEAR $NAME is a bit nutty.
The character sequence (c) has never been ruled to have the same force
in US law as the actual copyright symbol, and that neither of these
US-specific symbols adds anything of value beyond saying "Copyright"
since the Berne convention took effect in the US back in 1989.

Similarly, saying "all rights reserved" doesn't do anything magical
unless your software goes in a time-warp back to when the Buenos Aires
Convention was the general rule.  (And what will they run it on back
then?)  And what would even lead you to say "All Rights Reserved" when
you're explicitly granting most of those rights to anybody receiving
the work in accordance with the 3-clause BSD license?

But still the FOSS community retains these ritual notations out of a
kind of cargo-cult lawyering.  Who knows?  Perhaps one day, if we
write our copyright notices ineptly enough, John Frum will come and
give us a DFSG-compatible license that everybody can get behind.

(Also, I am not a lawyer.  The above should not be taken as legal
advice.  -- Nick)
2010-01-19 13:55:53 -05:00
Nick Mathewson
4b9f307d8d Add a forgotten header (changelist-internal.h) 2010-01-15 10:26:25 -05:00
Nick Mathewson
854645797b Merge commit 'niels/http_dns' 2010-01-14 23:28:16 -05:00
Niels Provos
78a50fe04c forgot to add void to test function 2010-01-14 17:39:54 -08:00
Niels Provos
26714ca19f add a test for evhttp_connection_base_new with a dns_base 2010-01-14 17:05:00 -08:00
Niels Provos
b8226390bc move dns utility functions into a separate file so that we can use them for http testing 2010-01-14 16:53:25 -08:00
Niels Provos
5032e52680 do not use a function to assign the evdns base; instead assign it via evhttp_connection_base_new() which is a new function introduced in 2.0 2010-01-14 15:42:07 -08:00
Nick Mathewson
3225dfb91d Remove kqueue->pend_changes.
Since we're no longer writing directly to it from add/del, we don't
need to worry about it changing as kq_dispatch releases the lock.  We
would make it a local variable, except that we wouldn't want to malloc
and free it all the time.
2010-01-14 17:04:08 -05:00
Nick Mathewson
45e5ae3717 Make kqueue use changelists.
This fixes a bug in kqueue identified by Charles Kerr and various
Transmission users, where adding and deleting an event in succession
would make the event get reported, even if we didn't actually want to
see it.

Of course, this also makes the array of changes passed to kevent
smaller, which could help performance.
2010-01-14 16:34:40 -05:00
Nick Mathewson
27308aae4d Changelist code to defer event changes until just before dispatch
This is necessary or useful for a few reasons:

    1) Sometimes applications will add and delete the same event more
       than once between calls to dispatch.  Processing these changes
       immediately is needless, and potentially expensive (especially
       if we're on a system that makes one syscall per changed event).

       Yes, this actually happens in practice for nonpathological
       code, such as in cases where the user's callback conditionally
       re-adds a non-persistent event, or where draining a buffer
       turns off writing and invokes a user callback which adds more
       data which in turn re-enabled writing.

    2) Sometimes we can coalesce multiple changes on the same fd into
       a single syscall if we know about them in advance.  For
       example, epoll can do an add and a delete at the same time, but
       only if we have found out about both of them before we tell
       epoll.

    3) Sometimes adding an event that we immediately delete can cause
       unintended consequences: in kqueue, this makes pending events
       get reported spuriously.
2010-01-14 16:31:22 -05:00
Nick Mathewson
c698b77d19 Allow http connections to use evdns for hostname looksups.
This was as simple as using bufferevent_connect_hostname instead of
calling connect() ourself, which already knows how to use an
evdns_base if it gets one.

Untangling the bind code might be a little trickier.
2010-01-14 15:18:25 -05:00
Nick Mathewson
a334b31c6f More unit tests for getaddrinfo_async: v4timeout and cancel.
One covers the case where the v4 request times out but the v6 request
doesn't.  The other makes sure that cancelling a request actually works.
2010-01-14 14:46:16 -05:00
Nick Mathewson
94131e92b8 Fix test.sh on shells without echo -n
Some systems have a version of /bin/sh whose builtin echo doesn't
support the -n option used in test/test.sh.  /bin/echo, however,
usually does.  This patch makes us use /bin/echo for echo -n whenever
it is present.

Also, our use of echo -n really only made sense when suppressing all
test output.  Since test output isn't suppressed when logging to a
file, this pach makes us stop using echo -n when logging to a file.
2010-01-12 15:58:36 -05:00
Nick Mathewson
b9f43b231f Add a comment on evthread_enable_lock_debuging. 2010-01-11 20:47:45 -05:00
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
Jardel Weyrich
510ab6bce0 Comestic changes in evconnlistener_new(), new_accepting_socket(), accepted_socket_invoke_user_cb() and iocp_listener_enable(). 2010-01-08 23:28:54 -05:00
Jardel Weyrich
fec66f9685 Improved error handling in evconnlistener_new_async(). Also keeping the fd open because it is not opened by this function, so the caller is responsible for closing it. Additionally, since evconnlistener_new_bind() creates a socket and passes it to the function above, it required error checking to close the same socket. 2010-01-08 23:28:23 -05:00
Jardel Weyrich
4367a33a20 Fixed a fd leak in start_accepting(), plus cosmetic changes 2010-01-08 23:27:26 -05:00
Jardel Weyrich
2f33e00af3 Fixed a memory leak on windows threads implementation. The CRITICAL_SECTION was not being free'd in evthread_win32_lock_free(). 2010-01-08 23:26:01 -05:00
Nick Mathewson
66c02c7826 Look at the proper /etc/hosts file on windows.
This is harder than it might initially seem, since the proper filename
depends on what the admin has decided to call the windows system directory,
which for all we know might be Q:\tralfamidore\slartibartfast.  And of course,
this being windows, there are twelve ways to do it, where you can pick a
nice one or a portable one, but not a really nice portable one.
2010-01-08 19:36:38 -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
0f7144fd8b Refactor code from evdns into a new internal "read a file" function. 2010-01-08 19:36:35 -05:00