195 Commits

Author SHA1 Message Date
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
Nick Mathewson
5b3fb5bfa5 More documentation and unit tests for event_tagging.
svn:r1476
2009-10-29 16:35:20 +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
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
Nick Mathewson
8cc6883524 Fix the main/methods unit test to pass from "make verify".
The problem was introduced when we changed the semantics of
get_supported_methods() to reflect all the methods that exist.
Previously, it had not returned methods disabled from the environment,
but the test didn't know that.

svn:r1379
2009-07-25 03:35:32 +00:00
Nick Mathewson
49de08ef35 Push coverage of event.c a little higher
svn:r1373
2009-07-21 19:20:44 +00:00
Nick Mathewson
f4775918cd Refactor evtag tests into their own suite.
svn:r1366
2009-07-20 14:55:51 +00:00
Nick Mathewson
e8400a43ca Rename encode_int(64) to avoid polluting the global namespace.
They're now called evtag_encode_int(64).  The old names are available
as macros in event2/tag_compat.h.

Also, add unit tests for encode/decode_int64.

svn:r1365
2009-07-20 14:55:35 +00:00
Nick Mathewson
5d71b25b51 Remove all trailing whitespace from end-of-line.
svn:r1350
2009-07-17 18:38:38 +00:00
Nick Mathewson
d4e3671fb4 Add a test to free_active_base to free a base with an active event.
svn:r1349
2009-07-17 18:38:21 +00:00
Nick Mathewson
e224321c64 Convert and expand free_active_base/event_base_new tests to avoid dbl-free. Patch from Zack Weinberg
svn:r1342
2009-07-14 18:49:42 +00:00
Nick Mathewson
b45cead762 Make environment-variable tests work on win32, which has only one method and lacks (un)setenv.
svn:r1253
2009-04-30 18:05:33 +00:00
Nick Mathewson
586aa46886 Unit test for disabling events with EVENT_NO*, and for EVENT_BASE_FLAG_IGNORE_ENV.
svn:r1247
2009-04-28 19:08:27 +00:00
Nick Mathewson
d70b080488 Make main/methods test pass on systems where only one backend exists.
svn:r1235
2009-04-23 18:08:42 +00:00
Nick Mathewson
0068c98ad2 Make version test ignore the bottom byte of the version number.
svn:r1225
2009-04-23 00:01:14 +00:00
Nick Mathewson
b21be24545 Somehow free_active_base was using the socketpair, but not saying it needed it. How did this ever work?
svn:r1223
2009-04-23 00:00:55 +00:00
Nick Mathewson
1f9c9e5137 Add a missing "static".
svn:r1219
2009-04-22 15:38:50 +00:00
Nick Mathewson
133a015dba Make sure the test case for mem_functions hits strdup too.
svn:r1218
2009-04-21 18:48:05 +00:00