summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-01 11:24:51 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-01 10:38:47 +0200
commit0204ae6229bae3573b3194c3f657c8f385c0b940 (patch)
treeceedf55cc2064b7780f17df62d881872b384a6b4 /lib/util
parent56e72337b01216dc7cba418f040a5cc928e5fc6f (diff)
downloadsamba-0204ae6229bae3573b3194c3f657c8f385c0b940.tar.gz
samba-0204ae6229bae3573b3194c3f657c8f385c0b940.tar.bz2
samba-0204ae6229bae3573b3194c3f657c8f385c0b940.zip
lib/util/time.c: timeval_current_ofs_usec
Several places want "microseconds from current time", and several were simply handing "usecs" values which could be over a million. Using a helper to do this is safer and more readable. I didn't replace any obviously correct callers (ie. constants). I also renamed wait_nsec in source3/lib/util_sock.c; it's actually microseconds not nanoseconds (introduced with this code in Volker's 19b783cc Async wrapper for open_socket_out_send/recv). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/time.c9
-rw-r--r--lib/util/time.h5
2 files changed, 14 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index de1553aff8..d8fd4a3dfc 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -589,6 +589,15 @@ _PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs)
}
/**
+ return a timeval microseconds into the future
+*/
+_PUBLIC_ struct timeval timeval_current_ofs_usec(uint32_t usecs)
+{
+ struct timeval tv = timeval_current();
+ return timeval_add(&tv, usecs / 1000000, usecs % 1000000);
+}
+
+/**
compare two timeval structures.
Return -1 if tv1 < tv2
Return 0 if tv1 == tv2
diff --git a/lib/util/time.h b/lib/util/time.h
index 4e4f72f71f..1f7f57db77 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -218,6 +218,11 @@ _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs);
_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs);
/**
+ return a timeval microseconds into the future
+*/
+_PUBLIC_ struct timeval timeval_current_ofs_usec(uint32_t usecs);
+
+/**
compare two timeval structures.
Return -1 if tv1 < tv2
Return 0 if tv1 == tv2