summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-03-16 14:15:07 +0100
committerStefan Metzmacher <metze@samba.org>2009-03-17 19:58:57 +0100
commit940e61846e97ba62153d5b977b0823f196607743 (patch)
tree22e0442255cd2d6eca42b6f260a7436c8181a716 /lib
parent0139befb915006d6ec9fec2734057c5c50b3c383 (diff)
downloadsamba-940e61846e97ba62153d5b977b0823f196607743.tar.gz
samba-940e61846e97ba62153d5b977b0823f196607743.tar.bz2
samba-940e61846e97ba62153d5b977b0823f196607743.zip
tevent: add tevent_common_loop_wait() helper function and use it
tevent_loop_wait should do the same for all backends. It should loop as long as we have pending events. metze
Diffstat (limited to 'lib')
-rw-r--r--lib/tevent/tevent.c28
-rw-r--r--lib/tevent/tevent_epoll.c18
-rw-r--r--lib/tevent/tevent_internal.h2
-rw-r--r--lib/tevent/tevent_select.c20
-rw-r--r--lib/tevent/tevent_standard.c20
5 files changed, 33 insertions, 55 deletions
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 867cfc08fe..31dc58d98e 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -514,6 +514,34 @@ done:
/*
return on failure or (with 0) if all fd events are removed
*/
+int tevent_common_loop_wait(struct tevent_context *ev,
+ const char *location)
+{
+ /*
+ * loop as long as we have events pending
+ */
+ while (ev->fd_events ||
+ ev->timer_events ||
+ ev->immediate_events ||
+ ev->signal_events) {
+ int ret;
+ ret = _tevent_loop_once(ev, location);
+ if (ret != 0) {
+ tevent_debug(ev, TEVENT_DEBUG_FATAL,
+ "_tevent_loop_once() failed: %d - %s\n",
+ ret, strerror(errno));
+ return ret;
+ }
+ }
+
+ tevent_debug(ev, TEVENT_DEBUG_WARNING,
+ "tevent_common_loop_wait() out of events\n");
+ return 0;
+}
+
+/*
+ return on failure or (with 0) if all fd events are removed
+*/
int _tevent_loop_wait(struct tevent_context *ev, const char *location)
{
return ev->ops->loop_wait(ev, location);
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index 6c960c7491..32544593de 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -419,22 +419,6 @@ static int epoll_event_loop_once(struct tevent_context *ev, const char *location
return epoll_event_loop(epoll_ev, &tval);
}
-/*
- return on failure or (with 0) if all fd events are removed
-*/
-static int epoll_event_loop_wait(struct tevent_context *ev, const char *location)
-{
- struct epoll_event_context *epoll_ev = talloc_get_type(ev->additional_data,
- struct epoll_event_context);
- while (epoll_ev->ev->fd_events) {
- if (epoll_event_loop_once(ev, location) != 0) {
- break;
- }
- }
-
- return 0;
-}
-
static const struct tevent_ops epoll_event_ops = {
.context_init = epoll_event_context_init,
.add_fd = epoll_event_add_fd,
@@ -444,7 +428,7 @@ static const struct tevent_ops epoll_event_ops = {
.add_timer = tevent_common_add_timer,
.add_signal = tevent_common_add_signal,
.loop_once = epoll_event_loop_once,
- .loop_wait = epoll_event_loop_wait,
+ .loop_wait = tevent_common_loop_wait,
};
bool tevent_epoll_init(void)
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index f10485398f..f63a58aadd 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -247,6 +247,8 @@ struct tevent_context {
bool tevent_register_backend(const char *name, const struct tevent_ops *ops);
int tevent_common_context_destructor(struct tevent_context *ev);
+int tevent_common_loop_wait(struct tevent_context *ev,
+ const char *location);
int tevent_common_fd_destructor(struct tevent_fd *fde);
struct tevent_fd *tevent_common_add_fd(struct tevent_context *ev,
diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c
index b666b4fba4..1c295d7ca4 100644
--- a/lib/tevent/tevent_select.c
+++ b/lib/tevent/tevent_select.c
@@ -223,24 +223,6 @@ static int select_event_loop_once(struct tevent_context *ev, const char *locatio
return select_event_loop_select(select_ev, &tval);
}
-/*
- return on failure or (with 0) if all fd events are removed
-*/
-static int select_event_loop_wait(struct tevent_context *ev, const char *location)
-{
- struct select_event_context *select_ev = talloc_get_type(ev->additional_data,
- struct select_event_context);
- select_ev->exit_code = 0;
-
- while (ev->fd_events && select_ev->exit_code == 0) {
- if (select_event_loop_once(ev, location) != 0) {
- break;
- }
- }
-
- return select_ev->exit_code;
-}
-
static const struct tevent_ops select_event_ops = {
.context_init = select_event_context_init,
.add_fd = select_event_add_fd,
@@ -250,7 +232,7 @@ static const struct tevent_ops select_event_ops = {
.add_timer = tevent_common_add_timer,
.add_signal = tevent_common_add_signal,
.loop_once = select_event_loop_once,
- .loop_wait = select_event_loop_wait,
+ .loop_wait = tevent_common_loop_wait,
};
bool tevent_select_init(void)
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 40a08d7ab0..88db6a1725 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -543,24 +543,6 @@ static int std_event_loop_once(struct tevent_context *ev, const char *location)
return std_event_loop_select(std_ev, &tval);
}
-/*
- return on failure or (with 0) if all fd events are removed
-*/
-static int std_event_loop_wait(struct tevent_context *ev, const char *location)
-{
- struct std_event_context *std_ev = talloc_get_type(ev->additional_data,
- struct std_event_context);
- std_ev->exit_code = 0;
-
- while (ev->fd_events && std_ev->exit_code == 0) {
- if (std_event_loop_once(ev, location) != 0) {
- break;
- }
- }
-
- return std_ev->exit_code;
-}
-
static const struct tevent_ops std_event_ops = {
.context_init = std_event_context_init,
.add_fd = std_event_add_fd,
@@ -570,7 +552,7 @@ static const struct tevent_ops std_event_ops = {
.add_timer = tevent_common_add_timer,
.add_signal = tevent_common_add_signal,
.loop_once = std_event_loop_once,
- .loop_wait = std_event_loop_wait,
+ .loop_wait = tevent_common_loop_wait,
};