1210 Commits

Author SHA1 Message Date
Nick Mathewson
f9c65580f0 Oops; add missing bufferevent_evdns.c file
svn:r1497
2009-11-03 20:42:32 +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
a84c87d76a Refactor IOCP callback interface
Chris Davis points out that GetQueuedCompletionStatus
sometimes returns false not to report "No events for
you!" but instead to report "An overlapped operation
failed."  Add a way to tell an event_overlapped that
its operation failed.

svn:r1490
2009-11-02 19:51:26 +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
5d2c1650f3 More refactoring for IOCP listener code
svn:r1486
2009-11-02 17:42:09 +00:00
Nick Mathewson
e90e14fb94 Call the bufferevent_flush_mode variable "mode" more consistently in the documentation. Spotted by Alex.
svn:r1485
2009-11-02 16:31:13 +00:00
Nick Mathewson
7f0ad2f63c Fix an errant user of ssize_t to use ev_ssize_t.
My usual strategy of grep '[^_]ssize_t' had apparently failed me,
since this ssize_t was in the first column.

Resolves bug 2890434; spotted by Mihai Draghicioiu.

svn:r1484
2009-11-02 16:17:06 +00:00
Nick Mathewson
315fde1a70 Remove some duplicate code in kqueue.c and fix a small memory leak.
svn:r1483
2009-10-30 22:43:53 +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
516452b71a Keep openssl errors associated with the right bufferevent object.
OpenSSL has a per-thread error stack, and really doesn't like you
leaving errors on the stack.  Rather than discard the errors or force
the user to handle them, this patch pulls them off the openssl stack
and puts them on a stack associated with the bufferevent_openssl.  If
the user leaves them on the stack then, it won't affect any other
connections.

This bug was found by Roman Puls.  Thanks!

svn:r1481
2009-10-30 21:08:29 +00:00
Nick Mathewson
20f5bdfd6b Refactor evconnlistener to allow multiple implementations; add an (incomplete, not-yet-integrated) IOCP implementation.
svn:r1480
2009-10-29 19:25:33 +00:00
Nick Mathewson
fa313f28c5 Extract XP-only functions when initializing the IOCP port
svn:r1479
2009-10-29 18:30:43 +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
1eadb3e3a2 Actually use the logic in select.c designed to make the out_sets threadsafe.
svn:r1475
2009-10-29 16:35:15 +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
a2a7d1d123 Do not call the locking variant of event_add or event_active in some cases when we know we have the lock.
svn:r1471
2009-10-27 05:16:32 +00:00
Nick Mathewson
d386dc89b5 Refactor event_assing even more to avoid unnecessary calls
svn:r1470
2009-10-27 05:16:23 +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
10cf631e84 Do not add a newline to the end of log statements.
svn:r1468
2009-10-27 04:04:07 +00:00
Nick Mathewson
369aafc4d7 Refactor kq_init error handling.
svn:r1467
2009-10-27 04:03:58 +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
7f10fac342 Note assert-related change in changelog
svn:r1465
2009-10-26 20:07:06 +00:00
Nick Mathewson
2e36dbe1a6 Use EVUTIL_ASSERT() consistently instead of assert.
svn:r1464
2009-10-26 20:00:43 +00:00
Nick Mathewson
37c3456d70 Add an EVUTIL_ASSERT() to replace our calls to assert().
The big difference here is that EVUTIL_ASSERT() passes its message on
via event_errx() before aborting, so that the application has a prayer
of noticing and recording it.

svn:r1463
2009-10-26 20:00:08 +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
c119e4a13f Improve the behavior of le-proxy in a few cases.
svn:r1458
2009-10-23 17:40:00 +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
b73ad7bc45 Treat the bitwise OR of two enum values as an int.
This makes our interfaces usable from C++, which doesn't believe
you can say    "bufferevent_socket_nase(base, -1,
BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS)" but which instead
would demand "static_cast<bufferevent_options>(BEV_OPT_CLOSE_ON_FREE|
BEV_OPT_DEFER_CALLBACKS))" for the last	argument.

Diagnosis and patch from Chris Davis.

svn:r1456
2009-10-21 18:48:22 +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
d8164d0cfc Fix win32 connect() event handling.
Christopher Davis reported:

    Connection failures aren't reported on Windows when
    using bufferevent_socket_connect, because Windows uses
    select's exceptfds to notify of failure, and libevent
    treats them like read events. Only the write event
    handler is currently used to handle connection events.

We should think hard about this one, since it changes
behavior from 1.4.x.  Anything that worked on Mac/Unix before
will work more consistently on Windows now... but this might
break stuff that worked only on Windows, but nowhere else.

Patch from Chris Davis.

svn:r1454
2009-10-21 07:00:14 +00:00
Nick Mathewson
b89b58b5f4 OSX compilation issues
svn:r1453
2009-10-21 06:03:00 +00:00
Nick Mathewson
c9c4ec26ee Remove an EVBASE_RELEASE_LOCK that I missed.
svn:r1452
2009-10-21 05:36:27 +00:00
Nick Mathewson
ed748a48ba Fix win32 compilation.
svn:r1451
2009-10-21 04:45:59 +00:00
Nick Mathewson
6b22e74aa1 Add locking to event_base_loop.
This is harder than it sounds, since we need to make sure to
release the lock around the key call to the kernel (e.g.,
select, epoll_wait, kevent), AND we need to make sure that
none of the fields that are used in that call are touched by
anything that might be running concurrently in another
thread.  I managed to do this pretty well for everything but
poll().  With poll, I needed to introduce a copy of the
event_set structure.

This patch also fixes a bug in win32.c where we called
realloc() instead of mm_realloc().

svn:r1450
2009-10-21 03:54:00 +00:00
Nick Mathewson
5082546682 Fix windows compilation warnings.
svn:r1449
2009-10-21 02:14:16 +00:00
Niels Provos
e1c9b84ae6 Fix compilation for listener.h for C++ - missing extern "C". Patch from Ferenc Szalai.
svn:r1448
2009-10-19 16:20:12 +00:00
Nick Mathewson
b812563a6e Add a note that we should change previous_to_last to last_with_space
svn:r1447
2009-10-16 13:20:16 +00:00