summaryrefslogtreecommitdiff
path: root/bufferevent.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-07-28 04:03:57 +0000
committerNick Mathewson <nickm@torproject.org>2009-07-28 04:03:57 +0000
commit709c21c48ca541c75bf803e6801c335d8ae3d043 (patch)
treeff87cc257ecf83765377ef01ce8c29cfa5d69cab /bufferevent.c
parentb06b2649b4c7f5feaedea97c31001c14708e4d1f (diff)
downloadlibevent-709c21c48ca541c75bf803e6801c335d8ae3d043.tar.gz
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
Diffstat (limited to 'bufferevent.c')
-rw-r--r--bufferevent.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/bufferevent.c b/bufferevent.c
index f79ff540..6d9f67ec 100644
--- a/bufferevent.c
+++ b/bufferevent.c
@@ -325,7 +325,7 @@ bufferevent_enable(struct bufferevent *bufev, short event)
short impl_events = event;
int r = 0;
- BEV_LOCK(bufev);
+ _bufferevent_incref_and_lock(bufev);
if (bufev_private->read_suspended)
impl_events &= ~EV_READ;
@@ -334,7 +334,7 @@ bufferevent_enable(struct bufferevent *bufev, short event)
if (bufev->be_ops->enable(bufev, impl_events) < 0)
r = -1;
- BEV_UNLOCK(bufev);
+ _bufferevent_decref_and_unlock(bufev);
return r;
}
@@ -525,10 +525,17 @@ bufferevent_enable_locking(struct bufferevent *bufev, void *lock)
#ifdef _EVENT_DISABLE_THREAD_SUPPORT
return -1;
#else
+ struct bufferevent *underlying;
+
if (BEV_UPCAST(bufev)->lock)
return -1;
+ underlying = bufferevent_get_underlying(bufev);
- if (!lock) {
+ if (!lock && underlying && BEV_UPCAST(underlying)->lock) {
+ lock = BEV_UPCAST(underlying)->lock;
+ BEV_UPCAST(bufev)->lock = lock;
+ BEV_UPCAST(bufev)->own_lock = 0;
+ } else if (!lock) {
EVTHREAD_ALLOC_LOCK(lock);
if (!lock)
return -1;
@@ -541,6 +548,9 @@ bufferevent_enable_locking(struct bufferevent *bufev, void *lock)
evbuffer_enable_locking(bufev->input, lock);
evbuffer_enable_locking(bufev->output, lock);
+ if (underlying && !BEV_UPCAST(underlying)->lock)
+ bufferevent_enable_locking(underlying, lock);
+
return 0;
#endif
}
@@ -632,3 +642,11 @@ _bufferevent_generic_adj_timeouts(struct bufferevent *bev)
event_del(&bev->ev_write);
}
+int
+_bufferevent_add_event(struct event *ev, const struct timeval *tv)
+{
+ if (tv->tv_sec == 0 && tv->tv_usec == 0)
+ return event_add(ev, NULL);
+ else
+ return event_add(ev, tv);
+}