svn rev #25172: trunk/src/util/ k5ev/ verto/

ghudson@MIT.EDU ghudson at MIT.EDU
Mon Sep 12 12:08:05 EDT 2011


http://src.mit.edu/fisheye/changelog/krb5/?cs=25172
Commit By: ghudson
Log Message:
Update verto sources to 2011-09-10 versions.

Also update verto-k5ev.c to match changes to verto-libev.c.


Changed Files:
U   trunk/src/util/k5ev/verto-k5ev.c
U   trunk/src/util/verto/verto-module.h
U   trunk/src/util/verto/verto.c
U   trunk/src/util/verto/verto.h
Modified: trunk/src/util/k5ev/verto-k5ev.c
===================================================================
--- trunk/src/util/k5ev/verto-k5ev.c	2011-09-10 22:58:55 UTC (rev 25171)
+++ trunk/src/util/k5ev/verto-k5ev.c	2011-09-12 16:08:04 UTC (rev 25172)
@@ -70,6 +70,12 @@
 }
 
 static void
+k5ev_ctx_reinitialize(void *ctx)
+{
+    ev_loop_fork(ctx);
+}
+
+static void
 libev_callback(EV_P_ ev_watcher *w, int revents)
 {
     if (verto_get_type(w->data) == VERTO_EV_TYPE_CHILD)
@@ -127,14 +133,19 @@
     switch (verto_get_type(ev)) {
         case VERTO_EV_TYPE_IO:
             ev_io_stop(ctx, evpriv);
+	    break;
         case VERTO_EV_TYPE_TIMEOUT:
             ev_timer_stop(ctx, evpriv);
+	    break;
         case VERTO_EV_TYPE_IDLE:
             ev_idle_stop(ctx, evpriv);
+	    break;
         case VERTO_EV_TYPE_SIGNAL:
             ev_signal_stop(ctx, evpriv);
+	    break;
         case VERTO_EV_TYPE_CHILD:
             ev_child_stop(ctx, evpriv);
+	    break;
         default:
             break;
     }
@@ -152,13 +163,13 @@
              VERTO_EV_TYPE_CHILD);
 
 verto_ctx *
-verto_new_k5ev()
+verto_new_k5ev(void)
 {
     return verto_convert_k5ev(ev_loop_new(EVFLAG_AUTO));
 }
 
 verto_ctx *
-verto_default_k5ev()
+verto_default_k5ev(void)
 {
     return verto_convert_k5ev(ev_default_loop(EVFLAG_AUTO));
 }

Modified: trunk/src/util/verto/verto-module.h
===================================================================
--- trunk/src/util/verto/verto-module.h	2011-09-10 22:58:55 UTC (rev 25171)
+++ trunk/src/util/verto/verto-module.h	2011-09-12 16:08:04 UTC (rev 25172)
@@ -37,6 +37,7 @@
         name ## _ctx_run, \
         name ## _ctx_run_once, \
         name ## _ctx_break, \
+        name ## _ctx_reinitialize, \
         name ## _ctx_add, \
         name ## _ctx_del \
     }; \
@@ -65,6 +66,7 @@
     void  (*ctx_run)(void *ctx);
     void  (*ctx_run_once)(void *ctx);
     void  (*ctx_break)(void *ctx);
+    void  (*ctx_reinitialize)(void *ctx);
     void *(*ctx_add)(void *ctx, const verto_ev *ev, verto_ev_flag *flags);
     void  (*ctx_del)(void *ctx, const verto_ev *ev, void *evpriv);
 } verto_ctx_funcs;

Modified: trunk/src/util/verto/verto.c
===================================================================
--- trunk/src/util/verto/verto.c	2011-09-10 22:58:55 UTC (rev 25171)
+++ trunk/src/util/verto/verto.c	2011-09-12 16:08:04 UTC (rev 25172)
@@ -46,7 +46,8 @@
 #ifdef WIN32
 #define pdlmsuffix ".dll"
 #define pdlmtype HMODULE
-#define pdlopenl(filename) LoadLibraryEx(filename, NULL, DONT_RESOLVE_DLL_REFERENCES)
+#define pdlopenl(filename) LoadLibraryEx(filename, NULL, \
+                                         DONT_RESOLVE_DLL_REFERENCES)
 #define pdlclose(module) FreeLibrary((pdlmtype) module)
 #define pdlsym(mod, sym) ((void *) GetProcAddress(mod, sym))
 
@@ -57,7 +58,8 @@
     return LoadLibrary(filename);
 }
 
-static char *pdlerror() {
+static char *
+pdlerror(void) {
     char *amsg;
     LPTSTR msg;
 
@@ -191,8 +193,7 @@
     size = vsnprintf(NULL, 0, fmt, apc);
     va_end(apc);
 
-    *strp = malloc(size + 1);
-    if (!size)
+    if (size <= 0 || !(*strp = malloc(size + 1)))
         return -1;
 
     return vsnprintf(*strp, size + 1, fmt, ap);
@@ -254,16 +255,23 @@
             int reqsym, verto_ev_type reqtypes, pdlmtype *dll,
             const verto_module **module)
 {
+    DIR *dir;
+    struct dirent *ent = NULL;
+
     *module = NULL;
-    DIR *dir = opendir(dirname);
+    dir = opendir(dirname);
     if (!dir)
         return 0;
 
-    struct dirent *ent = NULL;
+
     while ((ent = readdir(dir))) {
-        size_t flen = strlen(ent->d_name);
-        size_t slen = strlen(suffix);
+        char *tmp = NULL;
+        int success;
+        size_t flen, slen;
 
+        flen = strlen(ent->d_name);
+        slen = strlen(suffix);
+
         if (!strcmp(".", ent->d_name) || !strcmp("..", ent->d_name))
             continue;
         if (strstr(ent->d_name, prefix) != ent->d_name)
@@ -271,11 +279,10 @@
         if (flen < slen || strcmp(ent->d_name + flen - slen, suffix))
             continue;
 
-        char *tmp = NULL;
         if (_asprintf(&tmp, "%s/%s", dirname, ent->d_name) < 0)
             continue;
 
-        int success = do_load_file(tmp, reqsym, reqtypes, dll, module);
+        success = do_load_file(tmp, reqsym, reqtypes, dll, module);
         free(tmp);
         if (success)
             break;
@@ -394,10 +401,12 @@
 static void
 push_ev(verto_ctx *ctx, verto_ev *ev)
 {
+    verto_ev *tmp;
+
     if (!ctx || !ev)
         return;
 
-    verto_ev *tmp = ctx->events;
+    tmp = ctx->events;
     ctx->events = ev;
     ctx->events->next = tmp;
 }
@@ -543,8 +552,36 @@
     ctx->funcs.ctx_break(ctx->modpriv);
 }
 
-#define doadd(set, type) \
-    verto_ev *ev = make_ev(ctx, callback, type, flags); \
+void
+verto_reinitialize(verto_ctx *ctx)
+{
+    verto_ev *tmp, *next;
+    if (!ctx)
+        return;
+
+    /* Delete all events, but keep around the forkable ev structs */
+    for (tmp = ctx->events; tmp; tmp = next) {
+        next = ctx->events->next;
+
+        if (tmp->flags & VERTO_EV_FLAG_REINITIABLE)
+            ctx->funcs.ctx_del(ctx->modpriv, tmp, tmp->modpriv);
+        else
+            verto_del(tmp);
+    }
+
+    /* Reinit the loop */
+    ctx->funcs.ctx_reinitialize(ctx->modpriv);
+
+    /* Recreate events that were marked forkable */
+    for (tmp = ctx->events; tmp; tmp = tmp->next) {
+        tmp->actual = tmp->flags;
+        tmp->modpriv = ctx->funcs.ctx_add(ctx, tmp, &tmp->actual);
+        assert(tmp->modpriv);
+    }
+}
+
+#define doadd(ev, set, type) \
+    ev = make_ev(ctx, callback, type, flags); \
     if (ev) { \
         set; \
         ev->actual = ev->flags; \
@@ -561,29 +598,36 @@
 verto_add_io(verto_ctx *ctx, verto_ev_flag flags,
              verto_callback *callback, int fd)
 {
+    verto_ev *ev;
+
     if (fd < 0 || !(flags & (VERTO_EV_FLAG_IO_READ | VERTO_EV_FLAG_IO_WRITE)))
         return NULL;
-    doadd(ev->option.fd = fd, VERTO_EV_TYPE_IO);
+
+    doadd(ev, ev->option.fd = fd, VERTO_EV_TYPE_IO);
 }
 
 verto_ev *
 verto_add_timeout(verto_ctx *ctx, verto_ev_flag flags,
                   verto_callback *callback, time_t interval)
 {
-    doadd(ev->option.interval = interval, VERTO_EV_TYPE_TIMEOUT);
+    verto_ev *ev;
+    doadd(ev, ev->option.interval = interval, VERTO_EV_TYPE_TIMEOUT);
 }
 
 verto_ev *
 verto_add_idle(verto_ctx *ctx, verto_ev_flag flags,
                verto_callback *callback)
 {
-    doadd(, VERTO_EV_TYPE_IDLE);
+    verto_ev *ev;
+    doadd(ev,, VERTO_EV_TYPE_IDLE);
 }
 
 verto_ev *
 verto_add_signal(verto_ctx *ctx, verto_ev_flag flags,
                  verto_callback *callback, int signal)
 {
+    verto_ev *ev;
+
     if (signal < 0)
         return NULL;
 #ifndef WIN32
@@ -595,13 +639,15 @@
         if (!(flags & VERTO_EV_FLAG_PERSIST))
             return NULL;
     }
-    doadd(ev->option.signal = signal, VERTO_EV_TYPE_SIGNAL);
+    doadd(ev, ev->option.signal = signal, VERTO_EV_TYPE_SIGNAL);
 }
 
 verto_ev *
 verto_add_child(verto_ctx *ctx, verto_ev_flag flags,
                 verto_callback *callback, verto_proc proc)
 {
+    verto_ev *ev;
+
     if (flags & VERTO_EV_FLAG_PERSIST) /* persist makes no sense */
         return NULL;
 #ifdef WIN32
@@ -610,19 +656,18 @@
     if (proc < 1)
 #endif
         return NULL;
-    doadd(ev->option.child.proc = proc, VERTO_EV_TYPE_CHILD);
+    doadd(ev, ev->option.child.proc = proc, VERTO_EV_TYPE_CHILD);
 }
 
-int
+void
 verto_set_private(verto_ev *ev, void *priv, verto_callback *free)
 {
     if (!ev)
-        return 0;
+        return;
     if (ev->onfree && free)
         ev->onfree(ev->ctx, ev);
     ev->priv = priv;
     ev->onfree = free;
-    return 1;
 }
 
 void *

Modified: trunk/src/util/verto/verto.h
===================================================================
--- trunk/src/util/verto/verto.h	2011-09-10 22:58:55 UTC (rev 25171)
+++ trunk/src/util/verto/verto.h	2011-09-12 16:08:04 UTC (rev 25172)
@@ -59,7 +59,8 @@
     VERTO_EV_FLAG_PRIORITY_HIGH = 1 << 3,
     VERTO_EV_FLAG_IO_READ = 1 << 4,
     VERTO_EV_FLAG_IO_WRITE = 1 << 5,
-    _VERTO_EV_FLAG_MAX = VERTO_EV_FLAG_IO_WRITE
+    VERTO_EV_FLAG_REINITIABLE = 1 << 6,
+    _VERTO_EV_FLAG_MAX = VERTO_EV_FLAG_REINITIABLE
 } verto_ev_flag;
 
 typedef void (verto_callback)(verto_ctx *ctx, verto_ev *ev);
@@ -210,6 +211,20 @@
 verto_break(verto_ctx *ctx);
 
 /**
+ * Re-initializes the verto_ctx.
+ *
+ * This function deletes all events, except those which have set the
+ * VERTO_EV_FLAG_REINITIABLE flag. If you fork(), you MUST call this in the
+ * child process after the fork!
+ *
+ * @see verto_new()
+ * @see verto_default()
+ * @param ctx The verto_ctx to re-initialize.
+ */
+void
+verto_reinitialize(verto_ctx *ctx);
+
+/**
  * Adds a callback executed when a file descriptor is ready to be read/written.
  *
  * All verto_ev events are automatically freed when their parent verto_ctx is
@@ -345,9 +360,8 @@
  * @param ev The verto_ev
  * @param priv The private value to store
  * @param free The callback used to free the data or NULL
- * @return 1 on success or 0 on failure
  */
-int
+void
 verto_set_private(verto_ev *ev, void *priv, verto_callback *free);
 
 /**




More information about the cvs-krb5 mailing list