aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat_libevent.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-12-06 19:49:20 -0500
committerNick Mathewson <nickm@torproject.org>2011-12-06 19:49:20 -0500
commitdf1f72329acf5f555618a5309f2621e584c0d763 (patch)
tree322a3115843ddb041192acf8f66294fe342254de /src/common/compat_libevent.c
parent3a17a1a62f242f3aa64891407d3d64aa040d6d02 (diff)
downloadtor-df1f72329acf5f555618a5309f2621e584c0d763.tar
tor-df1f72329acf5f555618a5309f2621e584c0d763.tar.gz
Revert "Refactor tor_event_base_once to do what we actually want"
This reverts commit 7920ea55b8d994268d2b07f27316b0f34d8f27e5.
Diffstat (limited to 'src/common/compat_libevent.c')
-rw-r--r--src/common/compat_libevent.c45
1 files changed, 5 insertions, 40 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index c3a4746b3..b709b4afd 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -558,48 +558,13 @@ tor_check_libevent_header_compatibility(void)
#endif
}
-typedef struct runnable_t {
- struct event *ev;
- void (*cb)(void *arg);
- void *arg;
-} runnable_t;
-
-/** Callback for tor_run_in_libevent_loop */
-static void
-run_runnable_cb(evutil_socket_t s, short what, void *arg)
-{
- runnable_t *r = arg;
- void (*cb)(void *) = r->cb;
- void *cb_arg = r->arg;
- (void)what;
- (void)s;
- event_free(r->ev);
- tor_free(r);
-
- cb(cb_arg);
-}
-
-/** Cause cb(arg) to run later on this iteration of the libevent loop, or in
- * the next iteration of the libevent loop. This is useful for when you're
- * deep inside a no-reentrant code and there's some function you want to call
- * without worrying about whether it might cause reeentrant invocation.
- */
+/** Wrapper around libevent's event_base_once(). Sets a
+ * timeout-triggered event with no associated file descriptor. */
int
-tor_run_in_libevent_loop(void (*cb)(void *arg), void *arg)
+tor_event_base_once(void (*cb)(evutil_socket_t, short, void *),
+ void *arg, struct timeval *timer)
{
- runnable_t *r = tor_malloc(sizeof(runnable_t));
- r->cb = cb;
- r->arg = arg;
- r->ev = tor_event_new(tor_libevent_get_base(), -1, EV_TIMEOUT,
- run_runnable_cb, r);
- if (!r->ev) {
- tor_free(r);
- return -1;
- }
- /* Make the event active immediately. */
- event_active(r->ev, EV_TIMEOUT, 1);
-
- return 0;
+ return event_base_once(tor_libevent_get_base(), -1, EV_TIMEOUT, cb, arg, timer);
}
/*