Repository: qpid-proton Updated Branches: refs/heads/master a61f50e94 -> b2e1acd97
PROTON-1471: Implement pn_proactor_now(void) - This returns a millisecond monotonic time since an arbitrary timepoint Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b2e1acd9 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b2e1acd9 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b2e1acd9 Branch: refs/heads/master Commit: b2e1acd97c4d66d0f62618aa715d408a0e01e3d1 Parents: a61f50e Author: Andrew Stitcher <[email protected]> Authored: Thu Apr 27 12:58:07 2017 -0400 Committer: Andrew Stitcher <[email protected]> Committed: Thu Apr 27 13:06:38 2017 -0400 ---------------------------------------------------------------------- proton-c/include/proton/proactor.h | 10 ++++++++++ proton-c/src/proactor/epoll.c | 6 ++++++ proton-c/src/proactor/libuv.c | 4 ++++ 3 files changed, 20 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b2e1acd9/proton-c/include/proton/proactor.h ---------------------------------------------------------------------- diff --git a/proton-c/include/proton/proactor.h b/proton-c/include/proton/proactor.h index 901bc62..8b193b5 100644 --- a/proton-c/include/proton/proactor.h +++ b/proton-c/include/proton/proactor.h @@ -335,6 +335,16 @@ PNP_EXTERN const struct sockaddr_storage *pn_proactor_addr_sockaddr(const pn_pro /** + * Get the real elapsed time since an arbitrary point in the past in milliseconds. + * + * This may be used as a portable way to get a timestamp for the current time. It is monotonically + * increasing and will never go backwards. + * + * @note Thread safe. + */ +PNP_EXTERN pn_millis_t pn_proactor_now(void); + +/** * @defgroup proactor_events Events * * **Experimental** - Events returned by pn_proactor_wait(). http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b2e1acd9/proton-c/src/proactor/epoll.c ---------------------------------------------------------------------- diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c index b1175f4..6f9e237 100644 --- a/proton-c/src/proactor/epoll.c +++ b/proton-c/src/proactor/epoll.c @@ -46,6 +46,7 @@ #include <netinet/tcp.h> #include <sys/eventfd.h> #include <limits.h> +#include <time.h> // TODO: replace timerfd per connection with global lightweight timer mechanism. // logging in general, listener events in particular @@ -1755,3 +1756,8 @@ size_t pn_proactor_addr_str(const struct pn_proactor_addr_t* addr, char *buf, si } } +pn_millis_t pn_proactor_now(void) { + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + return t.tv_sec*1000 + t.tv_nsec/1000000; +} http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b2e1acd9/proton-c/src/proactor/libuv.c ---------------------------------------------------------------------- diff --git a/proton-c/src/proactor/libuv.c b/proton-c/src/proactor/libuv.c index 4992b40..5a7f97d 100644 --- a/proton-c/src/proactor/libuv.c +++ b/proton-c/src/proactor/libuv.c @@ -1294,3 +1294,7 @@ size_t pn_proactor_addr_str(const struct pn_proactor_addr_t* addr, char *buf, si return 0; } } + +pn_millis_t pn_proactor_now(void) { + return uv_hrtime() / 1000000; // uv_hrtime returns time in nanoseconds +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
