From 3f8f99eaecf7a07126969594c41c00392b85cefd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 12:06:39 +0100 Subject: s4:tevent: move event_context_find() to tevent_s4.c metze --- lib/tevent/tevent.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index e45a690c33..130bfaa665 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -290,21 +290,3 @@ int event_loop_wait(struct tevent_context *ev) { return ev->ops->loop_wait(ev); } - -/* - find an event context that is a parent of the given memory context, - or create a new event context as a child of the given context if - none is found - - This should be used in preference to event_context_init() in places - where you would prefer to use the existing event context if possible - (which is most situations) -*/ -struct tevent_context *event_context_find(TALLOC_CTX *mem_ctx) -{ - struct tevent_context *ev = talloc_find_parent_bytype(mem_ctx, struct tevent_context); - if (ev == NULL) { - ev = event_context_init(mem_ctx); - } - return ev; -} -- cgit From 0ffed7d992a50bff5f3bc89447418ed485dbccb0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 12:53:05 +0100 Subject: tevent: use libreplace headers instead of system headers metze --- lib/tevent/tevent_aio.c | 5 +++-- lib/tevent/tevent_epoll.c | 2 +- lib/tevent/tevent_signal.c | 3 +-- lib/tevent/tevent_timed.c | 5 +---- 4 files changed, 6 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index 746e96060b..46a5d3d6fc 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -30,12 +30,13 @@ this is _very_ experimental code */ -#include "system/filesys.h" #include "replace.h" +#include "system/filesys.h" +#include "system/network.h" +#include "system/select.h" #include "tevent.h" #include "tevent_internal.h" #include "tevent_util.h" -#include #include #define MAX_AIO_QUEUE_DEPTH 100 diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index 1ce666462c..ab07515f10 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -23,10 +23,10 @@ #include "replace.h" #include "system/filesys.h" #include "system/network.h" +#include "system/select.h" #include "tevent.h" #include "tevent_internal.h" #include "tevent_util.h" -#include struct epoll_event_context { /* a pointer back to the generic event_context */ diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c index bb50480dd7..fdd7070625 100644 --- a/lib/tevent/tevent_signal.c +++ b/lib/tevent/tevent_signal.c @@ -19,10 +19,9 @@ along with this program. If not, see . */ -#include #include "replace.h" #include "system/filesys.h" -#include "system/select.h" +#include "system/wait.h" #include "tevent.h" #include "tevent_internal.h" #include "tevent_util.h" diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c index ce3fc8eb00..4ad457221e 100644 --- a/lib/tevent/tevent_timed.c +++ b/lib/tevent/tevent_timed.c @@ -20,11 +20,8 @@ along with this program. If not, see . */ -#include -#include #include "replace.h" -#include "system/filesys.h" -#include "system/select.h" +#include "system/time.h" #include "tevent.h" #include "tevent_internal.h" #include "tevent_util.h" -- cgit From 8bdc947993dd29d0480675464d548134c6f71ea7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 11:17:00 +0100 Subject: tevent: rename event_set_default_backend() => tevent_set_default_backend() metze --- lib/tevent/tevent.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 130bfaa665..94d71d490d 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -65,7 +65,7 @@ struct event_ops_list { /* list of registered event backends */ static struct event_ops_list *event_backends = NULL; -static char *event_default_backend = NULL; +static char *tevent_default_backend = NULL; /* register an events backend @@ -94,10 +94,11 @@ bool event_register_backend(const char *name, const struct event_ops *ops) /* set the default event backend */ -void event_set_default_backend(const char *backend) +void tevent_set_default_backend(const char *backend) { - if (event_default_backend) free(event_default_backend); - event_default_backend = strdup(backend); + talloc_free(tevent_default_backend); + tevent_default_backend = talloc_strdup(talloc_autofree_context(), + backend); } /* @@ -177,7 +178,7 @@ struct tevent_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char event_backend_init(); if (name == NULL) { - name = event_default_backend; + name = tevent_default_backend; } if (name == NULL) { name = "standard"; -- cgit From d33b6aeff3ff0220c16211936043934cfa3ec71b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 11:32:29 +0100 Subject: tevent: rename event_loop_* => tevent_loop_* metze --- lib/tevent/tevent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 94d71d490d..563a6522a5 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -47,8 +47,8 @@ After that you can add/remove events that you are interested in using event_add_*() and talloc_free() - Finally, you call event_loop_wait_once() to block waiting for one of the - events to occor or event_loop_wait() which will loop + Finally, you call tevent_loop_wait_once() to block waiting for one of the + events to occor or tevent_loop_wait() which will loop forever. */ @@ -279,7 +279,7 @@ struct signal_event *event_add_signal(struct tevent_context *ev, TALLOC_CTX *mem /* do a single event loop using the events defined in ev */ -int event_loop_once(struct tevent_context *ev) +int tevent_loop_once(struct tevent_context *ev) { return ev->ops->loop_once(ev); } @@ -287,7 +287,7 @@ int event_loop_once(struct tevent_context *ev) /* return on failure or (with 0) if all fd events are removed */ -int event_loop_wait(struct tevent_context *ev) +int tevent_loop_wait(struct tevent_context *ev) { return ev->ops->loop_wait(ev); } -- cgit From 7db63990698563fd5d32698cb7988358cf5ab247 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 11:36:52 +0100 Subject: tevent: rename event_[s|g]et_fd_flags => tevent_fd_[s|g]et_flags metze --- lib/tevent/tevent.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 563a6522a5..4c87ef5f73 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -233,7 +233,7 @@ struct aio_event *event_add_aio(struct tevent_context *ev, /* return the fd event flags */ -uint16_t event_get_fd_flags(struct tevent_fd *fde) +uint16_t tevent_fd_get_flags(struct tevent_fd *fde) { if (!fde) return 0; return fde->event_ctx->ops->get_fd_flags(fde); @@ -242,7 +242,7 @@ uint16_t event_get_fd_flags(struct tevent_fd *fde) /* set the fd event flags */ -void event_set_fd_flags(struct tevent_fd *fde, uint16_t flags) +void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags) { if (!fde) return; fde->event_ctx->ops->set_fd_flags(fde, flags); -- cgit From 0a73e8b334d2b9f5e8032c685d78b6425a9fa5e7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 11:30:00 +0100 Subject: tevent: rename event_context_init* => tevent_context_init*() metze --- lib/tevent/tevent.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 4c87ef5f73..0b4a3cd5b7 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -41,7 +41,7 @@ handler to get another event. To setup a set of events you first need to create a event_context - structure using the function event_context_init(); This returns a + structure using the function tevent_context_init(); This returns a 'struct tevent_context' that you use in all subsequent calls. After that you can add/remove events that you are interested in @@ -57,36 +57,36 @@ #include "tevent_internal.h" #include "tevent_util.h" -struct event_ops_list { - struct event_ops_list *next, *prev; +struct tevent_ops_list { + struct tevent_ops_list *next, *prev; const char *name; - const struct event_ops *ops; + const struct tevent_ops *ops; }; /* list of registered event backends */ -static struct event_ops_list *event_backends = NULL; +static struct tevent_ops_list *tevent_backends = NULL; static char *tevent_default_backend = NULL; /* register an events backend */ -bool event_register_backend(const char *name, const struct event_ops *ops) +bool event_register_backend(const char *name, const struct tevent_ops *ops) { - struct event_ops_list *e; + struct tevent_ops_list *e; - for (e = event_backends; e != NULL; e = e->next) { + for (e = tevent_backends; e != NULL; e = e->next) { if (0 == strcmp(e->name, name)) { /* already registered, skip it */ return true; } } - e = talloc(talloc_autofree_context(), struct event_ops_list); + e = talloc(talloc_autofree_context(), struct tevent_ops_list); if (e == NULL) return false; e->name = name; e->ops = ops; - DLIST_ADD(event_backends, e); + DLIST_ADD(tevent_backends, e); return true; } @@ -104,7 +104,7 @@ void tevent_set_default_backend(const char *backend) /* initialise backends if not already done */ -static void event_backend_init(void) +static void tevent_backend_init(void) { events_select_init(); events_standard_init(); @@ -119,14 +119,14 @@ static void event_backend_init(void) /* list available backends */ -const char **event_backend_list(TALLOC_CTX *mem_ctx) +const char **tevent_backend_list(TALLOC_CTX *mem_ctx) { const char **list = NULL; - struct event_ops_list *e; + struct tevent_ops_list *e; - event_backend_init(); + tevent_backend_init(); - for (e=event_backends;e;e=e->next) { + for (e=tevent_backends;e;e=e->next) { list = ev_str_list_add(list, e->name); } @@ -144,10 +144,10 @@ const char **event_backend_list(TALLOC_CTX *mem_ctx) This function is for allowing third-party-applications to hook in gluecode to their own event loop code, so that they can make async usage of our client libs - NOTE: use event_context_init() inside of samba! + NOTE: use tevent_context_init() inside of samba! */ -static struct tevent_context *event_context_init_ops(TALLOC_CTX *mem_ctx, - const struct event_ops *ops) +static struct tevent_context *tevent_context_init_ops(TALLOC_CTX *mem_ctx, + const struct tevent_ops *ops) { struct tevent_context *ev; int ret; @@ -171,11 +171,12 @@ static struct tevent_context *event_context_init_ops(TALLOC_CTX *mem_ctx, call, and all subsequent calls pass this event_context as the first element. Event handlers also receive this as their first argument. */ -struct tevent_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char *name) +struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx, + const char *name) { - struct event_ops_list *e; + struct tevent_ops_list *e; - event_backend_init(); + tevent_backend_init(); if (name == NULL) { name = tevent_default_backend; @@ -184,9 +185,9 @@ struct tevent_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char name = "standard"; } - for (e=event_backends;e;e=e->next) { + for (e=tevent_backends;e;e=e->next) { if (strcmp(name, e->name) == 0) { - return event_context_init_ops(mem_ctx, e->ops); + return tevent_context_init_ops(mem_ctx, e->ops); } } return NULL; @@ -198,9 +199,9 @@ struct tevent_context *event_context_init_byname(TALLOC_CTX *mem_ctx, const char call, and all subsequent calls pass this event_context as the first element. Event handlers also receive this as their first argument. */ -struct tevent_context *event_context_init(TALLOC_CTX *mem_ctx) +struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx) { - return event_context_init_byname(mem_ctx, NULL); + return tevent_context_init_byname(mem_ctx, NULL); } /* -- cgit From d9529a331afaf1c82b24becc1d0d245e19d518aa Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 13:35:32 +0100 Subject: tevent: rename event_register_backend() => tevent_register_backend() And fix the callers and there init functions. metze --- lib/tevent/tevent.c | 10 +++++----- lib/tevent/tevent_aio.c | 6 +++--- lib/tevent/tevent_epoll.c | 6 +++--- lib/tevent/tevent_internal.h | 10 +++++----- lib/tevent/tevent_select.c | 7 +++---- lib/tevent/tevent_standard.c | 6 +++--- 6 files changed, 22 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 0b4a3cd5b7..676a3dc398 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -70,7 +70,7 @@ static char *tevent_default_backend = NULL; /* register an events backend */ -bool event_register_backend(const char *name, const struct tevent_ops *ops) +bool tevent_register_backend(const char *name, const struct tevent_ops *ops) { struct tevent_ops_list *e; @@ -106,13 +106,13 @@ void tevent_set_default_backend(const char *backend) */ static void tevent_backend_init(void) { - events_select_init(); - events_standard_init(); + tevent_select_init(); + tevent_standard_init(); #if HAVE_EVENTS_EPOLL - events_epoll_init(); + tevent_epoll_init(); #endif #if HAVE_LINUX_AIO - events_aio_init(); + tevent_aio_init(); #endif } diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index 46a5d3d6fc..8d25791bea 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -549,7 +549,7 @@ static struct aio_event *aio_event_add_aio(struct tevent_context *ev, return ae; } -static const struct event_ops aio_event_ops = { +static const struct tevent_ops aio_event_ops = { .context_init = aio_event_context_init, .add_fd = aio_event_add_fd, .add_aio = aio_event_add_aio, @@ -561,8 +561,8 @@ static const struct event_ops aio_event_ops = { .loop_wait = aio_event_loop_wait, }; -bool events_aio_init(void) +bool tevent_aio_init(void) { - return event_register_backend("aio", &aio_event_ops); + return tevent_register_backend("aio", &aio_event_ops); } diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index ab07515f10..1f853e60f1 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -465,7 +465,7 @@ static int epoll_event_loop_wait(struct tevent_context *ev) return 0; } -static const struct event_ops epoll_event_ops = { +static const struct tevent_ops epoll_event_ops = { .context_init = epoll_event_context_init, .add_fd = epoll_event_add_fd, .get_fd_flags = epoll_event_get_fd_flags, @@ -476,7 +476,7 @@ static const struct event_ops epoll_event_ops = { .loop_wait = epoll_event_loop_wait, }; -bool events_epoll_init(void) +bool tevent_epoll_init(void) { - return event_register_backend("epoll", &epoll_event_ops); + return tevent_register_backend("epoll", &epoll_event_ops); } diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index 2d6909da36..a439c62743 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -132,7 +132,7 @@ struct tevent_context { }; -bool event_register_backend(const char *name, const struct tevent_ops *ops); +bool tevent_register_backend(const char *name, const struct tevent_ops *ops); bool ev_timeval_is_zero(const struct timeval *tv); struct tevent_timer *common_event_add_timed(struct tevent_context *, @@ -151,11 +151,11 @@ struct tevent_signal *common_event_add_signal(struct tevent_context *ev, int common_event_check_signal(struct tevent_context *ev); -bool events_standard_init(void); -bool events_select_init(void); +bool tevent_standard_init(void); +bool tevent_select_init(void); #if HAVE_EVENTS_EPOLL -bool events_epoll_init(void); +bool tevent_epoll_init(void); #endif #if HAVE_LINUX_AIO -bool events_aio_init(void); +bool tevent_aio_init(void); #endif diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c index 3e72ce4943..103e5ac1fa 100644 --- a/lib/tevent/tevent_select.c +++ b/lib/tevent/tevent_select.c @@ -284,7 +284,7 @@ static int select_event_loop_wait(struct tevent_context *ev) return select_ev->exit_code; } -static const struct event_ops select_event_ops = { +static const struct tevent_ops select_event_ops = { .context_init = select_event_context_init, .add_fd = select_event_add_fd, .get_fd_flags = select_event_get_fd_flags, @@ -295,8 +295,7 @@ static const struct event_ops select_event_ops = { .loop_wait = select_event_loop_wait, }; -bool events_select_init(void) +bool tevent_select_init(void) { - return event_register_backend("select", &select_event_ops); + return tevent_register_backend("select", &select_event_ops); } - diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c index 1c99408b8d..1c60fc0167 100644 --- a/lib/tevent/tevent_standard.c +++ b/lib/tevent/tevent_standard.c @@ -588,7 +588,7 @@ static int std_event_loop_wait(struct tevent_context *ev) return std_ev->exit_code; } -static const struct event_ops std_event_ops = { +static const struct tevent_ops std_event_ops = { .context_init = std_event_context_init, .add_fd = std_event_add_fd, .get_fd_flags = std_event_get_fd_flags, @@ -600,8 +600,8 @@ static const struct event_ops std_event_ops = { }; -bool events_standard_init(void) +bool tevent_standard_init(void) { - return event_register_backend("standard", &std_event_ops); + return tevent_register_backend("standard", &std_event_ops); } -- cgit From b12e78e64517d423aefecc84f23499b13aedd734 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 13:39:26 +0100 Subject: tevent: use HAVE_EPOLL instead of HAVE_EVENTS_EPOLL metze --- lib/tevent/libtevent.m4 | 2 -- lib/tevent/tevent.c | 4 ++-- lib/tevent/tevent_internal.h | 4 ++-- lib/tevent/tevent_standard.c | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/tevent/libtevent.m4 b/lib/tevent/libtevent.m4 index 30105d9bef..24cdd8c27f 100644 --- a/lib/tevent/libtevent.m4 +++ b/lib/tevent/libtevent.m4 @@ -26,8 +26,6 @@ if test x"$ac_cv_header_sys_epoll_h" = x"yes" -a x"$ac_cv_func_epoll_create" = x TEVENT_OBJ="$TEVENT_OBJ tevent_epoll.o" SMB_ENABLE(TEVENT_EPOLL,YES) AC_DEFINE(HAVE_EPOLL, 1, [Whether epoll available]) - #TODO: remove HAVE_EVENTS_EPOLL and use HAVE_EPOLL - AC_DEFINE(HAVE_EVENTS_EPOLL, 1, [Whether epoll available]) # check for native Linux AIO interface AC_CHECK_HEADERS(libaio.h) diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index 676a3dc398..f79e4cefb5 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -108,10 +108,10 @@ static void tevent_backend_init(void) { tevent_select_init(); tevent_standard_init(); -#if HAVE_EVENTS_EPOLL +#ifdef HAVE_EPOLL tevent_epoll_init(); #endif -#if HAVE_LINUX_AIO +#ifdef HAVE_LINUX_AIO tevent_aio_init(); #endif } diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index a439c62743..b654e4b500 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -153,9 +153,9 @@ int common_event_check_signal(struct tevent_context *ev); bool tevent_standard_init(void); bool tevent_select_init(void); -#if HAVE_EVENTS_EPOLL +#ifdef HAVE_EPOLL bool tevent_epoll_init(void); #endif -#if HAVE_LINUX_AIO +#ifdef HAVE_LINUX_AIO bool tevent_aio_init(void); #endif diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c index 1c60fc0167..7abb695d89 100644 --- a/lib/tevent/tevent_standard.c +++ b/lib/tevent/tevent_standard.c @@ -30,7 +30,7 @@ #include "replace.h" #include "system/filesys.h" #include "system/network.h" -#include "system/select.h" /* needed for HAVE_EVENTS_EPOLL */ +#include "system/select.h" #include "tevent.h" #include "tevent_util.h" #include "tevent_internal.h" @@ -64,7 +64,7 @@ struct std_event_context { }; /* use epoll if it is available */ -#if HAVE_EVENTS_EPOLL +#if HAVE_EPOLL /* called when a epoll call fails, and we should fallback to using select -- cgit From 49acf9799aab288b4e585295eb7c44a719973945 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 11:44:17 +0100 Subject: tevent: make tevent_add_*() macros arround _tevent_add_*() This passes some additional debug information into the events system to make it easier to find bugs. metze --- lib/tevent/tevent.c | 53 ++++++++++++++++++++++++++---------------- lib/tevent/tevent.h | 66 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 77 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index f79e4cefb5..fd44838a98 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -45,7 +45,7 @@ 'struct tevent_context' that you use in all subsequent calls. After that you can add/remove events that you are interested in - using event_add_*() and talloc_free() + using tevent_add_*() and talloc_free() Finally, you call tevent_loop_wait_once() to block waiting for one of the events to occor or tevent_loop_wait() which will loop @@ -208,12 +208,17 @@ struct tevent_context *tevent_context_init(TALLOC_CTX *mem_ctx) add a fd based event return NULL on failure (memory allocation error) - if flags contains EVENT_FD_AUTOCLOSE then the fd will be closed when + if flags contains TEVENT_FD_AUTOCLOSE then the fd will be closed when the returned fd_event context is freed */ -struct tevent_fd *event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, event_fd_handler_t handler, - void *private_data) +struct tevent_fd *_tevent_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) { return ev->ops->add_fd(ev, mem_ctx, fd, flags, handler, private_data); } @@ -221,11 +226,13 @@ struct tevent_fd *event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, /* add a disk aio event */ -struct aio_event *event_add_aio(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - struct iocb *iocb, - event_aio_handler_t handler, - void *private_data) +struct tevent_aio *_tevent_add_aio(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct iocb *iocb, + tevent_aio_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { if (ev->ops->add_aio == NULL) return NULL; return ev->ops->add_aio(ev, mem_ctx, iocb, handler, private_data); @@ -250,13 +257,16 @@ void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags) } /* - add a timed event + add a timer event return NULL on failure */ -struct tevent_timer *event_add_timed(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - struct timeval next_event, - event_timed_handler_t handler, - void *private_data) +struct tevent_timer *_tevent_add_timer(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct timeval next_event, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { return ev->ops->add_timer(ev, mem_ctx, next_event, handler, private_data); } @@ -268,11 +278,14 @@ struct tevent_timer *event_add_timed(struct tevent_context *ev, TALLOC_CTX *mem_ return NULL on failure */ -struct signal_event *event_add_signal(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int signum, - int sa_flags, - event_signal_handler_t handler, - void *private_data) +struct tevent_signal *_tevent_add_signal(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + int signum, + int sa_flags, + tevent_signal_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { return ev->ops->add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data); } diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index f626de9d12..fd6b613b9d 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -51,30 +51,52 @@ struct tevent_context *tevent_context_init_byname(TALLOC_CTX *mem_ctx, const cha const char **tevent_backend_list(TALLOC_CTX *mem_ctx); void tevent_set_default_backend(const char *backend); -struct tevent_fd *tevent_add_fd(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - tevent_fd_handler_t handler, - void *private_data); - -struct tevent_timer *tevent_add_timer(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - struct timeval next_event, - tevent_timer_handler_t handler, - void *private_data); - -struct tevent_signal *tevent_add_signal(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - int signum, int sa_flags, - tevent_signal_handler_t handler, - void *private_data); +struct tevent_fd *_tevent_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); +#define tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data) \ + _tevent_add_fd(ev, mem_ctx, fd, flags, handler, private_data, \ + #handler, __location__) + +struct tevent_timer *_tevent_add_timer(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct timeval next_event, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location); +#define tevent_add_timer(ev, mem_ctx, next_event, handler, private_data) \ + _tevent_add_timer(ev, mem_ctx, next_event, handler, private_data, \ + #handler, __location__); + +struct tevent_signal *_tevent_add_signal(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + int signum, + int sa_flags, + tevent_signal_handler_t handler, + void *private_data, + const char *handler_name, + const char *location); +#define tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data) \ + _tevent_add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, \ + #handler, __location__) struct iocb; -struct tevent_aio *tevent_add_aio(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - struct iocb *iocb, - tevent_aio_handler_t handler, - void *private_data); +struct tevent_aio *_tevent_add_aio(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct iocb *iocb, + tevent_aio_handler_t handler, + void *private_data, + const char *handler_name, + const char *location); +#define tevent_add_aio(ev, mem_ctx, iocb, handler, private_data) \ + _tevent_add_aio(ev, mem_ctx, iocb, handler, private_data, \ + #handler, __location__); int tevent_loop_once(struct tevent_context *ev); int tevent_loop_wait(struct tevent_context *ev); -- cgit From 227f799dee4e59479612bcb3dc96231589515051 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 13:26:32 +0100 Subject: tevent: pass down handler_name and location to the backend layer metze --- lib/tevent/tevent.c | 12 +++++--- lib/tevent/tevent_aio.c | 46 +++++++++++++++++-------------- lib/tevent/tevent_epoll.c | 22 +++++++++------ lib/tevent/tevent_internal.h | 65 ++++++++++++++++++++++++++++++-------------- lib/tevent/tevent_select.c | 22 +++++++++------ lib/tevent/tevent_signal.c | 41 ++++++++++++++++------------ lib/tevent/tevent_standard.c | 26 ++++++++++-------- lib/tevent/tevent_timed.c | 22 +++++++++------ 8 files changed, 154 insertions(+), 102 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c index fd44838a98..9319177646 100644 --- a/lib/tevent/tevent.c +++ b/lib/tevent/tevent.c @@ -220,7 +220,8 @@ struct tevent_fd *_tevent_add_fd(struct tevent_context *ev, const char *handler_name, const char *location) { - return ev->ops->add_fd(ev, mem_ctx, fd, flags, handler, private_data); + return ev->ops->add_fd(ev, mem_ctx, fd, flags, handler, private_data, + handler_name, location); } /* @@ -235,7 +236,8 @@ struct tevent_aio *_tevent_add_aio(struct tevent_context *ev, const char *location) { if (ev->ops->add_aio == NULL) return NULL; - return ev->ops->add_aio(ev, mem_ctx, iocb, handler, private_data); + return ev->ops->add_aio(ev, mem_ctx, iocb, handler, private_data, + handler_name, location); } /* @@ -268,7 +270,8 @@ struct tevent_timer *_tevent_add_timer(struct tevent_context *ev, const char *handler_name, const char *location) { - return ev->ops->add_timer(ev, mem_ctx, next_event, handler, private_data); + return ev->ops->add_timer(ev, mem_ctx, next_event, handler, private_data, + handler_name, location); } /* @@ -287,7 +290,8 @@ struct tevent_signal *_tevent_add_signal(struct tevent_context *ev, const char *handler_name, const char *location) { - return ev->ops->add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data); + return ev->ops->add_signal(ev, mem_ctx, signum, sa_flags, handler, private_data, + handler_name, location); } /* diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index 8d25791bea..f3045fbf97 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -67,11 +67,11 @@ struct aio_event_context { pid_t pid; }; -struct aio_event { +struct tevent_aio { struct tevent_context *event_ctx; struct iocb iocb; void *private_data; - event_aio_handler_t handler; + tevent_aio_handler_t handler; }; /* @@ -261,7 +261,7 @@ static int aio_event_loop(struct aio_event_context *aio_ev, struct timeval *tval if (aio_ev->epoll_fd == -1) return -1; if (aio_ev->ev->num_signal_handlers && - common_event_check_signal(aio_ev->ev)) { + tevent_common_check_signal(aio_ev->ev)) { return 0; } @@ -279,14 +279,14 @@ static int aio_event_loop(struct aio_event_context *aio_ev, struct timeval *tval if (ret == -EINTR) { if (aio_ev->ev->num_signal_handlers) { - common_event_check_signal(aio_ev->ev); + tevent_common_check_signal(aio_ev->ev); } return 0; } if (ret == 0 && tvalp) { /* we don't care about a possible delay here */ - common_event_loop_timer_delay(aio_ev->ev); + tevent_common_loop_timer_delay(aio_ev->ev); return 0; } @@ -297,8 +297,8 @@ static int aio_event_loop(struct aio_event_context *aio_ev, struct timeval *tval switch (finished->aio_lio_opcode) { case IO_CMD_PWRITE: case IO_CMD_PREAD: { - struct aio_event *ae = talloc_get_type(finished->data, - struct aio_event); + struct tevent_aio *ae = talloc_get_type(finished->data, + struct tevent_aio); if (ae) { talloc_set_destructor(ae, NULL); ae->handler(ae->event_ctx, ae, @@ -412,9 +412,11 @@ static int aio_event_fd_destructor(struct tevent_fd *fde) return NULL on failure (memory allocation error) */ static struct tevent_fd *aio_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - event_fd_handler_t handler, - void *private_data) + int fd, uint16_t flags, + tevent_fd_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct aio_event_context *aio_ev = talloc_get_type(ev->additional_data, struct aio_event_context); @@ -430,6 +432,8 @@ static struct tevent_fd *aio_event_add_fd(struct tevent_context *ev, TALLOC_CTX fde->flags = flags; fde->handler = handler; fde->private_data = private_data; + fde->handler_name = handler_name; + fde->location = location; fde->additional_flags = 0; fde->additional_data = NULL; @@ -480,7 +484,7 @@ static int aio_event_loop_once(struct tevent_context *ev) struct aio_event_context); struct timeval tval; - tval = common_event_loop_timer_delay(ev); + tval = tevent_common_loop_timer_delay(ev); if (ev_timeval_is_zero(&tval)) { return 0; } @@ -509,7 +513,7 @@ static int aio_event_loop_wait(struct tevent_context *ev) /* called when a disk IO event needs to be cancelled */ -static int aio_destructor(struct aio_event *ae) +static int aio_destructor(struct tevent_aio *ae) { struct tevent_context *ev = ae->event_ctx; struct aio_event_context *aio_ev = talloc_get_type(ev->additional_data, @@ -521,16 +525,18 @@ static int aio_destructor(struct aio_event *ae) } /* submit an aio disk IO event */ -static struct aio_event *aio_event_add_aio(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - struct iocb *iocb, - event_aio_handler_t handler, - void *private_data) +static struct tevent_aio *aio_event_add_aio(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct iocb *iocb, + tevent_aio_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct aio_event_context *aio_ev = talloc_get_type(ev->additional_data, struct aio_event_context); struct iocb *iocbp; - struct aio_event *ae = talloc(mem_ctx?mem_ctx:ev, struct aio_event); + struct tevent_aio *ae = talloc(mem_ctx?mem_ctx:ev, struct tevent_aio); if (ae == NULL) return NULL; ae->event_ctx = ev; @@ -555,8 +561,8 @@ static const struct tevent_ops aio_event_ops = { .add_aio = aio_event_add_aio, .get_fd_flags = aio_event_get_fd_flags, .set_fd_flags = aio_event_set_fd_flags, - .add_timer = common_event_add_timed, - .add_signal = common_event_add_signal, + .add_timer = tevent_common_add_timer, + .add_signal = tevent_common_add_signal, .loop_once = aio_event_loop_once, .loop_wait = aio_event_loop_wait, }; diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index 1f853e60f1..d2703eda6c 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -258,14 +258,14 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval } if (epoll_ev->ev->num_signal_handlers && - common_event_check_signal(epoll_ev->ev)) { + tevent_common_check_signal(epoll_ev->ev)) { return 0; } ret = epoll_wait(epoll_ev->epoll_fd, events, MAXEVENTS, timeout); if (ret == -1 && errno == EINTR && epoll_ev->ev->num_signal_handlers) { - if (common_event_check_signal(epoll_ev->ev)) { + if (tevent_common_check_signal(epoll_ev->ev)) { return 0; } } @@ -277,7 +277,7 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval if (ret == 0 && tvalp) { /* we don't care about a possible delay here */ - common_event_loop_timer_delay(epoll_ev->ev); + tevent_common_loop_timer_delay(epoll_ev->ev); return 0; } @@ -371,9 +371,11 @@ static int epoll_event_fd_destructor(struct tevent_fd *fde) return NULL on failure (memory allocation error) */ static struct tevent_fd *epoll_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - event_fd_handler_t handler, - void *private_data) + int fd, uint16_t flags, + tevent_fd_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data, struct epoll_event_context); @@ -389,6 +391,8 @@ static struct tevent_fd *epoll_event_add_fd(struct tevent_context *ev, TALLOC_CT fde->flags = flags; fde->handler = handler; fde->private_data = private_data; + fde->handler_name = handler_name; + fde->location = location; fde->additional_flags = 0; fde->additional_data = NULL; @@ -439,7 +443,7 @@ static int epoll_event_loop_once(struct tevent_context *ev) struct epoll_event_context); struct timeval tval; - tval = common_event_loop_timer_delay(ev); + tval = tevent_common_loop_timer_delay(ev); if (ev_timeval_is_zero(&tval)) { return 0; } @@ -470,8 +474,8 @@ static const struct tevent_ops epoll_event_ops = { .add_fd = epoll_event_add_fd, .get_fd_flags = epoll_event_get_fd_flags, .set_fd_flags = epoll_event_set_fd_flags, - .add_timer = common_event_add_timed, - .add_signal = common_event_add_signal, + .add_timer = tevent_common_add_timer, + .add_signal = tevent_common_add_signal, .loop_once = epoll_event_loop_once, .loop_wait = epoll_event_loop_wait, }; diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index b654e4b500..408136dc71 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -30,7 +30,9 @@ struct tevent_ops { TALLOC_CTX *mem_ctx, int fd, uint16_t flags, tevent_fd_handler_t handler, - void *private_data); + void *private_data, + const char *handler_name, + const char *location); uint16_t (*get_fd_flags)(struct tevent_fd *fde); void (*set_fd_flags)(struct tevent_fd *fde, uint16_t flags); @@ -39,19 +41,25 @@ struct tevent_ops { TALLOC_CTX *mem_ctx, struct timeval next_event, tevent_timer_handler_t handler, - void *private_data); + void *private_data, + const char *handler_name, + const char *location); /* disk aio event functions */ struct tevent_aio *(*add_aio)(struct tevent_context *ev, TALLOC_CTX *mem_ctx, struct iocb *iocb, tevent_aio_handler_t handler, - void *private_data); + void *private_data, + const char *handler_name, + const char *location); /* signal functions */ struct tevent_signal *(*add_signal)(struct tevent_context *ev, TALLOC_CTX *mem_ctx, int signum, int sa_flags, tevent_signal_handler_t handler, - void *private_data); + void *private_data, + const char *handler_name, + const char *location); /* loop functions */ int (*loop_once)(struct tevent_context *ev); @@ -66,6 +74,9 @@ struct tevent_fd { tevent_fd_handler_t handler; /* this is private for the specific handler */ void *private_data; + /* this is for debugging only! */ + const char *handler_name; + const char *location; /* this is private for the events_ops implementation */ uint16_t additional_flags; void *additional_data; @@ -78,6 +89,9 @@ struct tevent_timer { tevent_timer_handler_t handler; /* this is private for the specific handler */ void *private_data; + /* this is for debugging only! */ + const char *handler_name; + const char *location; /* this is private for the events_ops implementation */ void *additional_data; }; @@ -85,10 +99,16 @@ struct tevent_timer { struct tevent_signal { struct tevent_signal *prev, *next; struct tevent_context *event_ctx; - tevent_signal_handler_t handler; - void *private_data; int signum; int sa_flags; + tevent_signal_handler_t handler; + /* this is private for the specific handler */ + void *private_data; + /* this is for debugging only! */ + const char *handler_name; + const char *location; + /* this is private for the events_ops implementation */ + void *additional_data; }; /* DEBUG */ @@ -135,21 +155,24 @@ struct tevent_context { bool tevent_register_backend(const char *name, const struct tevent_ops *ops); bool ev_timeval_is_zero(const struct timeval *tv); -struct tevent_timer *common_event_add_timed(struct tevent_context *, - TALLOC_CTX *, - struct timeval, - tevent_timer_handler_t, - void *); -struct timeval common_event_loop_timer_delay(struct tevent_context *); - -struct tevent_signal *common_event_add_signal(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - int signum, - int sa_flags, - tevent_signal_handler_t handler, - void *private_data); -int common_event_check_signal(struct tevent_context *ev); - +struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + struct timeval next_event, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location); +struct timeval tevent_common_loop_timer_delay(struct tevent_context *); + +struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + int signum, + int sa_flags, + tevent_signal_handler_t handler, + void *private_data, + const char *handler_name, + const char *location); +int tevent_common_check_signal(struct tevent_context *ev); bool tevent_standard_init(void); bool tevent_select_init(void); diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c index 103e5ac1fa..b082400a8e 100644 --- a/lib/tevent/tevent_select.c +++ b/lib/tevent/tevent_select.c @@ -116,9 +116,11 @@ static int select_event_fd_destructor(struct tevent_fd *fde) return NULL on failure (memory allocation error) */ static struct tevent_fd *select_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - event_fd_handler_t handler, - void *private_data) + int fd, uint16_t flags, + tevent_fd_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct select_event_context *select_ev = talloc_get_type(ev->additional_data, struct select_event_context); @@ -132,6 +134,8 @@ static struct tevent_fd *select_event_add_fd(struct tevent_context *ev, TALLOC_C fde->flags = flags; fde->handler = handler; fde->private_data = private_data; + fde->handler_name = handler_name; + fde->location = location; fde->additional_flags = 0; fde->additional_data = NULL; @@ -198,7 +202,7 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru } if (select_ev->ev->num_signal_handlers && - common_event_check_signal(select_ev->ev)) { + tevent_common_check_signal(select_ev->ev)) { return 0; } @@ -206,7 +210,7 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru if (selrtn == -1 && errno == EINTR && select_ev->ev->num_signal_handlers) { - common_event_check_signal(select_ev->ev); + tevent_common_check_signal(select_ev->ev); return 0; } @@ -224,7 +228,7 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru if (selrtn == 0 && tvalp) { /* we don't care about a possible delay here */ - common_event_loop_timer_delay(select_ev->ev); + tevent_common_loop_timer_delay(select_ev->ev); return 0; } @@ -258,7 +262,7 @@ static int select_event_loop_once(struct tevent_context *ev) struct select_event_context); struct timeval tval; - tval = common_event_loop_timer_delay(ev); + tval = tevent_common_loop_timer_delay(ev); if (ev_timeval_is_zero(&tval)) { return 0; } @@ -289,8 +293,8 @@ static const struct tevent_ops select_event_ops = { .add_fd = select_event_add_fd, .get_fd_flags = select_event_get_fd_flags, .set_fd_flags = select_event_set_fd_flags, - .add_timer = common_event_add_timed, - .add_signal = common_event_add_signal, + .add_timer = tevent_common_add_timer, + .add_signal = tevent_common_add_signal, .loop_once = select_event_loop_once, .loop_wait = select_event_loop_wait, }; diff --git a/lib/tevent/tevent_signal.c b/lib/tevent/tevent_signal.c index fdd7070625..031845927b 100644 --- a/lib/tevent/tevent_signal.c +++ b/lib/tevent/tevent_signal.c @@ -45,7 +45,7 @@ struct sigcounter { the poor design of signals means that this table must be static global */ static struct sig_state { - struct signal_event *sig_handlers[NUM_SIGNALS+1]; + struct tevent_signal *sig_handlers[NUM_SIGNALS+1]; struct sigaction *oldact[NUM_SIGNALS+1]; struct sigcounter signal_count[NUM_SIGNALS+1]; struct sigcounter got_signal; @@ -107,7 +107,7 @@ static void signal_handler_info(int signum, siginfo_t *info, void *uctx) /* destroy a signal event */ -static int signal_event_destructor(struct signal_event *se) +static int tevent_signal_destructor(struct tevent_signal *se) { se->event_ctx->num_signal_handlers--; DLIST_REMOVE(sig_state->sig_handlers[se->signum], se); @@ -140,14 +140,16 @@ static void signal_pipe_handler(struct tevent_context *ev, struct tevent_fd *fde add a signal event return NULL on failure (memory allocation error) */ -struct signal_event *common_event_add_signal(struct tevent_context *ev, - TALLOC_CTX *mem_ctx, - int signum, - int sa_flags, - event_signal_handler_t handler, - void *private_data) +struct tevent_signal *tevent_common_add_signal(struct tevent_context *ev, + TALLOC_CTX *mem_ctx, + int signum, + int sa_flags, + tevent_signal_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { - struct signal_event *se; + struct tevent_signal *se; if (signum >= NUM_SIGNALS) { return NULL; @@ -162,15 +164,18 @@ struct signal_event *common_event_add_signal(struct tevent_context *ev, } } - se = talloc(mem_ctx?mem_ctx:ev, struct signal_event); + se = talloc(mem_ctx?mem_ctx:ev, struct tevent_signal); if (se == NULL) return NULL; se->event_ctx = ev; - se->handler = handler; - se->private_data = private_data; se->signum = signum; se->sa_flags = sa_flags; - + se->handler = handler; + se->private_data = private_data; + se->handler_name = handler_name; + se->location = location; + se->additional_data = NULL; + /* Ensure, no matter the destruction order, that we always have a handle on the global sig_state */ if (!talloc_reference(se, sig_state)) { return NULL; @@ -208,7 +213,7 @@ struct signal_event *common_event_add_signal(struct tevent_context *ev, DLIST_ADD(sig_state->sig_handlers[signum], se); - talloc_set_destructor(se, signal_event_destructor); + talloc_set_destructor(se, tevent_signal_destructor); /* we need to setup the pipe hack handler if not already setup */ @@ -219,8 +224,8 @@ struct signal_event *common_event_add_signal(struct tevent_context *ev, ev_set_blocking(sig_state->pipe_hack[0], false); ev_set_blocking(sig_state->pipe_hack[1], false); } - ev->pipe_fde = event_add_fd(ev, ev, sig_state->pipe_hack[0], - EVENT_FD_READ, signal_pipe_handler, NULL); + ev->pipe_fde = tevent_add_fd(ev, ev, sig_state->pipe_hack[0], + TEVENT_FD_READ, signal_pipe_handler, NULL); } ev->num_signal_handlers++; @@ -232,7 +237,7 @@ struct signal_event *common_event_add_signal(struct tevent_context *ev, check if a signal is pending return != 0 if a signal was pending */ -int common_event_check_signal(struct tevent_context *ev) +int tevent_common_check_signal(struct tevent_context *ev) { int i; @@ -241,7 +246,7 @@ int common_event_check_signal(struct tevent_context *ev) } for (i=0;isignal_count[i]; uint32_t count = sig_count(counter); diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c index 7abb695d89..05310a5864 100644 --- a/lib/tevent/tevent_standard.c +++ b/lib/tevent/tevent_standard.c @@ -266,14 +266,14 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv } if (std_ev->ev->num_signal_handlers && - common_event_check_signal(std_ev->ev)) { + tevent_common_check_signal(std_ev->ev)) { return 0; } ret = epoll_wait(std_ev->epoll_fd, events, MAXEVENTS, timeout); if (ret == -1 && errno == EINTR && std_ev->ev->num_signal_handlers) { - if (common_event_check_signal(std_ev->ev)) { + if (tevent_common_check_signal(std_ev->ev)) { return 0; } } @@ -285,7 +285,7 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv if (ret == 0 && tvalp) { /* we don't care about a possible delay here */ - common_event_loop_timer_delay(std_ev->ev); + tevent_common_loop_timer_delay(std_ev->ev); return 0; } @@ -405,9 +405,11 @@ static int std_event_fd_destructor(struct tevent_fd *fde) return NULL on failure (memory allocation error) */ static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - int fd, uint16_t flags, - event_fd_handler_t handler, - void *private_data) + int fd, uint16_t flags, + tevent_fd_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct std_event_context *std_ev = talloc_get_type(ev->additional_data, struct std_event_context); @@ -496,7 +498,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva } if (std_ev->ev->num_signal_handlers && - common_event_check_signal(std_ev->ev)) { + tevent_common_check_signal(std_ev->ev)) { return 0; } @@ -504,7 +506,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva if (selrtn == -1 && errno == EINTR && std_ev->ev->num_signal_handlers) { - common_event_check_signal(std_ev->ev); + tevent_common_check_signal(std_ev->ev); return 0; } @@ -522,7 +524,7 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva if (selrtn == 0 && tvalp) { /* we don't care about a possible delay here */ - common_event_loop_timer_delay(std_ev->ev); + tevent_common_loop_timer_delay(std_ev->ev); return 0; } @@ -556,7 +558,7 @@ static int std_event_loop_once(struct tevent_context *ev) struct std_event_context); struct timeval tval; - tval = common_event_loop_timer_delay(ev); + tval = tevent_common_loop_timer_delay(ev); if (ev_timeval_is_zero(&tval)) { return 0; } @@ -593,8 +595,8 @@ static const struct tevent_ops std_event_ops = { .add_fd = std_event_add_fd, .get_fd_flags = std_event_get_fd_flags, .set_fd_flags = std_event_set_fd_flags, - .add_timer = common_event_add_timed, - .add_signal = common_event_add_signal, + .add_timer = tevent_common_add_timer, + .add_signal = tevent_common_add_signal, .loop_once = std_event_loop_once, .loop_wait = std_event_loop_wait, }; diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c index 4ad457221e..dadd360416 100644 --- a/lib/tevent/tevent_timed.c +++ b/lib/tevent/tevent_timed.c @@ -106,7 +106,7 @@ bool ev_timeval_is_zero(const struct timeval *tv) /* destroy a timed event */ -static int common_event_timed_destructor(struct tevent_timer *te) +static int tevent_common_timed_destructor(struct tevent_timer *te) { struct tevent_context *ev = talloc_get_type(te->event_ctx, struct tevent_context); @@ -114,7 +114,7 @@ static int common_event_timed_destructor(struct tevent_timer *te) return 0; } -static int common_event_timed_deny_destructor(struct tevent_timer *te) +static int tevent_common_timed_deny_destructor(struct tevent_timer *te) { return -1; } @@ -123,10 +123,12 @@ static int common_event_timed_deny_destructor(struct tevent_timer *te) add a timed event return NULL on failure (memory allocation error) */ -struct tevent_timer *common_event_add_timed(struct tevent_context *ev, TALLOC_CTX *mem_ctx, - struct timeval next_event, - event_timed_handler_t handler, - void *private_data) +struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, TALLOC_CTX *mem_ctx, + struct timeval next_event, + tevent_timer_handler_t handler, + void *private_data, + const char *handler_name, + const char *location) { struct tevent_timer *te, *last_te, *cur_te; @@ -137,6 +139,8 @@ struct tevent_timer *common_event_add_timed(struct tevent_context *ev, TALLOC_CT te->next_event = next_event; te->handler = handler; te->private_data = private_data; + te->handler_name = handler_name; + te->location = location; te->additional_data = NULL; /* keep the list ordered */ @@ -152,7 +156,7 @@ struct tevent_timer *common_event_add_timed(struct tevent_context *ev, TALLOC_CT DLIST_ADD_AFTER(ev->timer_events, te, last_te); - talloc_set_destructor(te, common_event_timed_destructor); + talloc_set_destructor(te, tevent_common_timed_destructor); return te; } @@ -163,7 +167,7 @@ struct tevent_timer *common_event_add_timed(struct tevent_context *ev, TALLOC_CT return the delay untill the next timed event, or zero if a timed event was triggered */ -struct timeval common_event_loop_timer_delay(struct tevent_context *ev) +struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev) { struct timeval current_time = ev_timeval_zero(); struct tevent_timer *te = ev->timer_events; @@ -200,7 +204,7 @@ struct timeval common_event_loop_timer_delay(struct tevent_context *ev) */ /* deny the handler to free the event */ - talloc_set_destructor(te, common_event_timed_deny_destructor); + talloc_set_destructor(te, tevent_common_timed_deny_destructor); /* We need to remove the timer from the list before calling the * handler because in a semi-async inner event loop called from the -- cgit From d79fc2ffcd9802d927f82f014c2b13c7eb8cc873 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 14:20:37 +0100 Subject: tevent: rename events => tevent in tevent.pc metze --- lib/tevent/tevent.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/tevent/tevent.pc.in b/lib/tevent/tevent.pc.in index afd9fcc279..93d0cf5d8b 100644 --- a/lib/tevent/tevent.pc.in +++ b/lib/tevent/tevent.pc.in @@ -3,7 +3,7 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ -Name: events +Name: tevent Description: An event system library Version: @PACKAGE_VERSION@ Libs: -L${libdir} -ltevent -- cgit From 4f04b06ac2cfceddaabcbf661f9878ff69a6f01b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 13:39:56 +0100 Subject: tevent: rename ev_debug_ops => tevent_debug_ops And related changes, but we keep compat macros metze --- lib/tevent/tevent.h | 28 ++++++++++++++++++++++++++++ lib/tevent/tevent_aio.c | 3 ++- lib/tevent/tevent_debug.c | 32 +++++++++++++++++++------------- lib/tevent/tevent_epoll.c | 12 ++++++------ lib/tevent/tevent_internal.h | 18 +++++------------- lib/tevent/tevent_select.c | 4 ++-- lib/tevent/tevent_standard.c | 14 +++++++------- 7 files changed, 69 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index fd6b613b9d..f4e04355e6 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -119,6 +119,22 @@ void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags); #define TEVENT_FD_NOT_READABLE(fde) \ tevent_fd_set_flags(fde, tevent_fd_get_flags(fde) & ~TEVENT_FD_READ) +/* DEBUG */ +enum tevent_debug_level { + TEVENT_DEBUG_FATAL, + TEVENT_DEBUG_ERROR, + TEVENT_DEBUG_WARNING, + TEVENT_DEBUG_TRACE +}; + +int tevent_set_debug(struct tevent_context *ev, + void (*debug)(void *context, + enum tevent_debug_level level, + const char *fmt, + va_list ap) PRINTF_ATTRIBUTE(3,0), + void *context); +int tevent_set_debug_stderr(struct tevent_context *ev); + /* for now always define the compat symbols */ #ifndef TEVENT_COMPAT_DEFINES #define TEVENT_COMPAT_DEFINES 1 @@ -190,6 +206,18 @@ void tevent_fd_set_flags(struct tevent_fd *fde, uint16_t flags); #define EVENT_FD_NOT_READABLE(fde) \ TEVENT_FD_NOT_READABLE(fde) +#define ev_debug_level tevent_debug_level + +#define EV_DEBUG_FATAL TEVENT_DEBUG_FATAL +#define EV_DEBUG_ERROR TEVENT_DEBUG_ERROR +#define EV_DEBUG_WARNING TEVENT_DEBUG_WARNING +#define EV_DEBUG_TRACE TEVENT_DEBUG_TRACE + +#define ev_set_debug(ev, debug, context) \ + tevent_set_debug(ev, debug, context) + +#define ev_set_debug_stderr(_ev) tevent_set_debug_stderr(ev) + #endif /* TEVENT_COMPAT_DEFINES */ #endif /* __TEVENT_H__ */ diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index f3045fbf97..f59a7505ab 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -114,7 +114,8 @@ static void epoll_check_reopen(struct aio_event_context *aio_ev) close(aio_ev->epoll_fd); aio_ev->epoll_fd = epoll_create(MAX_AIO_QUEUE_DEPTH); if (aio_ev->epoll_fd == -1) { - ev_debug(aio_ev->ev, EV_DEBUG_FATAL, "Failed to recreate epoll handle after fork\n"); + tevent_debug(aio_ev->ev, TEVENT_DEBUG_FATAL, + "Failed to recreate epoll handle after fork\n"); return; } aio_ev->pid = getpid(); diff --git a/lib/tevent/tevent_debug.c b/lib/tevent/tevent_debug.c index 4fa58534b4..841446bf6c 100644 --- a/lib/tevent/tevent_debug.c +++ b/lib/tevent/tevent_debug.c @@ -30,10 +30,12 @@ /* this allows the user to choose their own debug function */ -int ev_set_debug(struct tevent_context *ev, - void (*debug)(void *context, enum ev_debug_level level, - const char *fmt, va_list ap), - void *context) +int tevent_set_debug(struct tevent_context *ev, + void (*debug)(void *context, + enum tevent_debug_level level, + const char *fmt, + va_list ap) PRINTF_ATTRIBUTE(3,0), + void *context) { ev->debug_ops.debug = debug; ev->debug_ops.context = context; @@ -43,23 +45,26 @@ int ev_set_debug(struct tevent_context *ev, /* debug function for ev_set_debug_stderr */ -void ev_debug_stderr(void *context, enum ev_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); -void ev_debug_stderr(void *context, enum ev_debug_level level, - const char *fmt, va_list ap) +static void tevent_debug_stderr(void *private_data, + enum tevent_debug_level level, + const char *fmt, + va_list ap) PRINTF_ATTRIBUTE(3,0); +static void tevent_debug_stderr(void *private_data, + enum tevent_debug_level level, + const char *fmt, va_list ap) { - if (level <= EV_DEBUG_WARNING) { + if (level <= TEVENT_DEBUG_WARNING) { vfprintf(stderr, fmt, ap); } } /* convenience function to setup debug messages on stderr - messages of level EV_DEBUG_WARNING and higher are printed + messages of level TEVENT_DEBUG_WARNING and higher are printed */ -int ev_set_debug_stderr(struct tevent_context *ev) +int tevent_set_debug_stderr(struct tevent_context *ev) { - return ev_set_debug(ev, ev_debug_stderr, ev); + return tevent_set_debug(ev, tevent_debug_stderr, ev); } /* @@ -70,7 +75,8 @@ int ev_set_debug_stderr(struct tevent_context *ev) * Applications using the library must decide where to * redirect debugging messages */ -void ev_debug(struct tevent_context *ev, enum ev_debug_level level, const char *fmt, ...) +void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level, + const char *fmt, ...) { va_list ap; if (ev->debug_ops.debug == NULL) { diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index d2703eda6c..8e93004ff3 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -58,7 +58,7 @@ struct epoll_event_context { */ static void epoll_panic(struct epoll_event_context *epoll_ev, const char *reason) { - ev_debug(epoll_ev->ev, EV_DEBUG_FATAL, + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL, "%s (%s) - calling abort()\n", reason, strerror(errno)); abort(); } @@ -116,8 +116,8 @@ static void epoll_check_reopen(struct epoll_event_context *epoll_ev) close(epoll_ev->epoll_fd); epoll_ev->epoll_fd = epoll_create(64); if (epoll_ev->epoll_fd == -1) { - ev_debug(epoll_ev->ev, EV_DEBUG_FATAL, - "Failed to recreate epoll handle after fork\n"); + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL, + "Failed to recreate epoll handle after fork\n"); return; } epoll_ev->pid = getpid(); @@ -176,9 +176,9 @@ static void epoll_del_event(struct epoll_event_context *epoll_ev, struct tevent_ event.events = epoll_map_flags(fde->flags); event.data.ptr = fde; if (epoll_ctl(epoll_ev->epoll_fd, EPOLL_CTL_DEL, fde->fd, &event) != 0) { - ev_debug(epoll_ev->ev, EV_DEBUG_FATAL, - "epoll_del_event failed! probable early close bug (%s)\n", - strerror(errno)); + tevent_debug(epoll_ev->ev, TEVENT_DEBUG_FATAL, + "epoll_del_event failed! probable early close bug (%s)\n", + strerror(errno)); } fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; } diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h index 408136dc71..46ba1b1655 100644 --- a/lib/tevent/tevent_internal.h +++ b/lib/tevent/tevent_internal.h @@ -111,22 +111,14 @@ struct tevent_signal { void *additional_data; }; -/* DEBUG */ -enum ev_debug_level {EV_DEBUG_FATAL, EV_DEBUG_ERROR, - EV_DEBUG_WARNING, EV_DEBUG_TRACE}; - -struct ev_debug_ops { - void (*debug)(void *context, enum ev_debug_level level, +struct tevent_debug_ops { + void (*debug)(void *context, enum tevent_debug_level level, const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); void *context; }; -int ev_set_debug(struct tevent_context *ev, - void (*debug)(void *context, enum ev_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0), - void *context); -int ev_set_debug_stderr(struct tevent_context *ev); -void ev_debug(struct tevent_context *ev, enum ev_debug_level level, const char *fmt, ...); +void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level, + const char *fmt, ...) PRINTF_ATTRIBUTE(3,4); /* aio event is private to the aio backend */ struct tevent_aio; @@ -148,7 +140,7 @@ struct tevent_context { struct tevent_fd *pipe_fde; /* debugging operations */ - struct ev_debug_ops debug_ops; + struct tevent_debug_ops debug_ops; }; diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c index b082400a8e..06bc1aa0c9 100644 --- a/lib/tevent/tevent_select.c +++ b/lib/tevent/tevent_select.c @@ -220,8 +220,8 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru made readable and that should have removed the event, so this must be a bug. This is a fatal error. */ - ev_debug(select_ev->ev, EV_DEBUG_FATAL, - "ERROR: EBADF on select_event_loop_once\n"); + tevent_debug(select_ev->ev, TEVENT_DEBUG_FATAL, + "ERROR: EBADF on select_event_loop_once\n"); select_ev->exit_code = EBADF; return -1; } diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c index 05310a5864..762b834952 100644 --- a/lib/tevent/tevent_standard.c +++ b/lib/tevent/tevent_standard.c @@ -71,9 +71,9 @@ struct std_event_context { */ static void epoll_fallback_to_select(struct std_event_context *std_ev, const char *reason) { - ev_debug(std_ev->ev, EV_DEBUG_FATAL, - "%s (%s) - falling back to select()\n", - reason, strerror(errno)); + tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, + "%s (%s) - falling back to select()\n", + reason, strerror(errno)); close(std_ev->epoll_fd); std_ev->epoll_fd = -1; talloc_set_destructor(std_ev, NULL); @@ -130,8 +130,8 @@ static void epoll_check_reopen(struct std_event_context *std_ev) close(std_ev->epoll_fd); std_ev->epoll_fd = epoll_create(64); if (std_ev->epoll_fd == -1) { - ev_debug(std_ev->ev, EV_DEBUG_FATAL, - "Failed to recreate epoll handle after fork\n"); + tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, + "Failed to recreate epoll handle after fork\n"); return; } std_ev->pid = getpid(); @@ -516,8 +516,8 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva made readable and that should have removed the event, so this must be a bug. This is a fatal error. */ - ev_debug(std_ev->ev, EV_DEBUG_FATAL, - "ERROR: EBADF on std_event_loop_once\n"); + tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, + "ERROR: EBADF on std_event_loop_once\n"); std_ev->exit_code = EBADF; return -1; } -- cgit From 784b2dc8d02c4e5c1ae31314f08874fa57416c40 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 16:25:29 +0100 Subject: tevent: use TEVENT_FD_* instead of EVENT_FD_* metze --- lib/tevent/tevent_aio.c | 20 ++++++++++---------- lib/tevent/tevent_epoll.c | 24 ++++++++++++------------ lib/tevent/tevent_select.c | 10 +++++----- lib/tevent/tevent_standard.c | 32 ++++++++++++++++---------------- 4 files changed, 43 insertions(+), 43 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent_aio.c b/lib/tevent/tevent_aio.c index f59a7505ab..ba798cc799 100644 --- a/lib/tevent/tevent_aio.c +++ b/lib/tevent/tevent_aio.c @@ -80,8 +80,8 @@ struct tevent_aio { static uint32_t epoll_map_flags(uint16_t flags) { uint32_t ret = 0; - if (flags & EVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); - if (flags & EVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); return ret; } @@ -148,7 +148,7 @@ static void epoll_add_event(struct aio_event_context *aio_ev, struct tevent_fd * fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -193,7 +193,7 @@ static void epoll_mod_event(struct aio_event_context *aio_ev, struct tevent_fd * epoll_ctl(aio_ev->epoll_fd, EPOLL_CTL_MOD, fde->fd, &event); /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -201,8 +201,8 @@ static void epoll_mod_event(struct aio_event_context *aio_ev, struct tevent_fd * static void epoll_change_event(struct aio_event_context *aio_ev, struct tevent_fd *fde) { bool got_error = (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR); - bool want_read = (fde->flags & EVENT_FD_READ); - bool want_write= (fde->flags & EVENT_FD_WRITE); + bool want_read = (fde->flags & TEVENT_FD_READ); + bool want_write= (fde->flags & TEVENT_FD_WRITE); if (aio_ev->epoll_fd == -1) return; @@ -328,10 +328,10 @@ static int aio_event_loop(struct aio_event_context *aio_ev, struct timeval *tval epoll_del_event(aio_ev, fde); continue; } - flags |= EVENT_FD_READ; + flags |= TEVENT_FD_READ; } - if (ep->events & EPOLLIN) flags |= EVENT_FD_READ; - if (ep->events & EPOLLOUT) flags |= EVENT_FD_WRITE; + if (ep->events & EPOLLIN) flags |= TEVENT_FD_READ; + if (ep->events & EPOLLOUT) flags |= TEVENT_FD_WRITE; if (flags) { fde->handler(aio_ev->ev, fde, flags, fde->private_data); } @@ -400,7 +400,7 @@ static int aio_event_fd_destructor(struct tevent_fd *fde) epoll_del_event(aio_ev, fde); - if (fde->flags & EVENT_FD_AUTOCLOSE) { + if (fde->flags & TEVENT_FD_AUTOCLOSE) { close(fde->fd); fde->fd = -1; } diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c index 8e93004ff3..380d9461c9 100644 --- a/lib/tevent/tevent_epoll.c +++ b/lib/tevent/tevent_epoll.c @@ -64,13 +64,13 @@ static void epoll_panic(struct epoll_event_context *epoll_ev, const char *reason } /* - map from EVENT_FD_* to EPOLLIN/EPOLLOUT + map from TEVENT_FD_* to EPOLLIN/EPOLLOUT */ static uint32_t epoll_map_flags(uint16_t flags) { uint32_t ret = 0; - if (flags & EVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); - if (flags & EVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); return ret; } @@ -153,7 +153,7 @@ static void epoll_add_event(struct epoll_event_context *epoll_ev, struct tevent_ fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -201,7 +201,7 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_ } /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -209,8 +209,8 @@ static void epoll_mod_event(struct epoll_event_context *epoll_ev, struct tevent_ static void epoll_change_event(struct epoll_event_context *epoll_ev, struct tevent_fd *fde) { bool got_error = (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR); - bool want_read = (fde->flags & EVENT_FD_READ); - bool want_write= (fde->flags & EVENT_FD_WRITE); + bool want_read = (fde->flags & TEVENT_FD_READ); + bool want_write= (fde->flags & TEVENT_FD_WRITE); if (epoll_ev->epoll_fd == -1) return; @@ -293,7 +293,7 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval if (events[i].events & (EPOLLHUP|EPOLLERR)) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR; /* - * if we only wait for EVENT_FD_WRITE, we should not tell the + * if we only wait for TEVENT_FD_WRITE, we should not tell the * event handler about it, and remove the epoll_event, * as we only report errors when waiting for read events, * to match the select() behavior @@ -302,10 +302,10 @@ static int epoll_event_loop(struct epoll_event_context *epoll_ev, struct timeval epoll_del_event(epoll_ev, fde); continue; } - flags |= EVENT_FD_READ; + flags |= TEVENT_FD_READ; } - if (events[i].events & EPOLLIN) flags |= EVENT_FD_READ; - if (events[i].events & EPOLLOUT) flags |= EVENT_FD_WRITE; + if (events[i].events & EPOLLIN) flags |= TEVENT_FD_READ; + if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE; if (flags) { fde->handler(epoll_ev->ev, fde, flags, fde->private_data); if (destruction_count != epoll_ev->destruction_count) { @@ -358,7 +358,7 @@ static int epoll_event_fd_destructor(struct tevent_fd *fde) epoll_del_event(epoll_ev, fde); - if (fde->flags & EVENT_FD_AUTOCLOSE) { + if (fde->flags & TEVENT_FD_AUTOCLOSE) { close(fde->fd); fde->fd = -1; } diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c index 06bc1aa0c9..e21b3c44b9 100644 --- a/lib/tevent/tevent_select.c +++ b/lib/tevent/tevent_select.c @@ -103,7 +103,7 @@ static int select_event_fd_destructor(struct tevent_fd *fde) DLIST_REMOVE(select_ev->fd_events, fde); select_ev->destruction_count++; - if (fde->flags & EVENT_FD_AUTOCLOSE) { + if (fde->flags & TEVENT_FD_AUTOCLOSE) { close(fde->fd); fde->fd = -1; } @@ -193,10 +193,10 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru /* setup any fd events */ for (fde = select_ev->fd_events; fde; fde = fde->next) { - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { FD_SET(fde->fd, &r_fds); } - if (fde->flags & EVENT_FD_WRITE) { + if (fde->flags & TEVENT_FD_WRITE) { FD_SET(fde->fd, &w_fds); } } @@ -239,8 +239,8 @@ static int select_event_loop_select(struct select_event_context *select_ev, stru for (fde = select_ev->fd_events; fde; fde = fde->next) { uint16_t flags = 0; - if (FD_ISSET(fde->fd, &r_fds)) flags |= EVENT_FD_READ; - if (FD_ISSET(fde->fd, &w_fds)) flags |= EVENT_FD_WRITE; + if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ; + if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE; if (flags) { fde->handler(select_ev->ev, fde, flags, fde->private_data); if (destruction_count != select_ev->destruction_count) { diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c index 762b834952..5769eac589 100644 --- a/lib/tevent/tevent_standard.c +++ b/lib/tevent/tevent_standard.c @@ -80,13 +80,13 @@ static void epoll_fallback_to_select(struct std_event_context *std_ev, const cha } /* - map from EVENT_FD_* to EPOLLIN/EPOLLOUT + map from TEVENT_FD_* to EPOLLIN/EPOLLOUT */ static uint32_t epoll_map_flags(uint16_t flags) { uint32_t ret = 0; - if (flags & EVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); - if (flags & EVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); + if (flags & TEVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); return ret; } @@ -166,7 +166,7 @@ static void epoll_add_event(struct std_event_context *std_ev, struct tevent_fd * fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -209,7 +209,7 @@ static void epoll_mod_event(struct std_event_context *std_ev, struct tevent_fd * } /* only if we want to read we want to tell the event handler about errors */ - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; } } @@ -217,8 +217,8 @@ static void epoll_mod_event(struct std_event_context *std_ev, struct tevent_fd * static void epoll_change_event(struct std_event_context *std_ev, struct tevent_fd *fde) { bool got_error = (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR); - bool want_read = (fde->flags & EVENT_FD_READ); - bool want_write= (fde->flags & EVENT_FD_WRITE); + bool want_read = (fde->flags & TEVENT_FD_READ); + bool want_write= (fde->flags & TEVENT_FD_WRITE); if (std_ev->epoll_fd == -1) return; @@ -301,7 +301,7 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv if (events[i].events & (EPOLLHUP|EPOLLERR)) { fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR; /* - * if we only wait for EVENT_FD_WRITE, we should not tell the + * if we only wait for TEVENT_FD_WRITE, we should not tell the * event handler about it, and remove the epoll_event, * as we only report errors when waiting for read events, * to match the select() behavior @@ -310,10 +310,10 @@ static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tv epoll_del_event(std_ev, fde); continue; } - flags |= EVENT_FD_READ; + flags |= TEVENT_FD_READ; } - if (events[i].events & EPOLLIN) flags |= EVENT_FD_READ; - if (events[i].events & EPOLLOUT) flags |= EVENT_FD_WRITE; + if (events[i].events & EPOLLIN) flags |= TEVENT_FD_READ; + if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE; if (flags) { fde->handler(std_ev->ev, fde, flags, fde->private_data); if (destruction_count != std_ev->destruction_count) { @@ -392,7 +392,7 @@ static int std_event_fd_destructor(struct tevent_fd *fde) epoll_del_event(std_ev, fde); - if (fde->flags & EVENT_FD_AUTOCLOSE) { + if (fde->flags & TEVENT_FD_AUTOCLOSE) { close(fde->fd); fde->fd = -1; } @@ -489,10 +489,10 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva /* setup any fd events */ for (fde = std_ev->fd_events; fde; fde = fde->next) { - if (fde->flags & EVENT_FD_READ) { + if (fde->flags & TEVENT_FD_READ) { FD_SET(fde->fd, &r_fds); } - if (fde->flags & EVENT_FD_WRITE) { + if (fde->flags & TEVENT_FD_WRITE) { FD_SET(fde->fd, &w_fds); } } @@ -535,8 +535,8 @@ static int std_event_loop_select(struct std_event_context *std_ev, struct timeva for (fde = std_ev->fd_events; fde; fde = fde->next) { uint16_t flags = 0; - if (FD_ISSET(fde->fd, &r_fds)) flags |= EVENT_FD_READ; - if (FD_ISSET(fde->fd, &w_fds)) flags |= EVENT_FD_WRITE; + if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ; + if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE; if (flags) { fde->handler(std_ev->ev, fde, flags, fde->private_data); if (destruction_count != std_ev->destruction_count) { -- cgit From 2176295b02cb39945d5335d93f0c5dfe054c9b9a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 16:27:11 +0100 Subject: tevent: change pytevent to tevent_* metze --- lib/tevent/pytevent.c | 39 ++++++++++++++++++++------------------- lib/tevent/tests.py | 8 ++++---- 2 files changed, 24 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c index a969373738..3d71d78397 100644 --- a/lib/tevent/pytevent.c +++ b/lib/tevent/pytevent.c @@ -24,9 +24,9 @@ typedef struct { PyObject_HEAD struct tevent_context *ev_ctx; -} PyEventContextObject; +} PyTEventContextObject; -PyAPI_DATA(PyTypeObject) PyEventContext; +PyAPI_DATA(PyTypeObject) PyTEventContext; static PyObject *py_set_default_backend(PyObject *self, PyObject *args) { @@ -34,13 +34,13 @@ static PyObject *py_set_default_backend(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "s", &name)) return NULL; - event_set_default_backend(name); + tevent_set_default_backend(name); return Py_None; } static PyObject *py_backend_list(PyObject *self) { - const char **backends = event_backend_list(NULL); + const char **backends = tevent_backend_list(NULL); PyObject *ret; int i, len; @@ -66,28 +66,28 @@ static PyObject *py_event_ctx_new(PyTypeObject *type, PyObject *args, PyObject * const char *kwnames[] = { "name", NULL }; char *name = NULL; struct tevent_context *ev_ctx; - PyEventContextObject *ret; + PyTEventContextObject *ret; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", (char **)kwnames, &name)) return NULL; if (name == NULL) - ev_ctx = event_context_init(NULL); + ev_ctx = tevent_context_init(NULL); else - ev_ctx = event_context_init_byname(NULL, name); + ev_ctx = tevent_context_init_byname(NULL, name); - ret = (PyEventContextObject *)type->tp_alloc(type, 0); + ret = (PyTEventContextObject *)type->tp_alloc(type, 0); ret->ev_ctx = ev_ctx; return (PyObject *)ret; } -static PyObject *py_event_ctx_loop_once(PyEventContextObject *self) +static PyObject *py_event_ctx_loop_once(PyTEventContextObject *self) { - return PyInt_FromLong(event_loop_once(self->ev_ctx)); + return PyInt_FromLong(tevent_loop_once(self->ev_ctx)); } -static PyObject *py_event_ctx_loop_wait(PyEventContextObject *self) +static PyObject *py_event_ctx_loop_wait(PyTEventContextObject *self) { - return PyInt_FromLong(event_loop_wait(self->ev_ctx)); + return PyInt_FromLong(tevent_loop_wait(self->ev_ctx)); } static PyMethodDef py_event_ctx_methods[] = { @@ -98,16 +98,17 @@ static PyMethodDef py_event_ctx_methods[] = { { NULL } }; -static void py_event_ctx_dealloc(PyEventContextObject * self) +static void py_event_ctx_dealloc(PyTEventContextObject * self) { talloc_free(self->ev_ctx); self->ob_type->tp_free(self); } -PyTypeObject PyEventContext = { - .tp_name = "EventContext", + +PyTypeObject PyTEventContext = { + .tp_name = "TEventContext", .tp_methods = py_event_ctx_methods, - .tp_basicsize = sizeof(PyEventContextObject), + .tp_basicsize = sizeof(PyTEventContextObject), .tp_dealloc = (destructor)py_event_ctx_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = py_event_ctx_new, @@ -117,14 +118,14 @@ void inittevent(void) { PyObject *m; - if (PyType_Ready(&PyEventContext) < 0) + if (PyType_Ready(&PyTEventContext) < 0) return; m = Py_InitModule3("tevent", tevent_methods, "Event management."); if (m == NULL) return; - Py_INCREF(&PyEventContext); - PyModule_AddObject(m, "EventContext", (PyObject *)&PyEventContext); + Py_INCREF(&PyTEventContext); + PyModule_AddObject(m, "TEventContext", (PyObject *)&PyTEventContext); } diff --git a/lib/tevent/tests.py b/lib/tevent/tests.py index 0ec736b359..bf594a14f6 100644 --- a/lib/tevent/tests.py +++ b/lib/tevent/tests.py @@ -17,15 +17,15 @@ # along with this program. If not, see . # -import tevent as events +import tevent import unittest # Just test the bindings are there and that calling them doesn't crash # anything. -class EventTestCase(unittest.TestCase): +class TEventTestCase(unittest.TestCase): def test_create(self): - self.assertTrue(events.EventContext() is not None) + self.assertTrue(tevent.TEventContext() is not None) def test_loop_wait(self): - self.assertEquals(0, events.EventContext().loop_wait()) + self.assertEquals(0, tevent.TEventContext().loop_wait()) -- cgit From 73ef1773bebc206522b0a285573254441fc6a18a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 2 Jan 2009 16:28:38 +0100 Subject: tevent: only provide compat macros if the caller wants them metze --- lib/tevent/tevent.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lib') diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index f4e04355e6..01e79df208 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -135,11 +135,6 @@ int tevent_set_debug(struct tevent_context *ev, void *context); int tevent_set_debug_stderr(struct tevent_context *ev); -/* for now always define the compat symbols */ -#ifndef TEVENT_COMPAT_DEFINES -#define TEVENT_COMPAT_DEFINES 1 -#endif - #ifdef TEVENT_COMPAT_DEFINES #define event_context tevent_context -- cgit