213 Commits

Author SHA1 Message Date
Nick Mathewson
0cb70e3333 Merge remote-tracking branch 'origin/patches-2.0' 2011-10-26 10:17:21 -04:00
Nick Mathewson
3c824bd334 Update copyright dates to 2011. 2011-10-24 13:18:09 -04:00
Nick Mathewson
b3bc77b673 Merge remote-tracking branch 'origin/patches-2.0' 2011-10-03 12:54:35 -04:00
Nick Mathewson
2b768479e4 Make write-checking fixes use tt_fail_perror 2011-10-03 12:45:36 -04:00
Mark Ellzey
c3b62fd7fd Fixed compiler warnings for unchecked read/write calls. 2011-10-03 12:40:48 -04:00
Nick Mathewson
e903db3362 Reenable main/many_events_slow_add for evport in 2.1
The various evport fixes should let it actually work again
2011-05-27 15:31:40 -04:00
Nick Mathewson
356720a23b Merge remote-tracking branch 'origin/patches-2.0' 2011-05-27 15:09:54 -04:00
Nick Mathewson
c11c6fcd82 Disable main/many_events_slow_add with evport backend
In 2.0 and earlier, evport only reports up to 8 events at a time, which
confuses this test badly.
2011-05-27 14:58:21 -04:00
Nick Mathewson
9f560bfa11 Use "_WIN32", not WIN32: it's standard and we don't need to fake it
This patch was automatically generated with perl.

Based on a patch by Peter Rosin.
2011-05-25 20:03:15 -04:00
Nick Mathewson
d11e9e0f71 Oops; that new unit test breaks for epoll. Fix it. 2011-05-03 14:22:48 -04:00
Nick Mathewson
28317a087e Fix a warn-and-fail bug in kqueue by providing kevent() room to report errors
Apparently, kevent fails gracefully if there is not enough space in its
output events array to report every _event_... but it just dies and returns
-1 if there is not enough space to report every _error_.

There are a couple of possible fixes here.  One would to handle -1
returns from kevent better by re-growing the array and retrying... but
that seems a little error prone.  Instead, I'm just going to say that
the events array must be large enough to handle all the errors.

This patch also adds a unit test designed to make sure that our
many-events-out code works even if not all the events are added at
once.
2011-05-03 13:54:57 -04:00
Nick Mathewson
22f4af6580 Remove end-of-line whitespace 2010-12-09 11:43:12 -05:00
Nick Mathewson
7bcace2d54 Fix some irix compilation warnings spotted by Kevin Bowling 2010-11-22 21:02:34 -05:00
Nick Mathewson
aed7e02979 Make unit tests for epoll-with-changelist pass
The only changes needed were to handle the fact that the methodname
"epoll (with changelist)" matches the environment variable
EVENT_NOEPOLL rather than the imaginary "EVENT_EPOLL (WITH CHANGELIST)".
2010-11-22 15:51:45 -05:00
Christopher Davis
34b84b9727 Fix more wn64 warnings. 2010-11-03 23:30:29 -04:00
Nick Mathewson
5d389dc0f0 Fix some uses of int for socket in regress 2010-10-26 22:27:57 -04:00
Nick Mathewson
c281aba30e Fix a nasty bug related to use of dup() with epoll on Linux
Current versions of the Linux kernel don't seem to remove the struct
epitem for a given (file,fd) combo when the fd is closed unless the
file itself is also completely closed.  This means that if you do:
   fd = dup(fd_orig);
   add(fd);
   close(fd);
   dup2(fd_orig, fd);
   add(fd);
you will get an EEXIST when you should have gotten a success.  This
could cause warnings and dropped events when using dup and epoll.

The solution is pretty simple: when we get an EEXIST from
EPOLL_CTL_ADD, we retry with EPOLL_CTL_MOD.

Unit test included to demonstrate the bug.

Found due to the patient efforts of Gilad Benjamini; diagnosed with
help from Nicholas Marriott.
2010-10-24 11:38:29 -04:00
Nick Mathewson
e5c214a423 Fix -Wsigned-compare warnings in test/* 2010-10-14 13:16:41 -04:00
Nick Mathewson
4858b7949c Remove the now-useless evsig_caught and evsig_process 2010-09-15 01:54:51 -04:00
Nick Mathewson
720bd933c8 Warn when using the error-prone EV_SIGNAL interface in an error-prone way. Also, fix a couple of race conditions in signal.c
When using the signal.c signal backend, Libevent currently only allows
one event_base to actually receive signals at a time.  (This has been
the behavior since at least 1.4 and probably much earlier.)  Now, we
detect and warn if you're likely to be racing about which signal goes
to which thread.

We also add a lock to control modifications of the evsig_base field,
to avoid race conditions like those found by Jason Toffaletti.

Also, more comments.  Comments are good.
2010-09-15 01:12:01 -04:00
Nick Mathewson
25b6a74be6 Merge branch 'tests' 2010-09-08 14:53:57 -04:00
Nick Mathewson
ce85280beb Improve testing of when thread-notification occurs 2010-09-08 13:29:06 -04:00
Nick Mathewson
1115366e95 Fix a few memory leaks in the tests 2010-09-07 10:36:19 -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
Nick Mathewson
42a8c71112 Build more cleanly with NetBSDs that dislike toupper(char)
To be fair, when char can be signed, if toupper doesn't take negative
characters, toupper(char) is a very bad idea.  So let's just use the
nice safe EVUTIL_TOUPPER instead.  (It explicitly only upcases ASCII,
but we only use it for identifiers that we know to be ASCII anyway).
2010-07-31 17:10:04 -04:00
Nick Mathewson
7510aac3b9 Unit test for event_get_struct_event_size() 2010-06-21 12:23:32 -04:00
Nick Mathewson
44d57eee93 Add test for behavior on remote socket close
On all the backends on this little mac laptop, that behavior is to
report a remote socket close as both EV_READ and EV_WRITE.
Historically, we had problem for some of these behaviors on some
backends, so let's make sure that such behaviors don't come back.
2010-06-03 11:25:54 -04:00
Nick Mathewson
8bc1e3d6d1 Remove all non-error prints from test/regress.c
Now, running ./test/regress --quiet will indeed only inform you
about errors.  Previously, it would also spew extra output.
2010-05-26 13:43:00 -04:00
Nick Mathewson
e73f1d792a Remove the now-obsolete setup_test() and cleanup_test() functions 2010-05-26 13:43:00 -04:00
Nick Mathewson
f37cd4c227 Detect broken unsetenv at unit-test runtime
If we have an unsetenv function that doesn't work, we can't run the
main/base_environ unit test, so we should skip it.
2010-05-08 14:36:59 -04:00
Nick Mathewson
c16e68448c Rename current_base symbol to event_global_current_base_
The "current_base" symbol was never actually declared in an exported
header; it's hideously deprecated, and it was the one remaining
exported symbol (fwict) that was prefixed with neither ev nor
bufferevent nor _ev nor _bufferevent.

codesearch.google.com turns up no actual attempts to use our
current_base from outside libevent.
2010-05-04 13:27:36 -04:00
Sebastian Sjöberg
899c1dcc98 Replace EVUTIL_CLOSESOCKET macro with a function
The EVUTIL_CLOSESOCKET() macro required you to include unistd.h in your
source for POSIX.  We might as well turn it into a function: an extra
function call is going to be cheap in comparison with the system call.

We retain the EVUTIL_CLOSESOCKET() macro as an alias for the new
evutil_closesocket() function.

(commit message from email by Nick and Sebastian)
2010-04-14 15:42:57 -04:00
Nick Mathewson
b557b175c0 Detect and refuse reentrant event_base_loop() calls
Calling event_base_loop on a base from inside a callback invoked by
that same base, or from two threads at once, has long been a way to
get exceedingly hard-to-diagnose errors.  This patch adds code to
detect such reentrant invocatinos, and exit quickly with a warning
that should explain what went wrong.
2010-03-21 13:28:48 -04:00
Nick Mathewson
33874b0528 Make 'main/many_events' test 70 fds, not 64.
This is mainly intended to ensure that we don't get hung up on
the 64-handle limit that lots of O(n) Windows functions (but FWICT
not select) like to enforce.
2010-03-16 13:37:15 -04:00
Nick Mathewson
68dc742bf1 Fix a write of uninitialized RAM in regression tests
Not actually harmful, but not something we should be doing.

Found by valgrind.
2010-03-13 00:31:14 -05:00
Nick Mathewson
c7cf6f0049 Replace users of "int fd" with "evutil_socket_t fd" in portable code
Remeber, win32 has a socket type that's actually a handle, so if
there's a chance that code is run on win32, we can't use "int" as the
socket type.

This isn't a blind search-and-replace: sometimes an fd is really in
fact for a file, and not a socket at all.
2010-03-05 12:47:46 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
7ffd387574 Delete stack-alloced event in new unit test before returning. 2010-02-24 13:40:06 -05:00
Nick Mathewson
8fcb7a1b04 Add test for periodic timers that get activated for other reasons
This was already independently verified by the new bufferevent
timeout tests, but it's good to explicitly check that our code
does what it should.
2010-02-23 23:55:32 -05:00
Nick Mathewson
4faeaea90e Clean up formatting: function/keyword spacing consistency.
- Keywords always have a space before a paren.  Functions never do.

- No more than 3 blank lines in a row.
2010-02-19 03:39:50 -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
918e9c5e72 Fix a number of warnings from gcc -pedantic 2010-01-23 16:38:36 -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
d84d8385cd Fix two use-after-free bugs in unit tests spoted by lock debugging 2009-11-27 17:36:51 -05:00
Nick Mathewson
9bf124bff6 Build correctly with mm replacement turned off.
svn:r1547
2009-11-18 21:16:47 +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
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
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