17 Commits

Author SHA1 Message Date
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
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
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
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
11a178f2bd Defer EOF on paired bufferevent correctly.
svn:r1317
2009-05-25 23:11:31 +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
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
83f46e51d7 Do not use the "evbuffer_" prefix to denote parts of bufferevents.
This is a bit of an interface doozy, but it's really needed in order
to be able to document this stuff without apologizing it.  This patch
does the following renamings:

   evbuffercb -> bufferevent_data_cb
   everrorcb -> bufferevent_event_cb
   EVBUFFER_(READ,WRITE,...) -> BEV_EVENT_(...)
   EVBUFFER_(INPUT,OUTPUT) -> bufferevent_get_(input,output)

All the old names are available in event2/bufferevent_compat.h

svn:r1283
2009-05-13 20:36:56 +00:00
Nick Mathewson
e865eb938c More msvc build tweaks.
svn:r1262
2009-05-01 00:54:14 +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
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
8dec59bb35 Use freeze operations to prevent shenanegans on bufferevent pair evbuffers.
svn:r1167
2009-04-13 03:07:17 +00:00
Nick Mathewson
0b47b125cf Add a new EVUTIL_UPCAST macro so that I do not need to keep figuring out the right offsetof magic over and over.
svn:r1160
2009-04-12 22:02:54 +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