ub_event_pluggable.c File Reference

This file contains an implementation for the indirection layer for pluggable events that calls the registered pluggable event loop. More...

#include "config.h"
#include <sys/time.h>
#include "util/ub_event.h"
#include "libunbound/unbound-event.h"
#include "util/netevent.h"
#include "util/log.h"
#include "util/fptr_wlist.h"
#include "event2/event.h"
#include "event2/event_struct.h"
#include "event2/event_compat.h"

Data Structures

struct  my_event_base
 
struct  my_event
 

Macros

#define NATIVE_BITS(b)   (b)
 
#define NATIVE_BITS_CB(c)   (c)
 
#define EVFLAG_AUTO   0
 
#define AS_MY_EVENT_BASE(x)   ((struct my_event_base*)x)
 
#define AS_MY_EVENT(x)   ((struct my_event*)x)
 

Functions

const char * ub_event_get_version (void)
 Returns event-base type. More...
 
static void my_event_add_bits (struct ub_event *ev, short bits)
 
static void my_event_del_bits (struct ub_event *ev, short bits)
 
static void my_event_set_fd (struct ub_event *ev, int fd)
 
static void my_event_free (struct ub_event *ev)
 
static int my_event_add (struct ub_event *ev, struct timeval *tv)
 
static int my_event_del (struct ub_event *ev)
 
static int my_timer_add (struct ub_event *ev, struct ub_event_base *base, void(*cb)(int, short, void *), void *arg, struct timeval *tv)
 
static int my_timer_del (struct ub_event *ev)
 
static int my_signal_add (struct ub_event *ev, struct timeval *tv)
 
static int my_signal_del (struct ub_event *ev)
 
static void my_winsock_unregister_wsaevent (struct ub_event *ev)
 
static void my_winsock_tcp_wouldblock (struct ub_event *ev, int eventbits)
 
static void my_event_base_free (struct ub_event_base *base)
 
static int my_event_base_dispatch (struct ub_event_base *base)
 
static int my_event_base_loopexit (struct ub_event_base *base, struct timeval *tv)
 
static struct ub_eventmy_event_new (struct ub_event_base *base, int fd, short bits, void(*cb)(int, short, void *), void *arg)
 
static struct ub_eventmy_signal_new (struct ub_event_base *base, int fd, void(*cb)(int, short, void *), void *arg)
 
static struct ub_eventmy_winsock_register_wsaevent (struct ub_event_base *base, void *wsaevent, void(*cb)(int, short, void *), void *arg)
 
struct ub_event_baseub_default_event_base (int sigs, time_t *time_secs, struct timeval *time_tv)
 Return a default event base. More...
 
struct ub_event_baseub_libevent_event_base (struct event_base *base)
 Return an ub_event_base constructed for the given libevent event base.
 
struct event_base * ub_libevent_get_event_base (struct ub_event_base *base)
 Return the libevent base underlying the given ub_event_base. More...
 
void ub_get_event_sys (struct ub_event_base *ub_base, const char **n, const char **s, const char **m)
 Return the name, system and method for the pluggable event base.
 
void ub_event_base_free (struct ub_event_base *base)
 Free event base. More...
 
int ub_event_base_dispatch (struct ub_event_base *base)
 Run the event base.
 
int ub_event_base_loopexit (struct ub_event_base *base)
 exit that loop
 
struct ub_eventub_event_new (struct ub_event_base *base, int fd, short bits, void(*cb)(int, short, void *), void *arg)
 Create a new ub_event for the event base.
 
struct ub_eventub_signal_new (struct ub_event_base *base, int fd, void(*cb)(int, short, void *), void *arg)
 Create a new ub_event signal for the event base.
 
struct ub_eventub_winsock_register_wsaevent (struct ub_event_base *base, void *wsaevent, void(*cb)(int, short, void *), void *arg)
 Create a new ub_event associated with the wsaevent for the event base.
 
void ub_event_add_bits (struct ub_event *ev, short bits)
 Add event bits for this event to fire on.
 
void ub_event_del_bits (struct ub_event *ev, short bits)
 Configure the event so it will not longer fire on given bits.
 
void ub_event_set_fd (struct ub_event *ev, int fd)
 Change or set the file descriptor on the event.
 
void ub_event_free (struct ub_event *ev)
 free the event
 
int ub_event_add (struct ub_event *ev, struct timeval *tv)
 Activate the event. More...
 
int ub_event_del (struct ub_event *ev)
 Deactivate the event.
 
int ub_timer_add (struct ub_event *ev, struct ub_event_base *base, void(*cb)(int, short, void *), void *arg, struct timeval *tv)
 Reconfigure and activate a timeout event.
 
int ub_timer_del (struct ub_event *ev)
 Deactivate the timeout event.
 
int ub_signal_add (struct ub_event *ev, struct timeval *tv)
 Activate a signal event.
 
int ub_signal_del (struct ub_event *ev)
 Deactivate a signal event.
 
void ub_winsock_unregister_wsaevent (struct ub_event *ev)
 Free a with a wsaevent associated event.
 
void ub_winsock_tcp_wouldblock (struct ub_event *ev, int eventbits)
 Signal the eventloop when a TCP windows socket will block on next read or write (given by the eventbits)
 
void ub_comm_base_now (struct comm_base *cb)
 Equip the comm_base with the current time. More...
 

Variables

static struct ub_event_vmt default_event_vmt
 
static struct ub_event_base_vmt default_event_base_vmt
 

Detailed Description

This file contains an implementation for the indirection layer for pluggable events that calls the registered pluggable event loop.

It also defines a default pluggable event loop based on the default libevent (compatibility) functions.

Function Documentation

◆ ub_event_get_version()

const char* ub_event_get_version ( void  )

Returns event-base type.

Could be "mini-event", "winsock-event" for the daemon compile, and will be "pluggable-event<PACKAGE_VERSION>" for libunbound.

◆ ub_default_event_base()

struct ub_event_base* ub_default_event_base ( int  sigs,
time_t *  time_secs,
struct timeval *  time_tv 
)

Return a default event base.

In the daemon this will be the only event bases used.

◆ ub_libevent_get_event_base()

struct event_base* ub_libevent_get_event_base ( struct ub_event_base base)

Return the libevent base underlying the given ub_event_base.

Will return NULL when the ub_event_base does not have an underlying libevent event base

References ub_event_base::vmt.

Referenced by ub_get_event_sys().

◆ ub_event_base_free()

void ub_event_base_free ( struct ub_event_base base)

Free event base.

Free events yourself

References fptr_ok, ub_event_base::magic, UB_EVENT_MAGIC, and ub_event_base::vmt.

◆ ub_event_add()

int ub_event_add ( struct ub_event ev,
struct timeval *  tv 
)

Activate the event.

The given timeval is an timeout value.

References fptr_ok, ub_event::magic, UB_EVENT_MAGIC, and ub_event::vmt.

◆ ub_comm_base_now()

void ub_comm_base_now ( struct comm_base cb)

Equip the comm_base with the current time.

fillup the time values in the event base

Variable Documentation

◆ default_event_vmt

struct ub_event_vmt default_event_vmt
static
Initial value:
= {
my_event_add_bits, my_event_del_bits, my_event_set_fd,
my_event_free, my_event_add, my_event_del,
my_timer_add, my_timer_del, my_signal_add, my_signal_del,
my_winsock_unregister_wsaevent, my_winsock_tcp_wouldblock
}

◆ default_event_base_vmt

struct ub_event_base_vmt default_event_base_vmt
static
Initial value:
= {
my_event_base_free, my_event_base_dispatch,
my_event_base_loopexit, my_event_new, my_signal_new,
my_winsock_register_wsaevent
}