Tor 0.4.9.2-alpha-dev
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
compat_libevent.h
Go to the documentation of this file.
1/* Copyright (c) 2009-2024, The Tor Project, Inc. */
2/* See LICENSE for licensing information */
3
4/**
5 * \file compat_libevent.h
6 * \brief Header for compat_libevent.c
7 **/
8
9#ifndef TOR_COMPAT_LIBEVENT_H
10#define TOR_COMPAT_LIBEVENT_H
11
12#include "orconfig.h"
14#include "lib/malloc/malloc.h"
15
16#include <stdbool.h>
17
19void suppress_libevent_log_msg(const char *msg);
20
21#define tor_event_new event_new
22#define tor_event_del event_del
23#define tor_evtimer_new evtimer_new
24#define tor_evsignal_new evsignal_new
25#define tor_evdns_add_server_port(sock, tcp, cb, data) \
26 evdns_add_server_port_with_base(tor_libevent_get_base(), \
27 (sock),(tcp),(cb),(data));
28
29struct event;
30struct event_base;
31struct timeval;
32
33void tor_event_free_(struct event *ev);
34#define tor_event_free(ev) \
35 FREE_AND_NULL(struct event, tor_event_free_, (ev))
36
38
39periodic_timer_t *periodic_timer_new(struct event_base *base,
40 const struct timeval *tv,
41 void (*cb)(periodic_timer_t *timer, void *data),
42 void *data);
44void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv);
46#define periodic_timer_free(t) \
47 FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
48
51 void *userdata);
53 void (*cb)(mainloop_event_t *, void *),
54 void *userdata);
57 const struct timeval *delay);
60#define mainloop_event_free(event) \
61 FREE_AND_NULL(mainloop_event_t, mainloop_event_free_, (event))
62
63/** Defines a configuration for using libevent with Tor: passed as an argument
64 * to tor_libevent_initialize() to describe how we want to set up. */
65typedef struct tor_libevent_cfg_t {
66 /** How many CPUs should we use (not currently useful). */
68 /** How many milliseconds should we allow between updating bandwidth limits?
69 * (Not currently useful). */
72
75MOCK_DECL(struct event_base *, tor_libevent_get_base, (void));
76const char *tor_libevent_get_method(void);
77void tor_check_libevent_header_compatibility(void);
78const char *tor_libevent_get_version_str(void);
80void tor_libevent_free_all(void);
81
82int tor_init_libevent_rng(void);
83
84#ifdef TOR_UNIT_TESTS
85void tor_libevent_postfork(void);
86#endif
87
88int tor_libevent_run_event_loop(struct event_base *base, int once);
89void tor_libevent_exit_loop_after_delay(struct event_base *base,
90 const struct timeval *delay);
91void tor_libevent_exit_loop_after_callback(struct event_base *base);
92
93#ifdef COMPAT_LIBEVENT_PRIVATE
94
95/** Macro: returns the number of a Libevent version as a 4-byte number,
96 with the first three bytes representing the major, minor, and patchlevel
97 respectively of the library. The fourth byte is unused.
98
99 This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
100 2.0.1 or later. */
101#define V(major, minor, patch) \
102 (((major) << 24) | ((minor) << 16) | ((patch) << 8))
103
104STATIC void
105libevent_logging_callback(int severity, const char *msg);
106#endif /* defined(COMPAT_LIBEVENT_PRIVATE) */
107
108#endif /* !defined(TOR_COMPAT_LIBEVENT_H) */
STATIC void libevent_logging_callback(int severity, const char *msg)
void tor_libevent_initialize(tor_libevent_cfg_t *cfg)
const char * tor_libevent_get_header_version_str(void)
void suppress_libevent_log_msg(const char *msg)
bool tor_libevent_is_initialized(void)
void periodic_timer_free_(periodic_timer_t *)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *delay)
void periodic_timer_launch(periodic_timer_t *, const struct timeval *tv)
void mainloop_event_cancel(mainloop_event_t *event)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
void mainloop_event_free_(mainloop_event_t *event)
int tor_libevent_run_event_loop(struct event_base *base, int once)
const char * tor_libevent_get_version_str(void)
void tor_libevent_exit_loop_after_delay(struct event_base *base, const struct timeval *delay)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void tor_libevent_free_all(void)
periodic_timer_t * periodic_timer_new(struct event_base *base, const struct timeval *tv, void(*cb)(periodic_timer_t *timer, void *data), void *data)
const char * tor_libevent_get_method(void)
struct event_base * tor_libevent_get_base(void)
void configure_libevent_logging(void)
void periodic_timer_disable(periodic_timer_t *)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_activate(mainloop_event_t *event)
Headers for util_malloc.c.
void(* cb)(struct periodic_timer_t *, void *)
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127