From c1aa8b847b80f2a59bcf95984496be128b964928 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 12 Dec 2015 18:01:24 +0100 Subject: [PATCH] respondd: add monotonic timestamp to lua calls to allow caching --- net/respondd/src/respondd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/net/respondd/src/respondd.c b/net/respondd/src/respondd.c index 8f4e46e..5a4e490 100644 --- a/net/respondd/src/respondd.c +++ b/net/respondd/src/respondd.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -71,6 +72,7 @@ static void join_mcast(const int sock, const struct in6_addr addr, const char *i static void serve(lua_State *L, int sock) { char buffer[256]; ssize_t read_bytes; + struct timespec tp; lua_pushvalue(L, -1); @@ -84,9 +86,12 @@ static void serve(lua_State *L, int sock) { exit(EXIT_FAILURE); } - lua_pushlstring(L, buffer, read_bytes); + clock_gettime(CLOCK_MONOTONIC, &tp); - if (lua_pcall(L, 1, 1, 0)) { + lua_pushlstring(L, buffer, read_bytes); + lua_pushnumber(L, tp.tv_sec + 1.0e-9*tp.tv_nsec); + + if (lua_pcall(L, 2, 1, 0)) { fprintf(stderr, "%s\n", lua_tostring(L, -1)); } else if (lua_isstring(L, -1)) {