moonbridge
diff moonbridge_io.c @ 115:7014436d88ea
Added helper function moonbridge_io.timeref(...); HTTP module sends 408 Request Timeout
author | jbe |
---|---|
date | Fri Apr 10 00:33:07 2015 +0200 (2015-04-10) |
parents | 113185a57b06 |
children | 2ab19e15aa6b |
line diff
1.1 --- a/moonbridge_io.c Thu Apr 09 20:02:43 2015 +0200 1.2 +++ b/moonbridge_io.c Fri Apr 10 00:33:07 2015 +0200 1.3 @@ -14,6 +14,7 @@ 1.4 #include <sys/types.h> 1.5 #include <netdb.h> 1.6 #include <signal.h> 1.7 +#include <time.h> 1.8 1.9 #include <lua.h> 1.10 #include <lauxlib.h> 1.11 @@ -1026,6 +1027,17 @@ 1.12 } 1.13 } 1.14 1.15 +static int moonbr_io_timeref(lua_State *L) { 1.16 + lua_Number sub; 1.17 + struct timespec tp; 1.18 + sub = luaL_optnumber(L, 1, 0); 1.19 + if (clock_gettime(CLOCK_MONOTONIC, &tp)) { 1.20 + return luaL_error(L, "Could not access CLOCK_MONOTONIC"); 1.21 + } 1.22 + lua_pushnumber(L, tp.tv_sec + tp.tv_nsec / 1.0e9 - sub); 1.23 + return 1; 1.24 +} 1.25 + 1.26 static const struct luaL_Reg moonbr_io_handle_methods[] = { 1.27 {"read", moonbr_io_read}, 1.28 {"read_nb", moonbr_io_read_nb}, 1.29 @@ -1068,6 +1080,7 @@ 1.30 {"locallisten", moonbr_io_locallisten}, 1.31 {"tcplisten", moonbr_io_tcplisten}, 1.32 {"poll", moonbr_io_poll}, 1.33 + {"timeref", moonbr_io_timeref}, 1.34 {NULL, NULL} 1.35 }; 1.36