The branch, master has been updated
       via  6910d3a lib: Implement poll_timeout
       via  d9dd026 lib: Remove "num_contexts" from poll_funcs_state
       via  e987e62 lib: Remove "num_watches" from poll_funcs_state
       via  dccd968 lib: Change poll_funcs to take direct timevals
       via  552c7de lib: Fix poll_func_timeout prototypes
      from  a2086e9 lib: Cleanup includes in messages_dgm

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 6910d3a4d416ce8631440b8b3023f526bdfb4eb8
Author: Volker Lendecke <[email protected]>
Date:   Tue Oct 20 11:39:09 2015 +0200

    lib: Implement poll_timeout
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>
    
    Autobuild-User(master): Volker Lendecke <[email protected]>
    Autobuild-Date(master): Sat Aug 20 13:38:37 CEST 2016 on sn-devel-144

commit d9dd026815e96b7def5c8a1097550ca40ba48193
Author: Volker Lendecke <[email protected]>
Date:   Tue Oct 20 11:15:38 2015 +0200

    lib: Remove "num_contexts" from poll_funcs_state
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit e987e6212a1b57da2c0ca137dea1f188c55d1b39
Author: Volker Lendecke <[email protected]>
Date:   Tue Oct 20 10:43:06 2015 +0200

    lib: Remove "num_watches" from poll_funcs_state
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit dccd96867708e419c9e596a2fc518bd0041ca5c6
Author: Volker Lendecke <[email protected]>
Date:   Tue Oct 20 11:40:38 2015 +0200

    lib: Change poll_funcs to take direct timevals
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

commit 552c7de94d6701df565d69cd68d96dfe1e6f4f98
Author: Volker Lendecke <[email protected]>
Date:   Mon Oct 19 21:23:13 2015 +0200

    lib: Fix poll_func_timeout prototypes
    
    Signed-off-by: Volker Lendecke <[email protected]>
    Reviewed-by: Ralph Boehme <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 lib/poll_funcs/poll_funcs.h        |   8 +-
 lib/poll_funcs/poll_funcs_tevent.c | 280 +++++++++++++++++++++++++++++++------
 2 files changed, 245 insertions(+), 43 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/poll_funcs/poll_funcs.h b/lib/poll_funcs/poll_funcs.h
index 6072eb5..b16f07f 100644
--- a/lib/poll_funcs/poll_funcs.h
+++ b/lib/poll_funcs/poll_funcs.h
@@ -92,14 +92,14 @@ struct poll_funcs {
         *
         * @param[in] funcs The callback array
         * @param[in] tv The time when the timeout should trigger
-        * @param[in] callback Function to call at time "ts"
+        * @param[in] callback Function to call at time "tv"
         * @param[in] private_data Pointer to give back to callback
         *
         * @return A new poll_timeout struct
         */
 
        struct poll_timeout *(*timeout_new)(
-               const struct poll_funcs *funcs, const struct timeval *tv,
+               const struct poll_funcs *funcs, const struct timeval tv,
                void (*callback)(struct poll_timeout *t, void *private_data),
                void *private_data);
 
@@ -107,11 +107,11 @@ struct poll_funcs {
         * @brief Change the timeout of a watch
         *
         * @param[in] t The timeout watch to change
-        * @param[in] ts The new trigger time
+        * @param[in] tv The new trigger time
         */
 
        void (*timeout_update)(struct poll_timeout *t,
-                              const struct timespec *ts);
+                              const struct timeval tv);
 
        /**
         * @brief Free a poll_timeout
diff --git a/lib/poll_funcs/poll_funcs_tevent.c 
b/lib/poll_funcs/poll_funcs_tevent.c
index 8fdf080..3059ebc 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -29,7 +29,7 @@
 
 struct poll_watch {
        struct poll_funcs_state *state;
-       unsigned slot;          /* index into state->watches[] */
+       size_t slot;            /* index into state->watches[] */
        int fd;
        int events;
        void (*callback)(struct poll_watch *w, int fd, short events,
@@ -37,19 +37,30 @@ struct poll_watch {
        void *private_data;
 };
 
+struct poll_timeout {
+       struct poll_funcs_state *state;
+       size_t slot;            /* index into state->timeouts[] */
+       struct timeval tv;
+       void (*callback)(struct poll_timeout *t, void *private_data);
+       void *private_data;
+};
+
 struct poll_funcs_state {
        /*
         * "watches" is the array of all watches that we have handed out via
         * funcs->watch_new(). The "watches" array can contain NULL pointers.
         */
-       unsigned num_watches;
        struct poll_watch **watches;
 
        /*
+        * Like "watches" for timeouts;
+        */
+       struct poll_timeout **timeouts;
+
+       /*
         * "contexts is the array of tevent_contexts that serve
         * "watches". "contexts" can contain NULL pointers.
         */
-       unsigned num_contexts;
        struct poll_funcs_tevent_context **contexts;
 };
 
@@ -59,6 +70,7 @@ struct poll_funcs_tevent_context {
        unsigned slot;          /* index into state->contexts[] */
        struct tevent_context *ev;
        struct tevent_fd **fdes; /* same indexes as state->watches[] */
+       struct tevent_timer **timers;  /* same indexes as state->timeouts[] */
 };
 
 /*
@@ -102,12 +114,14 @@ static short tevent_to_poll_events(uint16_t flags)
  * Find or create a free slot in state->watches[]
  */
 static bool poll_funcs_watch_find_slot(struct poll_funcs_state *state,
-                                      unsigned *slot)
+                                      size_t *slot)
 {
        struct poll_watch **watches;
-       unsigned i;
+       size_t i, num_watches, num_contexts;
 
-       for (i=0; i<state->num_watches; i++) {
+       num_watches = talloc_array_length(state->watches);
+
+       for (i=0; i<num_watches; i++) {
                if (state->watches[i] == NULL) {
                        *slot = i;
                        return true;
@@ -115,31 +129,35 @@ static bool poll_funcs_watch_find_slot(struct 
poll_funcs_state *state,
        }
 
        watches = talloc_realloc(state, state->watches, struct poll_watch *,
-                                state->num_watches + 1);
+                                num_watches + 1);
        if (watches == NULL) {
                return false;
        }
-       watches[state->num_watches] = NULL;
+       watches[num_watches] = NULL;
        state->watches = watches;
 
-       for (i=0; i<state->num_contexts; i++) {
+       num_contexts = talloc_array_length(state->contexts);
+
+       for (i=0; i<num_contexts; i++) {
                struct tevent_fd **fdes;
                struct poll_funcs_tevent_context *c = state->contexts[i];
                if (c == NULL) {
                        continue;
                }
                fdes = talloc_realloc(c, c->fdes, struct tevent_fd *,
-                                     state->num_watches + 1);
+                                     num_watches + 1);
                if (fdes == NULL) {
+                       state->watches = talloc_realloc(
+                               state, state->watches, struct poll_watch *,
+                               num_watches);
                        return false;
                }
                c->fdes = fdes;
 
-               fdes[state->num_watches] = NULL;
+               fdes[num_watches] = NULL;
        }
 
-       *slot = state->num_watches;
-       state->num_watches += 1;
+       *slot = num_watches;
 
        return true;
 }
@@ -158,7 +176,7 @@ static struct poll_watch *tevent_watch_new(
        struct poll_funcs_state *state = talloc_get_type_abort(
                funcs->private_data, struct poll_funcs_state);
        struct poll_watch *w;
-       unsigned i, slot;
+       size_t i, slot, num_contexts;
 
        if (!poll_funcs_watch_find_slot(state, &slot)) {
                return NULL;
@@ -179,7 +197,9 @@ static struct poll_watch *tevent_watch_new(
 
        talloc_set_destructor(w, poll_watch_destructor);
 
-       for (i=0; i<state->num_contexts; i++) {
+       num_contexts = talloc_array_length(state->contexts);
+
+       for (i=0; i<num_contexts; i++) {
                struct poll_funcs_tevent_context *c = state->contexts[i];
                if (c == NULL) {
                        continue;
@@ -200,12 +220,13 @@ fail:
 static int poll_watch_destructor(struct poll_watch *w)
 {
        struct poll_funcs_state *state = w->state;
-       unsigned slot = w->slot;
-       unsigned i;
+       size_t num_contexts = talloc_array_length(state->contexts);
+       size_t slot = w->slot;
+       size_t i;
 
        TALLOC_FREE(state->watches[slot]);
 
-       for (i=0; i<state->num_contexts; i++) {
+       for (i=0; i<num_contexts; i++) {
                struct poll_funcs_tevent_context *c = state->contexts[i];
                if (c == NULL) {
                        continue;
@@ -219,12 +240,13 @@ static int poll_watch_destructor(struct poll_watch *w)
 static void tevent_watch_update(struct poll_watch *w, short events)
 {
        struct poll_funcs_state *state = w->state;
-       unsigned slot = w->slot;
-       unsigned i;
+       size_t num_contexts = talloc_array_length(state->contexts);
+       size_t slot = w->slot;
+       size_t i;
 
        w->events = poll_events_to_tevent(events);
 
-       for (i=0; i<state->num_contexts; i++) {
+       for (i=0; i<num_contexts; i++) {
                struct poll_funcs_tevent_context *c = state->contexts[i];
                if (c == NULL) {
                        continue;
@@ -243,24 +265,181 @@ static void tevent_watch_free(struct poll_watch *w)
        TALLOC_FREE(w);
 }
 
+static bool poll_funcs_timeout_find_slot(struct poll_funcs_state *state,
+                                        size_t *slot)
+{
+       struct poll_timeout **timeouts;
+       size_t i, num_timeouts, num_contexts;
+
+       num_timeouts = talloc_array_length(state->timeouts);
+
+       for (i=0; i<num_timeouts; i++) {
+               if (state->timeouts[i] == NULL) {
+                       *slot = i;
+                       return true;
+               }
+       }
+
+       timeouts = talloc_realloc(state, state->timeouts,
+                                 struct poll_timeout *,
+                                 num_timeouts + 1);
+       if (timeouts == NULL) {
+               return false;
+       }
+       timeouts[num_timeouts] = NULL;
+       state->timeouts = timeouts;
+
+       num_contexts = talloc_array_length(state->contexts);
+
+       for (i=0; i<num_contexts; i++) {
+               struct tevent_timer **timers;
+               struct poll_funcs_tevent_context *c = state->contexts[i];
+               if (c == NULL) {
+                       continue;
+               }
+               timers = talloc_realloc(c, c->timers, struct tevent_timer *,
+                                       num_timeouts + 1);
+               if (timers == NULL) {
+                       state->timeouts = talloc_realloc(
+                               state, state->timeouts, struct poll_timeout *,
+                               num_timeouts);
+                       return false;
+               }
+               c->timers = timers;
+
+               timers[num_timeouts] = NULL;
+       }
+
+       *slot = num_timeouts;
+
+       return true;
+}
+
+static void poll_funcs_timer_handler(struct tevent_context *ev,
+                                    struct tevent_timer *te,
+                                    struct timeval current_time,
+                                    void *private_data);
+static int poll_timeout_destructor(struct poll_timeout *t);
+
 static struct poll_timeout *tevent_timeout_new(
-       const struct poll_funcs *funcs, const struct timeval *tv,
+       const struct poll_funcs *funcs, const struct timeval tv,
        void (*callback)(struct poll_timeout *t, void *private_data),
        void *private_data)
 {
-       /* not implemented yet */
+       struct poll_funcs_state *state = talloc_get_type_abort(
+               funcs->private_data, struct poll_funcs_state);
+       struct poll_timeout *t;
+       size_t i, slot, num_contexts;
+
+       if (!poll_funcs_timeout_find_slot(state, &slot)) {
+               return NULL;
+       }
+
+       t = talloc(state->timeouts, struct poll_timeout);
+       if (t == NULL) {
+               return NULL;
+       }
+       t->state = state;
+       t->slot = slot;
+       t->tv = tv;
+       t->callback = callback;
+       t->private_data = private_data;
+
+       talloc_set_destructor(t, poll_timeout_destructor);
+
+       num_contexts = talloc_array_length(state->contexts);
+
+       for (i=0; i<num_contexts; i++) {
+               struct poll_funcs_tevent_context *c = state->contexts[i];
+               if (c == NULL) {
+                       continue;
+               }
+               c->timers[slot] = tevent_add_timer(
+                       c->ev, c->timers, tv, poll_funcs_timer_handler, t);
+               if (c->timers[slot] == NULL) {
+                       goto fail;
+               }
+       }
+       return t;
+
+fail:
+       TALLOC_FREE(t);
        return NULL;
 }
 
+static int poll_timeout_destructor(struct poll_timeout *t)
+{
+       struct poll_funcs_state *state = t->state;
+       size_t num_contexts = talloc_array_length(state->contexts);
+       size_t slot = t->slot;
+       size_t i;
+
+       TALLOC_FREE(state->timeouts[slot]);
+
+       for (i=0; i<num_contexts; i++) {
+               struct poll_funcs_tevent_context *c = state->contexts[i];
+               if (c == NULL) {
+                       continue;
+               }
+               TALLOC_FREE(c->timers[slot]);
+       }
+
+       return 0;
+}
+
+static void poll_funcs_timer_handler(struct tevent_context *ev,
+                                    struct tevent_timer *te,
+                                    struct timeval current_time,
+                                    void *private_data)
+{
+       struct poll_timeout *t = talloc_get_type_abort(
+               private_data, struct poll_timeout);
+       struct poll_funcs_state *state = t->state;
+       size_t slot = t->slot;
+       size_t i, num_contexts;
+
+       num_contexts = talloc_array_length(state->contexts);
+
+       for (i=0; i<num_contexts; i++) {
+               struct poll_funcs_tevent_context *c = state->contexts[i];
+               if (c == NULL) {
+                       continue;
+               }
+               TALLOC_FREE(c->timers[slot]);
+       }
+
+       t->callback(t, t->private_data);
+}
+
 static void tevent_timeout_update(struct poll_timeout *t,
-                                 const struct timespec *ts)
+                                 const struct timeval tv)
 {
-       return;
+       struct poll_funcs_state *state = t->state;
+       size_t num_contexts = talloc_array_length(state->contexts);
+       size_t slot = t->slot;
+       size_t i;
+
+       for (i=0; i<num_contexts; i++) {
+               struct poll_funcs_tevent_context *c = state->contexts[i];
+               if (c == NULL) {
+                       continue;
+               }
+               TALLOC_FREE(c->timers[slot]);
+
+               c->timers[slot] = tevent_add_timer(
+                       c->ev, c->timers, tv, poll_funcs_timer_handler, t);
+               if (c->timers[slot] == NULL) {
+                       /*
+                        * We just free'ed the space, why did this fail??
+                        */
+                       abort();
+               }
+       }
 }
 
 static void tevent_timeout_free(struct poll_timeout *t)
 {
-       return;
+       TALLOC_FREE(t);
 }
 
 static int poll_funcs_state_destructor(struct poll_funcs_state *state);
@@ -294,12 +473,13 @@ struct poll_funcs *poll_funcs_init_tevent(TALLOC_CTX 
*mem_ctx)
 
 static int poll_funcs_state_destructor(struct poll_funcs_state *state)
 {
-       unsigned i;
+       size_t num_watches = talloc_array_length(state->watches);
+       size_t i;
        /*
         * Make sure the watches are cleared before the contexts. The watches
         * have destructors attached to them that clean up the fde's
         */
-       for (i=0; i<state->num_watches; i++) {
+       for (i=0; i<num_watches; i++) {
                TALLOC_FREE(state->watches[i]);
        }
        return 0;
@@ -310,12 +490,13 @@ static int poll_funcs_state_destructor(struct 
poll_funcs_state *state)
  */
 static bool poll_funcs_context_slot_find(struct poll_funcs_state *state,
                                         struct tevent_context *ev,
-                                        unsigned *slot)
+                                        size_t *slot)
 {
        struct poll_funcs_tevent_context **contexts;
-       unsigned i;
+       size_t num_contexts = talloc_array_length(state->contexts);
+       size_t i;
 
-       for (i=0; i<state->num_contexts; i++) {
+       for (i=0; i<num_contexts; i++) {
                struct poll_funcs_tevent_context *ctx = state->contexts[i];
 
                if ((ctx == NULL) || (ctx->ev == ev)) {
@@ -326,15 +507,14 @@ static bool poll_funcs_context_slot_find(struct 
poll_funcs_state *state,
 
        contexts = talloc_realloc(state, state->contexts,
                                  struct poll_funcs_tevent_context *,
-                                 state->num_contexts + 1);
+                                 num_contexts + 1);
        if (contexts == NULL) {
                return false;
        }
        state->contexts = contexts;
-       state->contexts[state->num_contexts] = NULL;
+       state->contexts[num_contexts] = NULL;
 
-       *slot = state->num_contexts;
-       state->num_contexts += 1;
+       *slot = num_contexts;
 
        return true;
 }
@@ -347,7 +527,9 @@ static struct poll_funcs_tevent_context 
*poll_funcs_tevent_context_new(
        struct tevent_context *ev, unsigned slot)
 {
        struct poll_funcs_tevent_context *ctx;
-       unsigned i;
+       size_t num_watches = talloc_array_length(state->watches);
+       size_t num_timeouts = talloc_array_length(state->timeouts);
+       size_t i;
 
        ctx = talloc(mem_ctx, struct poll_funcs_tevent_context);
        if (ctx == NULL) {
@@ -359,12 +541,12 @@ static struct poll_funcs_tevent_context 
*poll_funcs_tevent_context_new(
        ctx->ev = ev;
        ctx->slot = slot;
 
-       ctx->fdes = talloc_array(ctx, struct tevent_fd *, state->num_watches);
+       ctx->fdes = talloc_array(ctx, struct tevent_fd *, num_watches);
        if (ctx->fdes == NULL) {
                goto fail;
        }
 
-       for (i=0; i<state->num_watches; i++) {
+       for (i=0; i<num_watches; i++) {
                struct poll_watch *w = state->watches[i];
 
                if (w == NULL) {
@@ -377,6 +559,26 @@ static struct poll_funcs_tevent_context 
*poll_funcs_tevent_context_new(
                        goto fail;
                }
        }
+
+       ctx->timers = talloc_array(ctx, struct tevent_timer *, num_timeouts);
+       if (ctx->timers == NULL) {
+               goto fail;
+       }
+
+       for (i=0; i<num_timeouts; i++) {
+               struct poll_timeout *t = state->timeouts[i];
+
+               if (t == NULL) {
+                       ctx->timers[i] = NULL;
+                       continue;
+               }
+               ctx->timers[i] = tevent_add_timer(ctx->ev, ctx->timers, t->tv,
+                                                 poll_funcs_timer_handler, t);
+               if (ctx->timers[i] == 0) {
+                       goto fail;
+               }
+       }
+
        talloc_set_destructor(ctx, poll_funcs_tevent_context_destructor);
        return ctx;
 fail:
@@ -417,7 +619,7 @@ void *poll_funcs_tevent_register(TALLOC_CTX *mem_ctx, 
struct poll_funcs *f,
        struct poll_funcs_state *state = talloc_get_type_abort(
                f->private_data, struct poll_funcs_state);
        struct poll_funcs_tevent_handle *handle;


-- 
Samba Shared Repository

Reply via email to