From 944305dc21350fd2ec32a9552d893da86894fd62 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 4 Mar 2016 15:36:32 -0300 Subject: Added gettimeout for completeness. Also documented. Rordered manuals so order is alphabetical. --- src/tcp.c | 8 ++++++++ src/timeout.c | 10 ++++++++++ src/timeout.h | 1 + src/udp.c | 7 +++++++ 4 files changed, 26 insertions(+) (limited to 'src') diff --git a/src/tcp.c b/src/tcp.c index e4f1a4b..ef9ee6f 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -36,6 +36,7 @@ static int meth_accept(lua_State *L); static int meth_close(lua_State *L); static int meth_getoption(lua_State *L); static int meth_setoption(lua_State *L); +static int meth_gettimeout(lua_State *L); static int meth_settimeout(lua_State *L); static int meth_getfd(lua_State *L); static int meth_setfd(lua_State *L); @@ -65,6 +66,7 @@ static luaL_Reg tcp_methods[] = { {"setpeername", meth_connect}, {"setsockname", meth_bind}, {"settimeout", meth_settimeout}, + {"gettimeout", meth_gettimeout}, {"shutdown", meth_shutdown}, {NULL, NULL} }; @@ -350,6 +352,12 @@ static int meth_settimeout(lua_State *L) return timeout_meth_settimeout(L, &tcp->tm); } +static int meth_gettimeout(lua_State *L) +{ + p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1); + return timeout_meth_gettimeout(L, &tcp->tm); +} + /*=========================================================================*\ * Library functions \*=========================================================================*/ diff --git a/src/timeout.c b/src/timeout.c index 087d033..5a601d5 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -173,6 +173,16 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) { return 1; } +/*-------------------------------------------------------------------------*\ +* Gets timeout values for IO operations +* Lua Output: block, total +\*-------------------------------------------------------------------------*/ +int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { + lua_pushnumber(L, tm->block); + lua_pushnumber(L, tm->total); + return 2; +} + /*=========================================================================*\ * Test support functions \*=========================================================================*/ diff --git a/src/timeout.h b/src/timeout.h index 6715ca7..af90231 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -22,6 +22,7 @@ p_timeout timeout_markstart(p_timeout tm); double timeout_getstart(p_timeout tm); double timeout_gettime(void); int timeout_meth_settimeout(lua_State *L, p_timeout tm); +int timeout_meth_gettimeout(lua_State *L, p_timeout tm); #define timeout_iszero(tm) ((tm)->block == 0.0) diff --git a/src/udp.c b/src/udp.c index 968dca8..ec97252 100644 --- a/src/udp.c +++ b/src/udp.c @@ -36,6 +36,7 @@ static int meth_receivefrom(lua_State *L); static int meth_getfamily(lua_State *L); static int meth_getsockname(lua_State *L); static int meth_getpeername(lua_State *L); +static int meth_gettimeout(lua_State *L); static int meth_setsockname(lua_State *L); static int meth_setpeername(lua_State *L); static int meth_close(lua_State *L); @@ -66,6 +67,7 @@ static luaL_Reg udp_methods[] = { {"setpeername", meth_setpeername}, {"setsockname", meth_setsockname}, {"settimeout", meth_settimeout}, + {"gettimeout", meth_gettimeout}, {NULL, NULL} }; @@ -347,6 +349,11 @@ static int meth_settimeout(lua_State *L) { return timeout_meth_settimeout(L, &udp->tm); } +static int meth_gettimeout(lua_State *L) { + p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); + return timeout_meth_gettimeout(L, &udp->tm); +} + /*-------------------------------------------------------------------------*\ * Turns a master udp object into a client object. \*-------------------------------------------------------------------------*/ -- cgit v1.2.3-55-g6feb