From 4506b633927a13ea3319db9928c5de28cd68fcb1 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Sun, 3 Feb 2019 22:44:33 +0000 Subject: [PATCH] libcompat: remove The old libcompat compatibility library no longer has any users. Remove it. --- configure.ac | 1 - src/common/Makefile.am | 2 - src/common/libcompat/Makefile.am | 18 -- src/common/libcompat/reactor.c | 297 ------------------------------- src/common/libcompat/reactor.h | 83 --------- 5 files changed, 401 deletions(-) delete mode 100644 src/common/libcompat/Makefile.am delete mode 100644 src/common/libcompat/reactor.c delete mode 100644 src/common/libcompat/reactor.h diff --git a/configure.ac b/configure.ac index 2163e5f92147..3b94e8eef7ff 100644 --- a/configure.ac +++ b/configure.ac @@ -389,7 +389,6 @@ AC_CONFIG_FILES( \ src/common/libkvs/Makefile \ src/common/libjob/Makefile \ src/common/libsubprocess/Makefile \ - src/common/libcompat/Makefile \ src/common/liboptparse/Makefile \ src/common/libidset/Makefile \ src/common/libtomlc99/Makefile \ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 5b20ce273532..0d05726692ba 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -6,7 +6,6 @@ SUBDIRS = libtap \ libflux \ libkvs \ libjob \ - libcompat \ liboptparse \ libidset \ libtomlc99 \ @@ -26,7 +25,6 @@ libflux_internal_la_LIBADD = \ $(builddir)/libutil/libutil.la \ $(builddir)/libidset/libidset.la \ $(builddir)/libev/libev.la \ - $(builddir)/libcompat/libcompat.la \ $(builddir)/libtomlc99/libtomlc99.la \ $(JANSSON_LIBS) $(ZMQ_LIBS) $(LIBPTHREAD) $(LIBUTIL) \ $(LIBDL) $(LIBRT) $(FLUX_SECURITY_LIBS) $(LIBSODIUM_LIBS) diff --git a/src/common/libcompat/Makefile.am b/src/common/libcompat/Makefile.am deleted file mode 100644 index 3c478247039e..000000000000 --- a/src/common/libcompat/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -AM_CFLAGS = \ - $(WARNING_CFLAGS) \ - $(CODE_COVERAGE_CFLAGS) - -AM_LDFLAGS = \ - $(CODE_COVERAGE_LIBS) - -AM_CPPFLAGS = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/src/include \ - -I$(top_builddir)/src/common/libflux \ - $(ZMQ_CFLAGS) - -noinst_LTLIBRARIES = libcompat.la - -libcompat_la_SOURCES = \ - reactor.c \ - reactor.h diff --git a/src/common/libcompat/reactor.c b/src/common/libcompat/reactor.c deleted file mode 100644 index fc390bcf81d1..000000000000 --- a/src/common/libcompat/reactor.c +++ /dev/null @@ -1,297 +0,0 @@ -/************************************************************\ - * Copyright 2014 Lawrence Livermore National Security, LLC - * (c.f. AUTHORS, NOTICE.LLNS, COPYING) - * - * This file is part of the Flux resource manager framework. - * For details, see https://github.com/flux-framework. - * - * SPDX-License-Identifier: LGPL-3.0 -\************************************************************/ - -#if HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#include -#include -#include - -#include "src/common/libflux/handle.h" -#include "src/common/libflux/reactor.h" -#include "src/common/libflux/msg_handler.h" -#include "src/common/libflux/message.h" -#include "src/common/libutil/xzmalloc.h" -#include "src/common/libutil/log.h" -#include "src/common/libutil/oom.h" - -#include "reactor.h" - - -#define HASHKEY_LEN 80 - -struct ctx { - zhash_t *watchers; - int timer_seq; -}; - -struct msg_compat { - flux_msg_handler_t *mh; - FluxMsgHandler fn; - void *arg; -}; - -struct fd_compat { - flux_t *h; - flux_watcher_t *w; - FluxFdHandler fn; - void *arg; -}; - -struct timer_compat { - flux_t *h; - flux_watcher_t *w; - FluxTmoutHandler fn; - void *arg; - int id; - bool oneshot; -}; - - -static void freectx (void *arg) -{ - struct ctx *ctx = arg; - - zhash_destroy (&ctx->watchers); - free (ctx); -} - -static struct ctx *getctx (flux_t *h) -{ - struct ctx *ctx = flux_aux_get (h, "reactor_compat"); - - if (!ctx) { - ctx = xzmalloc (sizeof (*ctx)); - ctx->watchers = zhash_new (); - if (!ctx->watchers) - oom (); - flux_aux_set (h, "reactor_compat", ctx, freectx); - } - return ctx; -} - -static int events_to_libzmq (int events) -{ - int e = 0; - if (events & FLUX_POLLIN) - e |= ZMQ_POLLIN; - if (events & FLUX_POLLOUT) - e |= ZMQ_POLLOUT; - if (events & FLUX_POLLERR) - e |= ZMQ_POLLERR; - return e; -} - -static int libzmq_to_events (int events) -{ - int e = 0; - if (events & ZMQ_POLLIN) - e |= FLUX_POLLIN; - if (events & ZMQ_POLLOUT) - e |= FLUX_POLLOUT; - if (events & ZMQ_POLLERR) - e |= FLUX_POLLERR; - return e; -} - -/* message - */ -void msg_compat_cb (flux_t *h, flux_msg_handler_t *mh, - const flux_msg_t *msg, void *arg) -{ - struct msg_compat *compat = arg; - flux_msg_t *cpy = NULL; - int type; - - if (flux_msg_get_type (msg, &type) < 0) - goto done; - if (!(cpy = flux_msg_copy (msg, true))) - goto done; - if (compat->fn (h, type, &cpy, compat->arg) < 0) - flux_reactor_stop_error (flux_get_reactor (h)); -done: - flux_msg_destroy (cpy); -} - -static void msg_compat_free (struct msg_compat *c) -{ - if (c) { - flux_msg_handler_destroy (c->mh); - free (c); - } -} - -static int msghandler_add (flux_t *h, int typemask, const char *pattern, - FluxMsgHandler cb, void *arg) -{ - struct ctx *ctx = getctx (h); - struct flux_match match = { - .typemask = typemask, - .topic_glob = (char *)pattern, - .matchtag = FLUX_MATCHTAG_NONE, - }; - char hashkey[HASHKEY_LEN]; - struct msg_compat *c = xzmalloc (sizeof (*c)); - - c->fn = cb; - c->arg = arg; - if (!(c->mh = flux_msg_handler_create (h, match, msg_compat_cb, c))) { - free (c); - return -1; - } - flux_msg_handler_start (c->mh); - snprintf (hashkey, sizeof (hashkey), "msg:%d:%s", typemask, pattern); - zhash_update (ctx->watchers, hashkey, c); - zhash_freefn (ctx->watchers, hashkey, (zhash_free_fn *)msg_compat_free); - return 0; -} - -int flux_msghandler_add (flux_t *h, int typemask, const char *pattern, - FluxMsgHandler cb, void *arg) -{ - return msghandler_add (h, typemask, pattern, cb, arg); -} - -void flux_msghandler_remove (flux_t *h, int typemask, const char *pattern) -{ - struct ctx *ctx = getctx (h); - struct msg_compat *c; - char hashkey[HASHKEY_LEN]; - - snprintf (hashkey, sizeof (hashkey), "msg:%d:%s", typemask, pattern); - if ((c = zhash_lookup (ctx->watchers, hashkey))) { - flux_msg_handler_stop (c->mh); - zhash_delete (ctx->watchers, hashkey); - } -} - -/* fd - */ - -static void fd_compat_free (struct fd_compat *c) -{ - if (c) { - flux_watcher_destroy (c->w); - free (c); - } -} - -static void fd_compat_cb (flux_reactor_t *r, flux_watcher_t *w, int revents, - void *arg) -{ - struct fd_compat *c = arg; - int fd = flux_fd_watcher_get_fd (w); - if (c->fn (c->h, fd, events_to_libzmq (revents), c->arg) < 0) - flux_reactor_stop_error (r); -} - - -int flux_fdhandler_add (flux_t *h, int fd, short events, - FluxFdHandler cb, void *arg) -{ - struct ctx *ctx = getctx (h); - struct fd_compat *c = xzmalloc (sizeof (*c)); - char hashkey[HASHKEY_LEN]; - - c->h = h; - c->fn = cb; - c->arg = arg; - c->w = flux_fd_watcher_create (flux_get_reactor (h), fd, - libzmq_to_events (events), fd_compat_cb,c); - if (!c->w) { - free (c); - return -1; - } - flux_watcher_start (c->w); - snprintf (hashkey, sizeof (hashkey), "fd:%d:%hd", fd, events); - zhash_update (ctx->watchers, hashkey, c); - zhash_freefn (ctx->watchers, hashkey, (zhash_free_fn *)fd_compat_free); - return 0; -} - -void flux_fdhandler_remove (flux_t *h, int fd, short events) -{ - struct ctx *ctx = getctx (h); - struct fd_compat *c; - char hashkey[HASHKEY_LEN]; - - snprintf (hashkey, sizeof (hashkey), "fd:%d:%hd", fd, events); - if ((c = zhash_lookup (ctx->watchers, hashkey))) { - flux_watcher_stop (c->w); - zhash_delete (ctx->watchers, hashkey); - } -} - -/* Timer - */ - -static void timer_compat_free (struct timer_compat *c) -{ - if (c) { - flux_watcher_destroy (c->w); - free (c); - } -} - -static void timer_compat_cb (flux_reactor_t *r, flux_watcher_t *w, - int revents, void *arg) -{ - struct timer_compat *c = arg; - if (c->fn (c->h, c->arg) < 0) - flux_reactor_stop_error (r); -} - -int flux_tmouthandler_add (flux_t *h, unsigned long msec, bool oneshot, - FluxTmoutHandler cb, void *arg) -{ - struct ctx *ctx = getctx (h); - struct timer_compat *c = xzmalloc (sizeof (*c)); - char hashkey[HASHKEY_LEN]; - double after = 1E-3 * msec; - double rpt = oneshot ? 0 : after; - - c->h = h; - c->fn = cb; - c->arg = arg; - c->oneshot = oneshot; - c->id = ctx->timer_seq++; - c->w = flux_timer_watcher_create (flux_get_reactor (h), - after, rpt, timer_compat_cb, c); - if (!c->w) { - free (c); - return -1; - } - flux_watcher_start (c->w); - snprintf (hashkey, sizeof (hashkey), "timer:%d", c->id); - zhash_update (ctx->watchers, hashkey, c); - zhash_freefn (ctx->watchers, hashkey, (zhash_free_fn *)timer_compat_free); - return c->id; -} - -void flux_tmouthandler_remove (flux_t *h, int timer_id) -{ - struct ctx *ctx = getctx (h); - struct timer_compat *c; - char hashkey[HASHKEY_LEN]; - - snprintf (hashkey, sizeof (hashkey), "timer:%d", timer_id); - if ((c = zhash_lookup (ctx->watchers, hashkey))) { - flux_watcher_stop (c->w); - zhash_delete (ctx->watchers, hashkey); - } -} - -/* - * vi:tabstop=4 shiftwidth=4 expandtab - */ diff --git a/src/common/libcompat/reactor.h b/src/common/libcompat/reactor.h deleted file mode 100644 index 00dbc5926360..000000000000 --- a/src/common/libcompat/reactor.h +++ /dev/null @@ -1,83 +0,0 @@ -/************************************************************\ - * Copyright 2014 Lawrence Livermore National Security, LLC - * (c.f. AUTHORS, NOTICE.LLNS, COPYING) - * - * This file is part of the Flux resource manager framework. - * For details, see https://github.com/flux-framework. - * - * SPDX-License-Identifier: LGPL-3.0 -\************************************************************/ - -#ifndef _FLUX_COMPAT_REACTOR_H -#define _FLUX_COMPAT_REACTOR_H - -#include - -#define flux_msghandler_add compat_msghandler_add -#define flux_msghandler_remove compat_msghandler_remove -#define flux_fdhandler_add compat_fdhandler_add -#define flux_fdhandler_remove compat_fdhandler_remove -#define flux_tmouthandler_add compat_tmouthandler_add -#define flux_tmouthandler_remove compat_tmouthandler_remove - -/* FluxMsgHandler indicates msg is "consumed" by destroying it. - * Callbacks return 0 on success, -1 on error and set errno. - * Error terminates reactor, and flux_reactor_start() returns -1. - */ -typedef int (*FluxMsgHandler)(flux_t *h, int typemask, flux_msg_t **msg, - void *arg); -typedef int (*FluxFdHandler)(flux_t *h, int fd, short revents, void *arg); -typedef int (*FluxTmoutHandler)(flux_t *h, void *arg); - -typedef struct { - int typemask; - const char *pattern; - FluxMsgHandler cb; -} msghandler_t; - -/* Register a FluxMsgHandler callback to be called whenever a message - * matching typemask and pattern (glob) is received. The callback is - * added to the beginning of the msghandler list. - */ -int flux_msghandler_add (flux_t *h, int typemask, const char *pattern, - FluxMsgHandler cb, void *arg) - __attribute__ ((deprecated)); - -/* Unregister a FluxMsgHandler callback. Only the first callback with - * identical typemask and pattern is removed. - */ -void flux_msghandler_remove (flux_t *h, int typemask, const char *pattern) - __attribute__ ((deprecated)); - - -/* Register a FluxFdHandler callback to be called whenever an event - * in the 'events' mask occurs on the given file descriptor 'fd'. - */ -int flux_fdhandler_add (flux_t *h, int fd, short events, - FluxFdHandler cb, void *arg) - __attribute__ ((deprecated)); - -/* Unregister a FluxFdHandler callback. Only the first callback with - * identical fd and events is removed. - */ -void flux_fdhandler_remove (flux_t *h, int fd, short events) - __attribute__ ((deprecated)); - - -/* Register a FluxTmoutHandler callback. Returns timer_id or -1 on error. - */ -int flux_tmouthandler_add (flux_t *h, unsigned long msec, bool oneshot, - FluxTmoutHandler cb, void *arg) - __attribute__ ((deprecated)); - -/* Unregister a FluxTmoutHandler callback. - */ -void flux_tmouthandler_remove (flux_t *h, int timer_id) - __attribute__ ((deprecated)); - - -#endif /* !_FLUX_COMPAT_REACTOR_H */ - -/* - * vi:tabstop=4 shiftwidth=4 expandtab - */