38 Commits

Author SHA1 Message Date
Nick Mathewson
e6af35d762 Correctly terminate IO on an async bufferevent on bufferevent_free 2011-08-28 14:39:12 -04:00
Sebastian Hahn
65707d7c3c add some (void) casts for unused variables
All these places already have an XXX marker, so we know we need to fix
them later. Let's not clutter the static analysis results with them.
2011-04-23 02:04:58 +02:00
Nick Mathewson
7bcace2d54 Fix some irix compilation warnings spotted by Kevin Bowling 2010-11-22 21:02:34 -05:00
Nick Mathewson
1ac5b2303a Only clear underlying callbacks when the user hasn't reset them. 2010-11-09 15:18:59 -05:00
Nick Mathewson
fc7b1b005c When closing a filtering bufferevent, clear callbacks on the underlying bufferevent
Previously, if BEV_OPT_CLOSE_ON_FREE wasn't set on a
bufferevent_filter or a filtering bufferevent_openssl, when we went
to free the filtering bufferevent, we'd leave the underlying
bufferevent unchanged.  That's not so good, since the callbacks are
set to activate stuff in the filtering bufferevent that we're about
to free.  Instead, set all the callbacks to NULL.
2010-11-09 11:43:47 -05:00
Nick Mathewson
ac27eb8276 Correct logic on disabling underlying bufferevents when disabling a filter
Previously, whenever writing was disabled on a bufferevent_filter (or
a filtering SSL bufferevent), we would stop writing on the underlying
bufferevent.  This would make for trouble, though, since if you
implemented common patterns like "stop writing once data X has been
flushed", your bufferevent filter would disable the underlying
bufferevent after the data was flushed to the underlying bufferevent,
but before actually having it written to the network.

Now, we have filters leave their underlying bufferevents enabled for
reading and writing for reading and writing immediately.  They are not
disabled, unless the user wants to disable them, which is now allowed.
To handle the case where we want to choke reading on the underlying
bufferevent because the filter no longer wants to read, we use
bufferevent_suspend_read().  This is analogous to the way that we use
bufferevent_suspend_write() to suspend writing on a filtering
bufferevent when the underlying bufferevent's output buffer has hit
its high watermark.
2010-10-14 10:55:04 -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
657d1b6d3f Set mem_offset for every bufferevent type 2010-03-13 01:06:57 -05:00
Nick Mathewson
f1bc125eb4 Improve robustness for refcounting
Document that we do intend to double-decref underlying bufferevents under
some circumstances.  Check to make sure that we don't decref past 0.
2010-03-13 00:28:50 -05:00
Nick Mathewson
17efc1cdfa Update all our copyright notices to say "2010" 2010-03-04 01:38:48 -05:00
Nick Mathewson
d3288293fd Provide consistent, tested semantics for bufferevent timeouts
The different bufferevent implementations had different behavior for
their timeouts.  Some of them kept re-triggering the timeouts
indefinitely; some disabled the event immediately the first time a
timeout triggered.  Some of them made the timeouts only count when
the bufferevent was actively trying to read or write; some did not.

The new behavior is modeled after old socket bufferevents, since
they were here first and their behavior is relatively sane.
Basically, each timeout disables the bufferevent's corresponding
read or write operation when it fires.  Timeouts are stopped
whenever we suspend writing or reading, and reset whenever we
unsuspend writing or reading.  Calling bufferevent_enable resets a
timeout, as does changing the timeout value.
2010-02-23 15:20:33 -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
8fdf09c09d Clean up formatting: Disallow space-before-tab. 2010-02-18 17:08:50 -05:00
Nick Mathewson
2e8eeea3e8 Fix crash bugs when a bufferevent's eventcb is not set.
In many places throughout the code, we called _bufferevent_run_eventcb
without checking whether the eventcb was actually set.  This would
work fine when the bufferevent's callbacks were deferred, but
otherwise the code would segfault.  Strangely, we always remembered to
check before calling the _bufferevent_run_{read,write}cb functions.

To prevent similar errors in the future, all of
_buferevent_run_{read,write,event}cb now check to make sure the
callback is actually set before invoking or deferring the callback.
This patch also removes the now-redundant checks for {read,write}cb.
2009-12-29 19:50:03 -05:00
Joachim Bauch
a773df54ce Fix a segfault when freeing SSL bufferevents in an unusual order
Have container bufferevents hold a reference to their underlying bufferevents.

(Commit message and minor revisions by nickm.)
2009-12-18 16:26:40 -05: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
2e36dbe1a6 Use EVUTIL_ASSERT() consistently instead of assert.
svn:r1464
2009-10-26 20:00:43 +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
e3fd294a6d Spelling fixes in comments and strings.
svn:r1445
2009-10-16 13:19:57 +00:00
Nick Mathewson
709c21c48c Bufferevent support for openssl.
This code adds a new Bufferevent type that is only compiled when the
openssl library is present.  It supports using an SSL object and an
event alert mechanism, which can either be an fd or an underlying
bufferevent.

There is still more work to do: the unit tests are incomplete, and we
need to support flush and shutdown much better.  Sometimes events are
generated needlessly: this will hose performance.

There's a new encrypting proxy in sample/le-proxy.c.

This code has only been tested on OSX, and nowhere else.

svn:r1382
2009-07-28 04:03:57 +00:00
Nick Mathewson
a62283a9c3 Always hold a reference to a bufferevent when calling its callbacks.
Rationale: we hold a lock on the bufferevent when its callbacks are
executing, so we need to release the lock afterwards.  But the
callback might free the bufferevent, so unless we're holding a
reference on the bufferevent, the lock might not be there for us to
release.

svn:r1347
2009-07-17 17:46:17 +00:00
Nick Mathewson
5232cfa357 Consistently say "eventcb" instead of "errorcb"
svn:r1316
2009-05-25 23:11:20 +00:00
Nick Mathewson
34574db0f8 Add a generic mechanism to implement timeouts in bufferevents.
Paired and asynchronous bufferevents didn't do timeouts, and filtering
bufferevents gave them funny semantics.  Now they all should all work
in a way consistent with what socket bufferevents do now: a [read/write]
timeout triggers if [reading/writing] is enabled, and if the timeout is
set, and the right amount of time passes without any data getting
[added to the input buffer/drained from the output buffer].

svn:r1314
2009-05-25 23:10:23 +00:00
Nick Mathewson
0b22ca1929 Use ev_ssize_t in place of ssize_t *everywhere*.
svn:r1309
2009-05-22 19:11:48 +00:00
Nick Mathewson
31d89f274b Add a "ctrl" mechanism to bufferevents for property access.
OpenSSL uses something like this to implement get/set access for
properties on its BIOs, so that it doesn't need to add a pair of
get/set functions to the vtable struct for every new abstract property
it provides an accessor for.

Doing this lets us make bufferevent_setfd abstract, and implement an
abstract bufferevent_getfd.

svn:r1284
2009-05-13 20:37:21 +00:00
Nick Mathewson
5a3eddf03f Use fewer _compat.h headers in our own code.
svn:r1268
2009-05-02 16:24:05 +00:00
Nick Mathewson
eda27f9557 Update copyright notices, add some missing license statements
svn:r1208
2009-04-19 20:54:12 +00:00
Nick Mathewson
a98a512bc1 Add a generic way for any bufferevent to make its callback deferred
svn:r1197
2009-04-17 23:12:34 +00:00
Nick Mathewson
a8f6d961eb Actually stop using EVBUFFER_LENGTH/DATA, and move them to buffer_compat.h
svn:r1183
2009-04-17 06:56:09 +00:00
Nick Mathewson
915193e7df Locking support for bufferevents.
svn:r1170
2009-04-13 03:17:19 +00:00
Nick Mathewson
1becc4c4e6 Refactor new elements of bufferevent into bufferevent_private structure
This way we don't expose more of a bufferevent than we need to.  One
motivation is to make it easier to automatically get deferred callbacks
with a bufferevent without exposing the deferred_cb structure.

svn:r1169
2009-04-13 03:08:11 +00:00
Nick Mathewson
23085c9247 Add a linked-pair abstraction to bufferevents.
The new bufferevent_pair abstraction works like a set of buferevent_sockets
connected by a socketpair, except that it doesn't require a socketpair,
and therefore doesn't need to get the kernel involved.

It's also a good way to make sure that deferred callbacks work.  It's a good
use case for deferred callbacks: before I implemented them, the recursive
relationship between the evbuffer callback and the read callback would
make the unit tests overflow the stack.

svn:r1152
2009-04-10 15:01:31 +00:00
Nick Mathewson
f1b1bad415 Make the new evbuffer callbacks use a new struct-based interface.
The old interface would fail pretty hard when we had to batch up
multiple adds and drains in a single call.

svn:r1131
2009-04-03 14:27:03 +00:00
Nick Mathewson
ac36f4047e oops; coding too quickly on nil-filter patch. Caught by niels.
svn:r1115
2009-02-11 05:17:27 +00:00
Nick Mathewson
20f809ce8c Make default (nil) filter use evbuffer_remove_buffer to respect the high-water mark of the target buffer.
svn:r1109
2009-02-10 19:39:12 +00:00
Nick Mathewson
3502a472b5 convert new bufferevent_*.c files to event-config.h only.
svn:r1097
2009-02-02 21:24:04 +00:00
Nick Mathewson
ea4b8724c0 checkpoint work on big bufferevent refactoring
svn:r1095
2009-02-02 19:22:13 +00:00