summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-02-16 23:34:15 +0100
committerKai Blin <kai@samba.org>2009-02-17 09:19:31 +0100
commit48b874e3764a20952dfd5e2957a3074073b480db (patch)
treea740b0c89205c06b9856d553a5594d95799550bd
parent046cb24d0ad76b8e01c9c7d0d0146af9f6576047 (diff)
downloadsamba-48b874e3764a20952dfd5e2957a3074073b480db.tar.gz
samba-48b874e3764a20952dfd5e2957a3074073b480db.tar.bz2
samba-48b874e3764a20952dfd5e2957a3074073b480db.zip
tevent: Rename ev_timeval* functions to tevent_timeval, export them.
Also add tevent_timeval_add() and tevent_timeval_current_ofs() to help not depending on lub/util/time.c for things that just need tevent
-rw-r--r--lib/tevent/tevent.h19
-rw-r--r--lib/tevent/tevent_epoll.c2
-rw-r--r--lib/tevent/tevent_internal.h2
-rw-r--r--lib/tevent/tevent_req.c2
-rw-r--r--lib/tevent/tevent_select.c2
-rw-r--r--lib/tevent/tevent_standard.c2
-rw-r--r--lib/tevent/tevent_timed.c55
7 files changed, 61 insertions, 23 deletions
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 9c88bb77fb..8e3d0973eb 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -300,6 +300,25 @@ bool tevent_req_is_error(struct tevent_req *req,
uint64_t *error);
+int tevent_timeval_compare(const struct timeval *tv1,
+ const struct timeval *tv2);
+
+struct timeval tevent_timeval_zero(void);
+
+struct timeval tevent_timeval_current(void);
+
+struct timeval tevent_timeval_set(uint32_t secs, uint32_t usecs);
+
+struct timeval tevent_timeval_until(const struct timeval *tv1,
+ const struct timeval *tv2);
+
+bool tevent_timeval_is_zero(const struct timeval *tv);
+
+struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs,
+ uint32_t usecs);
+
+struct timeval tevent_timeval_current_ofs(uint32_t secs, uint32_t usecs);
+
#ifdef TEVENT_COMPAT_DEFINES
#define event_context tevent_context
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index d7f446a814..0494f55060 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -418,7 +418,7 @@ static int epoll_event_loop_once(struct tevent_context *ev)
struct timeval tval;
tval = tevent_common_loop_timer_delay(ev);
- if (ev_timeval_is_zero(&tval)) {
+ if (tevent_timeval_is_zero(&tval)) {
return 0;
}
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index a25d2b50bb..758bdb4628 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -161,8 +161,6 @@ void tevent_common_fd_set_close_fn(struct tevent_fd *fde,
uint16_t tevent_common_fd_get_flags(struct tevent_fd *fde);
void tevent_common_fd_set_flags(struct tevent_fd *fde, uint16_t flags);
-struct timeval ev_timeval_zero(void);
-bool ev_timeval_is_zero(const struct timeval *tv);
struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev,
TALLOC_CTX *mem_ctx,
struct timeval next_event,
diff --git a/lib/tevent/tevent_req.c b/lib/tevent/tevent_req.c
index 8f2d7bb9bd..0846413f2e 100644
--- a/lib/tevent/tevent_req.c
+++ b/lib/tevent/tevent_req.c
@@ -216,7 +216,7 @@ static void tevent_req_trigger(struct tevent_context *ev,
struct tevent_req *tevent_req_post(struct tevent_req *req,
struct tevent_context *ev)
{
- req->internal.trigger = tevent_add_timer(ev, req, ev_timeval_zero(),
+ req->internal.trigger = tevent_add_timer(ev, req, tevent_timeval_zero(),
tevent_req_trigger, req);
if (!req->internal.trigger) {
talloc_free(req);
diff --git a/lib/tevent/tevent_select.c b/lib/tevent/tevent_select.c
index 0635be50fe..32678f0a15 100644
--- a/lib/tevent/tevent_select.c
+++ b/lib/tevent/tevent_select.c
@@ -220,7 +220,7 @@ static int select_event_loop_once(struct tevent_context *ev)
struct timeval tval;
tval = tevent_common_loop_timer_delay(ev);
- if (ev_timeval_is_zero(&tval)) {
+ if (tevent_timeval_is_zero(&tval)) {
return 0;
}
diff --git a/lib/tevent/tevent_standard.c b/lib/tevent/tevent_standard.c
index 8e107617cf..bbd5c5d785 100644
--- a/lib/tevent/tevent_standard.c
+++ b/lib/tevent/tevent_standard.c
@@ -541,7 +541,7 @@ static int std_event_loop_once(struct tevent_context *ev)
struct timeval tval;
tval = tevent_common_loop_timer_delay(ev);
- if (ev_timeval_is_zero(&tval)) {
+ if (tevent_timeval_is_zero(&tval)) {
return 0;
}
diff --git a/lib/tevent/tevent_timed.c b/lib/tevent/tevent_timed.c
index e06102c2f5..d75653d847 100644
--- a/lib/tevent/tevent_timed.c
+++ b/lib/tevent/tevent_timed.c
@@ -36,7 +36,7 @@
Return 0 if tv1 == tv2
Return 1 if tv1 > tv2
*/
-static int ev_timeval_compare(const struct timeval *tv1, const struct timeval *tv2)
+int tevent_timeval_compare(const struct timeval *tv1, const struct timeval *tv2)
{
if (tv1->tv_sec > tv2->tv_sec) return 1;
if (tv1->tv_sec < tv2->tv_sec) return -1;
@@ -48,7 +48,7 @@ static int ev_timeval_compare(const struct timeval *tv1, const struct timeval *t
/**
return a zero timeval
*/
-struct timeval ev_timeval_zero(void)
+struct timeval tevent_timeval_zero(void)
{
struct timeval tv;
tv.tv_sec = 0;
@@ -59,7 +59,7 @@ struct timeval ev_timeval_zero(void)
/**
return a timeval for the current time
*/
-static struct timeval ev_timeval_current(void)
+struct timeval tevent_timeval_current(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -69,7 +69,7 @@ static struct timeval ev_timeval_current(void)
/**
return a timeval struct with the given elements
*/
-static struct timeval ev_timeval_set(uint32_t secs, uint32_t usecs)
+struct timeval tevent_timeval_set(uint32_t secs, uint32_t usecs)
{
struct timeval tv;
tv.tv_sec = secs;
@@ -82,12 +82,12 @@ static struct timeval ev_timeval_set(uint32_t secs, uint32_t usecs)
if tv1 comes after tv2, then return a zero timeval
(this is *tv2 - *tv1)
*/
-static struct timeval ev_timeval_until(const struct timeval *tv1,
- const struct timeval *tv2)
+struct timeval tevent_timeval_until(const struct timeval *tv1,
+ const struct timeval *tv2)
{
struct timeval t;
- if (ev_timeval_compare(tv1, tv2) >= 0) {
- return ev_timeval_zero();
+ if (tevent_timeval_compare(tv1, tv2) >= 0) {
+ return tevent_timeval_zero();
}
t.tv_sec = tv2->tv_sec - tv1->tv_sec;
if (tv1->tv_usec > tv2->tv_usec) {
@@ -102,11 +102,32 @@ static struct timeval ev_timeval_until(const struct timeval *tv1,
/**
return true if a timeval is zero
*/
-bool ev_timeval_is_zero(const struct timeval *tv)
+bool tevent_timeval_is_zero(const struct timeval *tv)
{
return tv->tv_sec == 0 && tv->tv_usec == 0;
}
+struct timeval tevent_timeval_add(const struct timeval *tv, uint32_t secs,
+ uint32_t usecs)
+{
+ struct timeval tv2 = *tv;
+ tv2.tv_sec += secs;
+ tv2.tv_usec += usecs;
+ tv2.tv_sec += tv2.tv_usec / 1000000;
+ tv2.tv_usec += tv2.tv_usec % 1000000;
+
+ return tv2;
+}
+
+/**
+ return a timeval in the future with a specified offset
+*/
+struct timeval tevent_timeval_current_ofs(uint32_t secs, uint32_t usecs)
+{
+ struct timeval tv = tevent_timeval_current();
+ return tevent_timeval_add(&tv, secs, usecs);
+}
+
/*
destroy a timed event
*/
@@ -156,7 +177,7 @@ struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, TALLOC_C
last_te = NULL;
for (cur_te = ev->timer_events; cur_te; cur_te = cur_te->next) {
/* if the new event comes before the current one break */
- if (ev_timeval_compare(&te->next_event, &cur_te->next_event) < 0) {
+ if (tevent_timeval_compare(&te->next_event, &cur_te->next_event) < 0) {
break;
}
@@ -181,14 +202,14 @@ struct tevent_timer *tevent_common_add_timer(struct tevent_context *ev, TALLOC_C
*/
struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
{
- struct timeval current_time = ev_timeval_zero();
+ struct timeval current_time = tevent_timeval_zero();
struct tevent_timer *te = ev->timer_events;
if (!te) {
/* have a default tick time of 30 seconds. This guarantees
that code that uses its own timeout checking will be
able to proceeed eventually */
- return ev_timeval_set(30, 0);
+ return tevent_timeval_set(30, 0);
}
/*
@@ -200,13 +221,13 @@ struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
* if there's a delay till the next timed event, we're done
* with just returning the delay
*/
- if (!ev_timeval_is_zero(&te->next_event)) {
+ if (!tevent_timeval_is_zero(&te->next_event)) {
struct timeval delay;
- current_time = ev_timeval_current();
+ current_time = tevent_timeval_current();
- delay = ev_timeval_until(&current_time, &te->next_event);
- if (!ev_timeval_is_zero(&delay)) {
+ delay = tevent_timeval_until(&current_time, &te->next_event);
+ if (!tevent_timeval_is_zero(&delay)) {
return delay;
}
}
@@ -242,6 +263,6 @@ struct timeval tevent_common_loop_timer_delay(struct tevent_context *ev)
talloc_free(te);
- return ev_timeval_zero();
+ return tevent_timeval_zero();
}