Skip to content

Commit

Permalink
Update bundled libverto to 0.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
greghudson committed Sep 3, 2012
1 parent fe285ec commit 6b60871
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 63 deletions.
41 changes: 33 additions & 8 deletions src/util/k5ev/verto-k5ev.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,40 @@ k5ev_ctx_reinitialize(verto_mod_ctx *ctx)
static void
libev_callback(EV_P_ ev_watcher *w, int revents)
{
if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
verto_ev_flag state = VERTO_EV_FLAG_NONE;

if (verto_get_type(w->data)== VERTO_EV_TYPE_CHILD)
verto_set_proc_status(w->data, ((ev_child*) w)->rstatus);

if (revents & EV_READ)
state |= VERTO_EV_FLAG_IO_READ;
if (revents & EV_WRITE)
state |= VERTO_EV_FLAG_IO_WRITE;
if (revents & EV_ERROR)
state |= VERTO_EV_FLAG_IO_ERROR;

verto_set_fd_state(w->data, state);
verto_fire(w->data);
}

static void
k5ev_ctx_set_flags(verto_mod_ctx *ctx, const verto_ev *ev,
verto_mod_ev *evpriv)
{
if (verto_get_type(ev) == VERTO_EV_TYPE_IO) {
int events = EV_NONE;

if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
events |= EV_READ;
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
events |= EV_WRITE;

ev_io_stop(ctx, (ev_io*) evpriv);
ev_io_set(((ev_io*) evpriv), verto_get_fd(ev), events);
ev_io_start(ctx, (ev_io*) evpriv);
}
}

#define setuptype(type, ...) \
w.type = malloc(sizeof(ev_ ## type)); \
if (w.type) { \
Expand All @@ -120,17 +148,12 @@ k5ev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
ev_child *child;
} w;
ev_tstamp interval;
int events = EV_NONE;

w.watcher = NULL;
*flags |= VERTO_EV_FLAG_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
events |= EV_READ;
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
events |= EV_WRITE;
setuptype(io, libev_callback, verto_get_fd(ev), events);
setuptype(io, libev_callback, verto_get_fd(ev), EV_NONE);
case VERTO_EV_TYPE_TIMEOUT:
interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
setuptype(timer, libev_callback, interval, interval);
Expand All @@ -145,8 +168,10 @@ k5ev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
break; /* Not supported */
}

if (w.watcher)
if (w.watcher) {
w.watcher->data = (void*) ev;
k5ev_ctx_set_flags(ctx, ev, w.watcher);
}
return w.watcher;
}

Expand Down
41 changes: 33 additions & 8 deletions src/util/k5ev/verto-libev.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,40 @@ libev_ctx_reinitialize(verto_mod_ctx *ctx)
static void
libev_callback(EV_P_ ev_watcher *w, int revents)
{
if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
verto_ev_flag state = VERTO_EV_FLAG_NONE;

if (verto_get_type(w->data)== VERTO_EV_TYPE_CHILD)
verto_set_proc_status(w->data, ((ev_child*) w)->rstatus);

if (revents & EV_READ)
state |= VERTO_EV_FLAG_IO_READ;
if (revents & EV_WRITE)
state |= VERTO_EV_FLAG_IO_WRITE;
if (revents & EV_ERROR)
state |= VERTO_EV_FLAG_IO_ERROR;

verto_set_fd_state(w->data, state);
verto_fire(w->data);
}

static void
libev_ctx_set_flags(verto_mod_ctx *ctx, const verto_ev *ev,
verto_mod_ev *evpriv)
{
if (verto_get_type(ev) == VERTO_EV_TYPE_IO) {
int events = EV_NONE;

if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
events |= EV_READ;
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
events |= EV_WRITE;

ev_io_stop(ctx, (ev_io*) evpriv);
ev_io_set(((ev_io*) evpriv), verto_get_fd(ev), events);
ev_io_start(ctx, (ev_io*) evpriv);
}
}

#define setuptype(type, ...) \
w.type = malloc(sizeof(ev_ ## type)); \
if (w.type) { \
Expand All @@ -104,17 +132,12 @@ libev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
ev_child *child;
} w;
ev_tstamp interval;
int events = EV_NONE;

w.watcher = NULL;
*flags |= VERTO_EV_FLAG_PERSIST;
switch (verto_get_type(ev)) {
case VERTO_EV_TYPE_IO:
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_READ)
events |= EV_READ;
if (verto_get_flags(ev) & VERTO_EV_FLAG_IO_WRITE)
events |= EV_WRITE;
setuptype(io, libev_callback, verto_get_fd(ev), events);
setuptype(io, libev_callback, verto_get_fd(ev), EV_NONE);
case VERTO_EV_TYPE_TIMEOUT:
interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0;
setuptype(timer, libev_callback, interval, interval);
Expand All @@ -129,8 +152,10 @@ libev_ctx_add(verto_mod_ctx *ctx, const verto_ev *ev, verto_ev_flag *flags)
break; /* Not supported */
}

if (w.watcher)
if (w.watcher) {
w.watcher->data = (void*) ev;
libev_ctx_set_flags(ctx, ev, w.watcher);
}
return w.watcher;
}

Expand Down
4 changes: 4 additions & 0 deletions src/util/verto/libverto.exports
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ verto_default
verto_del
verto_fire
verto_free
verto_get_ctx
verto_get_fd
verto_get_fd_state
verto_get_flags
verto_get_interval
verto_get_private
Expand All @@ -22,6 +24,8 @@ verto_new
verto_reinitialize
verto_run
verto_run_once
verto_set_allocator
verto_set_default
verto_set_fd_state
verto_set_private
verto_set_proc_status
49 changes: 47 additions & 2 deletions src/util/verto/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,51 @@ dllerror(void) {
LocalFree(msg);
return amsg;
}
#elif defined(aix)
#include "sys/ldr.h"

struct Dl_info {
const char* dli_fname;
};

static int
dladdr(void* s, Dl_info* i)
{
static const size_t bufSize = 4096;
G__FastAllocString buf(bufSize);
char* pldi = buf;
int r;

r = loadquery(L_GETINFO, pldi, bufSize);
if (r == -1) {
i->dli_fname = NULL;
return 0;
}

for (ld_info* ldi = (ld_info*) buf;
ldi->ldinfo_next;
ldi += ldi->ldinfo_next) {
char* textBegin = (char*) ldi->ldinfo_textorg;
if (textBegin < s) {
char* textEnd = textBegin + ldi->ldinfo_textsize;
if (textEnd > s) {
i->dli_fname = ldi->ldinfo_filename;
return 1;
}
}
}

// First is main(), skip.
ld_info* ldi = (ld_info*) pldi;
while (ldi->ldinfo_next) {
pldi += ldi->ldinfo_next;
ldi = (ld_info*) pldi;

}

i->dli_fname = NULL;
return 0;
}
#else
#define _GNU_SOURCE
#include <stdlib.h>
Expand Down Expand Up @@ -80,14 +125,14 @@ module_get_filename_for_symbol(void *addr, char **filename)

if (!GetModuleFileNameA(mod, tmp, MAX_PATH))
return 0;
#else /* WIN32 */
#else
const char *tmp;
Dl_info dlinfo;

if (!dladdr(addr, &dlinfo))
return 0;
tmp = dlinfo.dli_fname;
#endif /* WIN32 */
#endif

if (filename) {
*filename = strdup(tmp);
Expand Down
21 changes: 20 additions & 1 deletion src/util/verto/verto-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef void verto_mod_ctx;
typedef void verto_mod_ev;
#endif

#define VERTO_MODULE_VERSION 2
#define VERTO_MODULE_VERSION 3
#define VERTO_MODULE_TABLE(name) verto_module_table_ ## name
#define VERTO_MODULE(name, symb, types) \
static verto_ctx_funcs name ## _funcs = { \
Expand All @@ -46,6 +46,7 @@ typedef void verto_mod_ev;
name ## _ctx_run_once, \
name ## _ctx_break, \
name ## _ctx_reinitialize, \
name ## _ctx_set_flags, \
name ## _ctx_add, \
name ## _ctx_del \
}; \
Expand Down Expand Up @@ -75,6 +76,9 @@ typedef struct {
/* Required */ void (*ctx_run_once)(verto_mod_ctx *ctx);
/* Optional */ void (*ctx_break)(verto_mod_ctx *ctx);
/* Optional */ void (*ctx_reinitialize)(verto_mod_ctx *ctx);
/* Optional */ void (*ctx_set_flags)(verto_mod_ctx *ctx,
const verto_ev *ev,
verto_mod_ev *modev);
/* Required */ verto_mod_ev *(*ctx_add)(verto_mod_ctx *ctx,
const verto_ev *ev,
verto_ev_flag *flags);
Expand Down Expand Up @@ -166,4 +170,19 @@ verto_fire(verto_ev *ev);
void
verto_set_proc_status(verto_ev *ev, verto_proc_status status);

/**
* Sets the state of the fd which caused this event to fire.
*
* This function does nothing if the verto_ev is not a io type.
*
* Only the flags VERTO_EV_FLAG_IO_(READ|WRITE|ERROR) are supported. All other
* flags are unset.
*
* @see verto_add_io()
* @param ev The verto_ev to set the state in.
* @param state The fd state.
*/
void
verto_set_fd_state(verto_ev *ev, verto_ev_flag state);

#endif /* VERTO_MODULE_H_ */

0 comments on commit 6b60871

Please sign in to comment.