From 022e2f81991f12637ca0eeb3a030d4cec69d6fb9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 5 Jan 2009 19:47:45 +0800 Subject: clean event context after child is forked. Signed-off-by: Stefan Metzmacher --- source3/lib/events.c | 6 ++++++ source3/lib/util.c | 3 +++ 2 files changed, 9 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/events.c b/source3/lib/events.c index 8bbc9497ac..7d4cdc209b 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -369,6 +369,12 @@ static int event_context_destructor(struct event_context *ev) return 0; } +void event_context_reinit(struct event_context *ev) +{ + event_context_destructor(ev); + return; +} + struct event_context *event_context_init(TALLOC_CTX *mem_ctx) { struct event_context *result; diff --git a/source3/lib/util.c b/source3/lib/util.c index d00a764c1d..08ea5add7a 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -949,6 +949,7 @@ void become_daemon(bool Fork, bool no_process_group) } bool reinit_after_fork(struct messaging_context *msg_ctx, + struct event_context *ev_ctx, bool parent_longlived) { NTSTATUS status; @@ -976,6 +977,8 @@ bool reinit_after_fork(struct messaging_context *msg_ctx, return false; } + event_context_reinit(ev_ctx); + return true; } -- cgit From 077d5cff71bdb95f5829ae27309958e4661e4184 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 4 Jan 2009 19:53:09 +0100 Subject: s3:events: remove unused stuff metze --- source3/lib/events.c | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/events.c b/source3/lib/events.c index 7d4cdc209b..0e3fecfaa2 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -44,16 +44,6 @@ struct fd_event { void *private_data; }; -#define EVENT_FD_WRITEABLE(fde) \ - event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_WRITE) -#define EVENT_FD_READABLE(fde) \ - event_set_fd_flags(fde, event_get_fd_flags(fde) | EVENT_FD_READ) - -#define EVENT_FD_NOT_WRITEABLE(fde) \ - event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_WRITE) -#define EVENT_FD_NOT_READABLE(fde) \ - event_set_fd_flags(fde, event_get_fd_flags(fde) & ~EVENT_FD_READ) - struct event_context { struct timed_event *timed_events; struct fd_event *fd_events; @@ -225,21 +215,6 @@ bool event_add_to_select_args(struct event_context *event_ctx, return True; } -bool events_pending(struct event_context *event_ctx) -{ - struct fd_event *fde; - - if (event_ctx->timed_events != NULL) { - return True; - } - for (fde = event_ctx->fd_events; fde; fde = fde->next) { - if (fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) { - return True; - } - } - return False; -} - bool run_events(struct event_context *event_ctx, int selrtn, fd_set *read_fds, fd_set *write_fds) { -- cgit From c34d5f445aae8180650dd2cae994bd5573870c04 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 5 Jan 2009 10:22:50 +0100 Subject: s3:events: change event_add_timed() prototype to match samba4 metze --- source3/lib/async_req.c | 13 ++++++------- source3/lib/ctdbd_conn.c | 3 +-- source3/lib/events.c | 8 ++++---- source3/lib/smbldap.c | 12 ++++++------ 4 files changed, 17 insertions(+), 19 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/async_req.c b/source3/lib/async_req.c index ac06df65a3..13b64ba79a 100644 --- a/source3/lib/async_req.c +++ b/source3/lib/async_req.c @@ -103,12 +103,12 @@ void async_req_error(struct async_req *req, NTSTATUS status) * @brief Timed event callback * @param[in] ev Event context * @param[in] te The timed event - * @param[in] now current time + * @param[in] now zero time * @param[in] priv The async request to be finished */ static void async_trigger(struct event_context *ev, struct timed_event *te, - const struct timeval *now, void *priv) + struct timeval now, void *priv) { struct async_req *req = talloc_get_type_abort(priv, struct async_req); @@ -139,7 +139,7 @@ bool async_post_status(struct async_req *req, struct event_context *ev, { req->status = status; - if (event_add_timed(ev, req, timeval_zero(), "async_trigger", + if (event_add_timed(ev, req, timeval_zero(), async_trigger, req) == NULL) { return false; } @@ -197,7 +197,7 @@ NTSTATUS async_req_simple_recv(struct async_req *req) static void async_req_timedout(struct event_context *ev, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *priv) { struct async_req *req = talloc_get_type_abort( @@ -211,7 +211,7 @@ bool async_req_set_timeout(struct async_req *req, struct event_context *ev, { return (event_add_timed(ev, req, timeval_current_ofs(to.tv_sec, to.tv_usec), - "async_req_timedout", async_req_timedout, req) + async_req_timedout, req) != NULL); } @@ -268,7 +268,7 @@ static int async_queue_entry_destructor(struct async_queue_entry *e) static void async_req_immediate_trigger(struct event_context *ev, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *priv) { struct async_queue_entry *e = talloc_get_type_abort( @@ -303,7 +303,6 @@ bool async_req_enqueue(struct async_req_queue *queue, struct event_context *ev, struct timed_event *te; te = event_add_timed(ev, e, timeval_zero(), - "async_req_immediate_trigger", async_req_immediate_trigger, e); if (te == NULL) { diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 75a513312e..c94ef802c4 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -200,7 +200,7 @@ struct deferred_msg_state { static void deferred_message_dispatch(struct event_context *event_ctx, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *private_data) { struct deferred_msg_state *state = talloc_get_type_abort( @@ -383,7 +383,6 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32 reqid, evt = event_add_timed(conn->msg_ctx->event_ctx, conn->msg_ctx->event_ctx, timeval_zero(), - "deferred_message_dispatch", deferred_message_dispatch, msg_state); if (evt == NULL) { diff --git a/source3/lib/events.c b/source3/lib/events.c index 0e3fecfaa2..203cfccd14 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -27,7 +27,7 @@ struct timed_event { const char *event_name; void (*handler)(struct event_context *event_ctx, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *private_data); void *private_data; }; @@ -88,13 +88,13 @@ static void add_event_by_time(struct timed_event *te) handed to it. ****************************************************************************/ -struct timed_event *event_add_timed(struct event_context *event_ctx, +struct timed_event *_event_add_timed(struct event_context *event_ctx, TALLOC_CTX *mem_ctx, struct timeval when, const char *event_name, void (*handler)(struct event_context *event_ctx, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *private_data), void *private_data) { @@ -241,7 +241,7 @@ bool run_events(struct event_context *event_ctx, event_ctx->timed_events->handler( event_ctx, - event_ctx->timed_events, &now, + event_ctx->timed_events, now, event_ctx->timed_events->private_data); fired = True; diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index f2161dc946..f0561a5081 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -1014,7 +1014,7 @@ static int smbldap_connect_system(struct smbldap_state *ldap_state, LDAP * ldap_ static void smbldap_idle_fn(struct event_context *event_ctx, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *private_data); /********************************************************************** @@ -1079,7 +1079,7 @@ static int smbldap_open(struct smbldap_state *ldap_state) ldap_state->idle_event = event_add_timed( ldap_state->event_context, NULL, timeval_current_ofs(SMBLDAP_IDLE_TIME, 0), - "smbldap_idle_fn", smbldap_idle_fn, ldap_state); + smbldap_idle_fn, ldap_state); } DEBUG(4,("The LDAP server is successfully connected\n")); @@ -1572,7 +1572,7 @@ int smbldap_search_suffix (struct smbldap_state *ldap_state, static void smbldap_idle_fn(struct event_context *event_ctx, struct timed_event *te, - const struct timeval *now, + struct timeval now, void *private_data) { struct smbldap_state *state = (struct smbldap_state *)private_data; @@ -1584,13 +1584,13 @@ static void smbldap_idle_fn(struct event_context *event_ctx, return; } - if ((state->last_use+SMBLDAP_IDLE_TIME) > now->tv_sec) { + if ((state->last_use+SMBLDAP_IDLE_TIME) > now.tv_sec) { DEBUG(10,("ldap connection not idle...\n")); state->idle_event = event_add_timed( event_ctx, NULL, - timeval_add(now, SMBLDAP_IDLE_TIME, 0), - "smbldap_idle_fn", smbldap_idle_fn, + timeval_add(&now, SMBLDAP_IDLE_TIME, 0), + smbldap_idle_fn, private_data); return; } -- cgit From f1aa4457c3dd0c3d6654482ff0dc0b3105a9cc35 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 Dec 2008 09:19:27 +0100 Subject: s3:events: get rid of the stupid cancel_named_event() function metze --- source3/lib/events.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/events.c b/source3/lib/events.c index 203cfccd14..3f7cc02db8 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -379,22 +379,6 @@ int set_event_dispatch_time(struct event_context *event_ctx, return 0; } -/* Returns 1 if event was found and cancelled, 0 otherwise. */ - -int cancel_named_event(struct event_context *event_ctx, - const char *event_name) -{ - struct timed_event *te; - - for (te = event_ctx->timed_events; te; te = te->next) { - if (strcmp(event_name, te->event_name) == 0) { - TALLOC_FREE(te); - return 1; - } - } - return 0; -} - void dump_event_list(struct event_context *event_ctx) { struct timed_event *te; -- cgit From 83ff9d3bcd5cfe9d060a8b1f0695e5b66be47efd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 Dec 2008 10:00:43 +0100 Subject: s3:events: get rid of the stupid set_event_dispatch_time() function metze --- source3/lib/events.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/events.c b/source3/lib/events.c index 3f7cc02db8..9e9d335c7b 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -363,22 +363,6 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx) return result; } -int set_event_dispatch_time(struct event_context *event_ctx, - const char *event_name, struct timeval when) -{ - struct timed_event *te; - - for (te = event_ctx->timed_events; te; te = te->next) { - if (strcmp(event_name, te->event_name) == 0) { - DLIST_REMOVE(event_ctx->timed_events, te); - te->when = when; - add_event_by_time(te); - return 1; - } - } - return 0; -} - void dump_event_list(struct event_context *event_ctx) { struct timed_event *te; -- cgit From 303c57ef785a6189b16d879cf719998f17ab097a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 4 Jan 2009 19:29:12 +0100 Subject: s3:events: register as tevent backend metze --- source3/lib/events.c | 309 ++++++++++++++++++++++++++++----------------------- 1 file changed, 172 insertions(+), 137 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/events.c b/source3/lib/events.c index 9e9d335c7b..be2fdcb68f 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -19,42 +19,19 @@ */ #include "includes.h" +#include -struct timed_event { - struct timed_event *next, *prev; - struct event_context *event_ctx; - struct timeval when; - const char *event_name; - void (*handler)(struct event_context *event_ctx, - struct timed_event *te, - struct timeval now, - void *private_data); - void *private_data; +struct s3_event_context { + struct tevent_context *ev; + struct tevent_fd *fd_events; }; -struct fd_event { - struct fd_event *prev, *next; - struct event_context *event_ctx; - int fd; - uint16_t flags; /* see EVENT_FD_* flags */ - void (*handler)(struct event_context *event_ctx, - struct fd_event *event, - uint16 flags, - void *private_data); - void *private_data; -}; - -struct event_context { - struct timed_event *timed_events; - struct fd_event *fd_events; -}; - -static int timed_event_destructor(struct timed_event *te) +static int s3_event_timer_destructor(struct tevent_timer *te) { - DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te, - te->event_name)); + DEBUG(10, ("Destroying timer event %p \"%s\"\n", + te, te->handler_name)); if (te->event_ctx != NULL) { - DLIST_REMOVE(te->event_ctx->timed_events, te); + DLIST_REMOVE(te->event_ctx->timer_events, te); } return 0; } @@ -63,23 +40,23 @@ static int timed_event_destructor(struct timed_event *te) Add te by time. ****************************************************************************/ -static void add_event_by_time(struct timed_event *te) +static void add_event_by_time(struct tevent_timer *te) { - struct event_context *ctx = te->event_ctx; - struct timed_event *last_te, *cur_te; + struct tevent_context *ctx = te->event_ctx; + struct tevent_timer *last_te, *cur_te; /* Keep the list ordered by time. We must preserve this. */ last_te = NULL; - for (cur_te = ctx->timed_events; cur_te; cur_te = cur_te->next) { + for (cur_te = ctx->timer_events; cur_te; cur_te = cur_te->next) { /* if the new event comes before the current one break */ - if (!timeval_is_zero(&cur_te->when) && - timeval_compare(&te->when, &cur_te->when) < 0) { + if (!timeval_is_zero(&cur_te->next_event) && + timeval_compare(&te->next_event, &cur_te->next_event) < 0) { break; } last_te = cur_te; } - DLIST_ADD_AFTER(ctx->timed_events, te, last_te); + DLIST_ADD_AFTER(ctx->timer_events, te, last_te); } /**************************************************************************** @@ -88,115 +65,128 @@ static void add_event_by_time(struct timed_event *te) handed to it. ****************************************************************************/ -struct timed_event *_event_add_timed(struct event_context *event_ctx, - TALLOC_CTX *mem_ctx, - struct timeval when, - const char *event_name, - void (*handler)(struct event_context *event_ctx, - struct timed_event *te, - struct timeval now, - void *private_data), - void *private_data) +static struct tevent_timer *s3_event_add_timer(struct tevent_context *event_ctx, + TALLOC_CTX *mem_ctx, + struct timeval when, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { - struct timed_event *te; + struct tevent_timer *te; - te = TALLOC_P(mem_ctx, struct timed_event); + te = TALLOC_P(mem_ctx, struct tevent_timer); if (te == NULL) { DEBUG(0, ("talloc failed\n")); return NULL; } te->event_ctx = event_ctx; - te->when = when; - te->event_name = event_name; + te->next_event = when; te->handler = handler; te->private_data = private_data; + te->handler_name = handler_name; + te->location = location; + te->additional_data = NULL; add_event_by_time(te); - talloc_set_destructor(te, timed_event_destructor); + talloc_set_destructor(te, s3_event_timer_destructor); - DEBUG(10, ("Added timed event \"%s\": %lx\n", event_name, - (unsigned long)te)); + DEBUG(10, ("Added timed event \"%s\": %p\n", handler_name, te)); return te; } -static int fd_event_destructor(struct fd_event *fde) +static int s3_event_fd_destructor(struct tevent_fd *fde) { if (fde->event_ctx != NULL) { - DLIST_REMOVE(fde->event_ctx->fd_events, fde); + struct s3_event_context *ev3; + ev3 = talloc_get_type(fde->event_ctx->additional_data, + struct s3_event_context); + DLIST_REMOVE(ev3->fd_events, fde); + } + if (fde->close_fn) { + fde->close_fn(fde->event_ctx, fde, fde->fd, fde->private_data); + fde->fd = -1; } return 0; } -struct fd_event *event_add_fd(struct event_context *event_ctx, - TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - void (*handler)(struct event_context *event_ctx, - struct fd_event *event, - uint16 flags, - void *private_data), - void *private_data) +static struct tevent_fd *s3_event_add_fd(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + int fd, + uint16_t flags, + tevent_fd_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { - struct fd_event *fde; + struct s3_event_context *ev3 = talloc_get_type(ev->additional_data, + struct s3_event_context); + struct tevent_fd *fde; - if (!(fde = TALLOC_P(mem_ctx, struct fd_event))) { + if (!(fde = TALLOC_P(mem_ctx, struct tevent_fd))) { return NULL; } - fde->event_ctx = event_ctx; + fde->event_ctx = ev; fde->fd = fd; fde->flags = flags; fde->handler = handler; + fde->close_fn = NULL; fde->private_data = private_data; + fde->handler_name = handler_name; + fde->location = location; - DLIST_ADD(event_ctx->fd_events, fde); + DLIST_ADD(ev3->fd_events, fde); - talloc_set_destructor(fde, fd_event_destructor); + talloc_set_destructor(fde, s3_event_fd_destructor); return fde; } -void event_fd_set_writeable(struct fd_event *fde) +void event_fd_set_writeable(struct tevent_fd *fde) { - fde->flags |= EVENT_FD_WRITE; + TEVENT_FD_WRITEABLE(fde); } -void event_fd_set_not_writeable(struct fd_event *fde) +void event_fd_set_not_writeable(struct tevent_fd *fde) { - fde->flags &= ~EVENT_FD_WRITE; + TEVENT_FD_NOT_WRITEABLE(fde); } -void event_fd_set_readable(struct fd_event *fde) +void event_fd_set_readable(struct tevent_fd *fde) { - fde->flags |= EVENT_FD_READ; + TEVENT_FD_READABLE(fde); } -void event_fd_set_not_readable(struct fd_event *fde) +void event_fd_set_not_readable(struct tevent_fd *fde) { - fde->flags &= ~EVENT_FD_READ; + TEVENT_FD_NOT_READABLE(fde); } /* * Return if there's something in the queue */ -bool event_add_to_select_args(struct event_context *event_ctx, +bool event_add_to_select_args(struct tevent_context *ev, const struct timeval *now, fd_set *read_fds, fd_set *write_fds, struct timeval *timeout, int *maxfd) { - struct fd_event *fde; + struct s3_event_context *ev3 = talloc_get_type(ev->additional_data, + struct s3_event_context); + struct tevent_fd *fde; struct timeval diff; - bool ret = False; + bool ret = false; - for (fde = event_ctx->fd_events; fde; fde = fde->next) { + for (fde = ev3->fd_events; fde; fde = fde->next) { if (fde->flags & EVENT_FD_READ) { FD_SET(fde->fd, read_fds); - ret = True; + ret = true; } if (fde->flags & EVENT_FD_WRITE) { FD_SET(fde->fd, write_fds); - ret = True; + ret = true; } if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE)) @@ -205,46 +195,48 @@ bool event_add_to_select_args(struct event_context *event_ctx, } } - if (event_ctx->timed_events == NULL) { + if (ev->timer_events == NULL) { return ret; } - diff = timeval_until(now, &event_ctx->timed_events->when); + diff = timeval_until(now, &ev->timer_events->next_event); *timeout = timeval_min(timeout, &diff); - return True; + return true; } -bool run_events(struct event_context *event_ctx, +bool run_events(struct tevent_context *ev, int selrtn, fd_set *read_fds, fd_set *write_fds) { - bool fired = False; - struct fd_event *fde, *next; + struct s3_event_context *ev3 = talloc_get_type(ev->additional_data, + struct s3_event_context); + bool fired = false; + struct tevent_fd *fde, *next; /* Run all events that are pending, not just one (as we did previously. */ - while (event_ctx->timed_events) { + while (ev->timer_events) { struct timeval now; GetTimeOfDay(&now); if (timeval_compare( - &now, &event_ctx->timed_events->when) < 0) { + &now, &ev->timer_events->next_event) < 0) { /* Nothing to do yet */ DEBUG(11, ("run_events: Nothing to do\n")); break; } - DEBUG(10, ("Running event \"%s\" %lx\n", - event_ctx->timed_events->event_name, - (unsigned long)event_ctx->timed_events)); + DEBUG(10, ("Running event \"%s\" %p\n", + ev->timer_events->handler_name, + ev->timer_events)); - event_ctx->timed_events->handler( - event_ctx, - event_ctx->timed_events, now, - event_ctx->timed_events->private_data); + ev->timer_events->handler( + ev, + ev->timer_events, now, + ev->timer_events->private_data); - fired = True; + fired = true; } if (fired) { @@ -252,7 +244,7 @@ bool run_events(struct event_context *event_ctx, * We might have changed the socket status during the timed * events, return to run select again. */ - return True; + return true; } if (selrtn == 0) { @@ -262,7 +254,7 @@ bool run_events(struct event_context *event_ctx, return fired; } - for (fde = event_ctx->fd_events; fde; fde = next) { + for (fde = ev3->fd_events; fde; fde = next) { uint16 flags = 0; next = fde->next; @@ -270,8 +262,8 @@ bool run_events(struct event_context *event_ctx, if (FD_ISSET(fde->fd, write_fds)) flags |= EVENT_FD_WRITE; if (flags & fde->flags) { - fde->handler(event_ctx, fde, flags, fde->private_data); - fired = True; + fde->handler(ev, fde, flags, fde->private_data); + fired = true; } } @@ -279,17 +271,17 @@ bool run_events(struct event_context *event_ctx, } -struct timeval *get_timed_events_timeout(struct event_context *event_ctx, +struct timeval *get_timed_events_timeout(struct tevent_context *ev, struct timeval *to_ret) { struct timeval now; - if (event_ctx->timed_events == NULL) { + if (ev->timer_events == NULL) { return NULL; } now = timeval_current(); - *to_ret = timeval_until(&now, &event_ctx->timed_events->when); + *to_ret = timeval_until(&now, &ev->timer_events->next_event); DEBUG(10, ("timed_events_timeout: %d/%d\n", (int)to_ret->tv_sec, (int)to_ret->tv_usec)); @@ -297,7 +289,7 @@ struct timeval *get_timed_events_timeout(struct event_context *event_ctx, return to_ret; } -int event_loop_once(struct event_context *ev) +static int s3_event_loop_once(struct tevent_context *ev) { struct timeval now, to; fd_set r_fds, w_fds; @@ -331,45 +323,60 @@ int event_loop_once(struct event_context *ev) return 0; } -static int event_context_destructor(struct event_context *ev) +static int s3_event_loop_wait(struct tevent_context *ev) +{ + int ret = 0; + + while (ret == 0) { + ret = s3_event_loop_once(ev); + } + + return ret; +} + +static int s3_event_context_destructor(struct tevent_context *ev) { - while (ev->fd_events != NULL) { - ev->fd_events->event_ctx = NULL; - DLIST_REMOVE(ev->fd_events, ev->fd_events); + struct s3_event_context *ev3 = talloc_get_type(ev->additional_data, + struct s3_event_context); + while (ev3->fd_events != NULL) { + ev3->fd_events->event_ctx = NULL; + DLIST_REMOVE(ev3->fd_events, ev3->fd_events); } - while (ev->timed_events != NULL) { - ev->timed_events->event_ctx = NULL; - DLIST_REMOVE(ev->timed_events, ev->timed_events); + while (ev->timer_events != NULL) { + ev->timer_events->event_ctx = NULL; + DLIST_REMOVE(ev->timer_events, ev3->ev->timer_events); } return 0; } -void event_context_reinit(struct event_context *ev) +void event_context_reinit(struct tevent_context *ev) { - event_context_destructor(ev); + s3_event_context_destructor(ev); return; } -struct event_context *event_context_init(TALLOC_CTX *mem_ctx) +static int s3_event_context_init(struct tevent_context *ev) { - struct event_context *result; + struct s3_event_context *ev3; - result = TALLOC_ZERO_P(mem_ctx, struct event_context); - if (result == NULL) { - return NULL; - } + ev3 = talloc_zero(ev, struct s3_event_context); + if (!ev3) return -1; + ev3->ev = ev; - talloc_set_destructor(result, event_context_destructor); - return result; + ev->additional_data = ev3; + talloc_set_destructor(ev, s3_event_context_destructor); + return 0; } -void dump_event_list(struct event_context *event_ctx) +void dump_event_list(struct tevent_context *ev) { - struct timed_event *te; - struct fd_event *fe; + struct s3_event_context *ev3 = talloc_get_type(ev->additional_data, + struct s3_event_context); + struct tevent_timer *te; + struct tevent_fd *fe; struct timeval evt, now; - if (!event_ctx) { + if (!ev) { return; } @@ -377,22 +384,50 @@ void dump_event_list(struct event_context *event_ctx) DEBUG(10,("dump_event_list:\n")); - for (te = event_ctx->timed_events; te; te = te->next) { + for (te = ev->timer_events; te; te = te->next) { - evt = timeval_until(&now, &te->when); + evt = timeval_until(&now, &te->next_event); - DEBUGADD(10,("Timed Event \"%s\" %lx handled in %d seconds (at %s)\n", - te->event_name, - (unsigned long)te, + DEBUGADD(10,("Timed Event \"%s\" %p handled in %d seconds (at %s)\n", + te->handler_name, + te, (int)evt.tv_sec, - http_timestring(talloc_tos(), te->when.tv_sec))); + http_timestring(talloc_tos(), te->next_event.tv_sec))); } - for (fe = event_ctx->fd_events; fe; fe = fe->next) { + for (fe = ev3->fd_events; fe; fe = fe->next) { - DEBUGADD(10,("FD Event %d %lx, flags: 0x%04x\n", + DEBUGADD(10,("FD Event %d %p, flags: 0x%04x\n", fe->fd, - (unsigned long)fe, + fe, fe->flags)); } } + +static const struct tevent_ops s3_event_ops = { + .context_init = s3_event_context_init, + .add_fd = s3_event_add_fd, + .set_fd_close_fn= tevent_common_fd_set_close_fn, + .get_fd_flags = tevent_common_fd_get_flags, + .set_fd_flags = tevent_common_fd_set_flags, + .add_timer = s3_event_add_timer, + .loop_once = s3_event_loop_once, + .loop_wait = s3_event_loop_wait, +}; + +static bool s3_tevent_init(void) +{ + static bool initialized; + if (initialized) { + return true; + } + initialized = tevent_register_backend("s3", &s3_event_ops); + tevent_set_default_backend("s3"); + return initialized; +} + +struct tevent_context *s3_tevent_context_init(TALLOC_CTX *mem_ctx) +{ + s3_tevent_init(); + return tevent_context_init_byname(mem_ctx, "s3"); +} -- cgit