diff options
Diffstat (limited to 'src/util/k5ev')
| -rw-r--r-- | src/util/k5ev/Makefile.in | 42 | ||||
| -rw-r--r-- | src/util/k5ev/README | 29 | ||||
| -rw-r--r-- | src/util/k5ev/deps | 7 | ||||
| -rw-r--r-- | src/util/k5ev/k5ev.c | 36 | ||||
| -rw-r--r-- | src/util/k5ev/libverto-k5ev.exports | 1 | ||||
| -rw-r--r-- | src/util/k5ev/verto-k5ev.c | 163 |
6 files changed, 278 insertions, 0 deletions
diff --git a/src/util/k5ev/Makefile.in b/src/util/k5ev/Makefile.in new file mode 100644 index 0000000000..857a85b082 --- /dev/null +++ b/src/util/k5ev/Makefile.in @@ -0,0 +1,42 @@ +mydir=util$(S)k5ev +BUILDTOP=$(REL)..$(S).. +RELDIR=../util/k5ev +DEFS= + +SED = sed + +LIBBASE=verto-k5ev +LIBMAJOR=0 +LIBMINOR=0 + +LOCALINCLUDES=-I. -I$(srcdir)/../verto + +# Turn off extra warnings since we're not going to clean up libev's code. +WARN_CFLAGS= + +STLIBOBJS=verto-k5ev.o +LIBOBJS=$(OUTPRE)verto-k5ev.$(OBJEXT) +SRCS=verto-k5ev.c + +STOBJLISTS=OBJS.ST +SHLIB_EXPLIBS= $(LIBS) -lverto -lm # libm needed for ceil() currently. +SHLIB_DIRS=-L$(TOPLIBD) +SHLIB_RDIRS=$(KRB5_LIBDIR) + +all-unix:: all-liblinks + +install-unix:: install-libs + +clean-unix:: clean-liblinks clean-libs clean-libobjs + +rename.h: $(srcdir)/Symbols.ev + $(RM) $@ + $(SED) -e 's/.*/#define & k5&/' < $(srcdir)/Symbols.ev > $@ + +clean:: + $(RM) rename.h + +depend:: rename.h + +@lib_frag@ +@libobj_frag@ diff --git a/src/util/k5ev/README b/src/util/k5ev/README new file mode 100644 index 0000000000..1165f37f70 --- /dev/null +++ b/src/util/k5ev/README @@ -0,0 +1,29 @@ +This directory builds a private libverto module using an embedded +libev with renamed symbols (so we don't leak libev symbols into the +namespace on platforms where we can't control the export list). The +module is not intended to be used directly by applications, so it has +no header file. + +libev has built-in support for this kind of embedding, so we don't +have to modify the libev sources. Following libev's documentation, +the following files have been copied from the ev sources: + + ev.h + ev_vars.h + ev_wrap.h + ev.c + ev_select.c + ev_poll.c + ev_win32.c + Symbols.ev + +(Symbols.ev wasn't included in the 4.04 tar file due to an oversight, +so it is taken from the appropriate tag in libev's source repository.) + +To rename the exported symbols, we create rename.h from Symbols.ev. +We also use Symbols.ev to construct the library export list. +(Renaming libev's symbols would be unnecessary if libev's embedding +had support for making its API symbols static, but it currently does +not.) The source file verto-k5ev.c wraps ev.c with appropriate +embedding defines, and then defines the libverto module functions +using the slightly modified contents of libverto's verto-ev.c. diff --git a/src/util/k5ev/deps b/src/util/k5ev/deps new file mode 100644 index 0000000000..2921c31e2c --- /dev/null +++ b/src/util/k5ev/deps @@ -0,0 +1,7 @@ +# +# Generated makefile dependencies follow. +# +verto-k5ev.so verto-k5ev.po $(OUTPRE)verto-k5ev.$(OBJEXT): \ + $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/verto.h \ + $(srcdir)/../verto/verto-module.h ev.c ev.h ev_poll.c \ + ev_vars.h ev_wrap.h rename.h verto-k5ev.c diff --git a/src/util/k5ev/k5ev.c b/src/util/k5ev/k5ev.c new file mode 100644 index 0000000000..42e4df877c --- /dev/null +++ b/src/util/k5ev/k5ev.c @@ -0,0 +1,36 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* util/k5ev/k5ev.c - Wrapper to create libk5ev from libev sources */ +/* + * Copyright (C) 2011 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + */ + +#include "rename.h" +#include "autoconf.h" +#define EV_STANDALONE 1 +#define EV_FEATURES 0x5f /* Everything but back ends */ +#ifdef HAVE_POLL_H +#define EV_USE_POLL 1 +#else +#define EV_USE_SELECT 1 +#endif +#include "ev.c" diff --git a/src/util/k5ev/libverto-k5ev.exports b/src/util/k5ev/libverto-k5ev.exports new file mode 100644 index 0000000000..ee1b8d00eb --- /dev/null +++ b/src/util/k5ev/libverto-k5ev.exports @@ -0,0 +1 @@ +verto_module_table diff --git a/src/util/k5ev/verto-k5ev.c b/src/util/k5ev/verto-k5ev.c new file mode 100644 index 0000000000..947085b85c --- /dev/null +++ b/src/util/k5ev/verto-k5ev.c @@ -0,0 +1,163 @@ +/* + * Copyright 2011 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* An edited version of verto's verto-libev.c, using an embedded libev with + * renamed symbols. */ + +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include <verto.h> +#include <verto-module.h> +#include "rename.h" +#include "autoconf.h" +#define EV_STANDALONE 1 +#define EV_FEATURES 0x5f /* Everything but back ends */ +#ifdef HAVE_POLL_H +#define EV_USE_POLL 1 +#else +#define EV_USE_SELECT 1 +#endif +#include "ev.c" + +static void +libev_ctx_free(void *ctx) +{ + if (ctx != EV_DEFAULT) + ev_loop_destroy(ctx); +} + +static void +libev_ctx_run(void *ctx) +{ + ev_run(ctx, 0); +} + +static void +libev_ctx_run_once(void *ctx) +{ + ev_run(ctx, EVRUN_ONCE); +} + +static void +libev_ctx_break(void *ctx) +{ + ev_break(ctx, EVBREAK_ONE); +} + +static void +libev_callback(EV_P_ ev_watcher *w, int revents) +{ + if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD) + verto_set_proc_status(w->data, ((ev_child*) w)->rstatus); + + verto_fire(w->data); +} + +#define setuptype(type, priv, ...) \ + type ## w = malloc(sizeof(ev_ ## type)); \ + if (!type ## w) \ + return NULL; \ + ev_ ## type ## _init(type ## w, (EV_CB(type, (*))) __VA_ARGS__); \ + type ## w->data = (void *) priv; \ + ev_ ## type ## _start(ctx, type ## w); \ + return type ## w + +static void * +libev_ctx_add(void *ctx, const verto_ev *ev, verto_ev_flag *flags) +{ + ev_io *iow = NULL; + ev_timer *timerw = NULL; + ev_idle *idlew = NULL; + ev_signal *signalw = NULL; + ev_child *childw = NULL; + ev_tstamp interval; + int events = EV_NONE; + + *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, ev, libev_callback, verto_get_fd(ev), events); + case VERTO_EV_TYPE_TIMEOUT: + interval = ((ev_tstamp) verto_get_interval(ev)) / 1000.0; + setuptype(timer, ev, libev_callback, interval, interval); + case VERTO_EV_TYPE_IDLE: + setuptype(idle, ev, libev_callback); + case VERTO_EV_TYPE_SIGNAL: + setuptype(signal, ev, libev_callback, verto_get_signal(ev)); + case VERTO_EV_TYPE_CHILD: + *flags &= ~VERTO_EV_FLAG_PERSIST; /* Child events don't persist */ + setuptype(child, ev, libev_callback, verto_get_proc(ev), 0); + default: + return NULL; /* Not supported */ + } +} + +static void +libev_ctx_del(void *ctx, const verto_ev *ev, void *evpriv) +{ + switch (verto_get_type(ev)) { + case VERTO_EV_TYPE_IO: + ev_io_stop(ctx, evpriv); + case VERTO_EV_TYPE_TIMEOUT: + ev_timer_stop(ctx, evpriv); + case VERTO_EV_TYPE_IDLE: + ev_idle_stop(ctx, evpriv); + case VERTO_EV_TYPE_SIGNAL: + ev_signal_stop(ctx, evpriv); + case VERTO_EV_TYPE_CHILD: + ev_child_stop(ctx, evpriv); + default: + break; + } + + free(evpriv); +} + +static verto_ctx *verto_new_libev(void); +static verto_ctx *verto_default_libev(void); + +VERTO_MODULE(libev, ev_loop_new, + VERTO_EV_TYPE_IO | + VERTO_EV_TYPE_TIMEOUT | + VERTO_EV_TYPE_IDLE | + VERTO_EV_TYPE_SIGNAL | + VERTO_EV_TYPE_CHILD); + +static verto_ctx * +verto_new_libev() +{ + return verto_convert(libev, ev_loop_new(EVFLAG_AUTO)); +} + +static verto_ctx * +verto_default_libev() +{ + return verto_convert(libev, ev_default_loop(EVFLAG_AUTO)); +} |
