compat_libevent.c File Reference

Wrappers to handle porting between different versions of libevent. More...

#include "orconfig.h"
#include "compat.h"
#include "compat_libevent.h"
#include "util.h"
#include "log.h"
#include <event.h>

Defines

#define V(major, minor, patch)   (((major) << 24) | ((minor) << 16) | ((patch) << 8))
#define V_OLD(major, minor, patch)   V((major), (minor), (patch)-'a'+1)
#define LE_OLD   V(0,0,0)
#define LE_OTHER   V(0,0,99)

Typedefs

typedef uint32_t le_version_t

Functions

static le_version_t tor_get_libevent_version (const char **v_out)
static void libevent_logging_callback (int severity, const char *msg)
void configure_libevent_logging (void)
void suppress_libevent_log_msg (const char *msg)
struct event * tor_event_new (struct event_base *base, int sock, short what, void(*cb)(int, short, void *), void *arg)
struct event * tor_evtimer_new (struct event_base *base, void(*cb)(int, short, void *), void *arg)
struct event * tor_evsignal_new (struct event_base *base, int sig, void(*cb)(int, short, void *), void *arg)
void tor_event_free (struct event *ev)
void tor_libevent_initialize (void)
struct event_base * tor_libevent_get_base (void)
const char * tor_libevent_get_method (void)
static le_version_t tor_decode_libevent_version (const char *v)
static int le_versions_compatibility (le_version_t v)
const char * tor_libevent_get_version_str (void)
void tor_check_libevent_version (const char *m, int server, const char **badness_out)
void tor_check_libevent_header_compatibility (void)

Variables

static const char * suppress_msg = NULL
struct event_base * the_event_base = NULL


Detailed Description

Wrappers to handle porting between different versions of libevent.

In an ideal world, we'd just use Libevent 2.0 from now on. But as of June 2009, Libevent 2.0 is still in alpha, and we will have old versions of Libevent for the forseeable future.


Typedef Documentation

typedef uint32_t le_version_t

A number representing a version of Libevent.

This is a 4-byte number, with the first three bytes representing the major, minor, and patchlevel respectively of the library. The fourth byte is unused.

This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent 2.0.1 or later. For versions of Libevent before 1.4.0, which followed the format of "1.0, 1.0a, 1.0b", we define 1.0 to be equivalent to 1.0.0, 1.0a to be equivalent to 1.0.1, and so on.


Function Documentation

void configure_libevent_logging ( void   ) 

Set hook to intercept log messages from libevent.

References libevent_logging_callback().

Referenced by init_libevent().

static int le_versions_compatibility ( le_version_t  v  )  [static]

Return an integer representing the binary interface of a Libevent library. Two different versions with different numbers are sure not to be binary compatible. Two different versions with the same numbers have a decent chance of binary compatibility.

References V.

Referenced by tor_check_libevent_header_compatibility().

static void libevent_logging_callback ( int  severity,
const char *  msg 
) [static]

Callback function passed to event_set_log() so we can intercept log messages from libevent.

References LD_GENERAL, LD_NET, and suppress_msg.

Referenced by configure_libevent_logging().

void suppress_libevent_log_msg ( const char *  msg  ) 

Ignore any libevent log message that contains msg.

References suppress_msg.

Referenced by init_libevent().

void tor_check_libevent_header_compatibility ( void   ) 

See whether the headers we were built against differ from the library we linked against so much that we're likely to crash. If so, warn the user.

References LD_GENERAL, le_versions_compatibility(), and tor_decode_libevent_version().

Referenced by init_libevent().

void tor_check_libevent_version ( const char *  m,
int  server,
const char **  badness_out 
)

Compare the current Libevent method and version to a list of versions which are known not to work. Warn the user as appropriate.

References LD_GENERAL, tor_get_libevent_version(), and V.

Referenced by init_libevent().

static le_version_t tor_decode_libevent_version ( const char *  v  )  [static]

Return the le_version_t for the current version of libevent. If the version is very new, return LE_OTHER. If the version is so old that it doesn't support event_get_version(), return LE_OLD. DOCDOC

References V.

Referenced by tor_check_libevent_header_compatibility(), and tor_get_libevent_version().

void tor_event_free ( struct event *  ev  ) 

Work-alike replacement for event_free() on pre-Libevent-2.0 systems.

References tor_free.

struct event* tor_event_new ( struct event_base *  base,
int  sock,
short  what,
void(*)(int, short, void *)  cb,
void *  arg 
) [read]

Work-alike replacement for event_new() on pre-Libevent-2.0 systems.

References tor_libevent_get_base().

Referenced by connection_add(), tor_evsignal_new(), and tor_evtimer_new().

struct event* tor_evsignal_new ( struct event_base *  base,
int  sig,
void(*)(int, short, void *)  cb,
void *  arg 
) [read]

Work-alike replacement for evsignal_new() on pre-Libevent-2.0 systems.

References tor_event_new().

Referenced by handle_signals().

struct event* tor_evtimer_new ( struct event_base *  base,
void(*)(int, short, void *)  cb,
void *  arg 
) [read]

Work-alike replacement for evtimer_new() on pre-Libevent-2.0 systems.

References tor_event_new().

Referenced by dns_launch_correctness_checks(), and second_elapsed_callback().

static le_version_t tor_get_libevent_version ( const char **  v_out  )  [static]

Return the version number of the currently running version of Libevent. See le_version_t for info on the format.

References tor_decode_libevent_version().

Referenced by tor_check_libevent_version(), and tor_libevent_initialize().

struct event_base* tor_libevent_get_base ( void   )  [read]

const char* tor_libevent_get_method ( void   ) 

Return the name of the Libevent backend we're using.

Referenced by do_main_loop(), init_libevent(), and tor_libevent_initialize().

const char* tor_libevent_get_version_str ( void   ) 

Return a string representation of the version of the currently running version of Libevent.

Referenced by init_libevent().

void tor_libevent_initialize ( void   ) 

Initialize the Libevent library and set up the event base.

References LD_GENERAL, tor_assert, tor_get_libevent_version(), and tor_libevent_get_method().

Referenced by init_libevent().


Variable Documentation

const char* suppress_msg = NULL [static]

A string which, if it appears in a libevent log, should be ignored.

Referenced by libevent_logging_callback(), and suppress_libevent_log_msg().

struct event_base* the_event_base = NULL

Global event base for use by the main thread.


Generated on Tue May 25 00:30:40 2010 for tor by  doxygen 1.5.6