Ignore:
Timestamp:
May 27, 2009, 9:09:42 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/lib/events.c

    r138 r232  
    6464        DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te,
    6565                te->event_name));
    66         DLIST_REMOVE(te->event_ctx->timed_events, te);
     66        if (te->event_ctx) {
     67                DLIST_REMOVE(te->event_ctx->timed_events, te);
     68        }
    6769        return 0;
    6870}
     
    134136        struct event_context *event_ctx = fde->event_ctx;
    135137
    136         DLIST_REMOVE(event_ctx->fd_events, fde);
     138        if (event_ctx) {
     139                DLIST_REMOVE(event_ctx->fd_events, fde);
     140        }
    137141        return 0;
    138142}
     
    242246                int selrtn, fd_set *read_fds, fd_set *write_fds)
    243247{
    244         bool fired = False;
    245         struct fd_event *fde, *next;
    246 
    247         /* Run all events that are pending, not just one (as we
    248            did previously. */
    249 
    250         while (event_ctx->timed_events) {
    251                 struct timeval now;
    252                 GetTimeOfDay(&now);
    253 
    254                 if (timeval_compare(
    255                             &now, &event_ctx->timed_events->when) < 0) {
    256                         /* Nothing to do yet */
    257                         DEBUG(11, ("run_events: Nothing to do\n"));
    258                         break;
    259                 }
     248        struct fd_event *fde;
     249        struct timeval now;
     250
     251        GetTimeOfDay(&now);
     252
     253        if ((event_ctx->timed_events != NULL)
     254            && (timeval_compare(&now, &event_ctx->timed_events->when) >= 0)) {
    260255
    261256                DEBUG(10, ("Running event \"%s\" %lx\n",
     
    268263                        event_ctx->timed_events->private_data);
    269264
    270                 fired = True;
    271         }
    272 
    273         if (fired) {
    274                 /*
    275                  * We might have changed the socket status during the timed
    276                  * events, return to run select again.
    277                  */
    278                 return True;
     265                return true;
    279266        }
    280267
     
    283270                 * No fd ready
    284271                 */
    285                 return fired;
    286         }
    287 
    288         for (fde = event_ctx->fd_events; fde; fde = next) {
     272                return false;
     273        }
     274
     275        for (fde = event_ctx->fd_events; fde; fde = fde->next) {
    289276                uint16 flags = 0;
    290277
    291                 next = fde->next;
    292278                if (FD_ISSET(fde->fd, read_fds)) flags |= EVENT_FD_READ;
    293279                if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE;
     
    295281                if (flags) {
    296282                        fde->handler(event_ctx, fde, flags, fde->private_data);
    297                         fired = True;
    298                 }
    299         }
    300 
    301         return fired;
     283                        return true;
     284                }
     285        }
     286
     287        return false;
    302288}
    303289
     
    355341}
    356342
     343static int event_context_destructor(struct event_context *ev)
     344{
     345        while (ev->fd_events != NULL) {
     346                ev->fd_events->event_ctx = NULL;
     347                DLIST_REMOVE(ev->fd_events, ev->fd_events);
     348        }
     349        while (ev->timed_events != NULL) {
     350                ev->timed_events->event_ctx = NULL;
     351                DLIST_REMOVE(ev->timed_events, ev->timed_events);
     352        }
     353        return 0;
     354}
     355
     356void event_context_reinit(struct event_context *ev)
     357{
     358        event_context_destructor(ev);
     359        return;
     360}
     361
    357362struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
    358363{
    359         return TALLOC_ZERO_P(NULL, struct event_context);
    360 }
    361 
    362 int set_event_dispatch_time(struct event_context *event_ctx,
    363                             const char *event_name, struct timeval when)
    364 {
    365         struct timed_event *te;
    366 
    367         for (te = event_ctx->timed_events; te; te = te->next) {
    368                 if (strcmp(event_name, te->event_name) == 0) {
    369                         DLIST_REMOVE(event_ctx->timed_events, te);
    370                         te->when = when;
    371                         add_event_by_time(te);
    372                         return 1;
    373                 }
    374         }
    375         return 0;
    376 }
    377 
    378 /* Returns 1 if event was found and cancelled, 0 otherwise. */
    379 
    380 int cancel_named_event(struct event_context *event_ctx,
    381                        const char *event_name)
    382 {
    383         struct timed_event *te;
    384 
    385         for (te = event_ctx->timed_events; te; te = te->next) {
    386                 if (strcmp(event_name, te->event_name) == 0) {
    387                         TALLOC_FREE(te);
    388                         return 1;
    389                 }
    390         }
    391         return 0;
     364        struct event_context *result;
     365
     366        result = TALLOC_ZERO_P(mem_ctx, struct event_context);
     367        if (result == NULL) {
     368                return NULL;
     369        }
     370
     371        talloc_set_destructor(result, event_context_destructor);
     372        return result;
    392373}
    393374
Note: See TracChangeset for help on using the changeset viewer.