diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2016-03-04 15:36:32 -0300 |
|---|---|---|
| committer | Diego Nehab <diego.nehab@gmail.com> | 2016-03-04 15:36:32 -0300 |
| commit | 944305dc21350fd2ec32a9552d893da86894fd62 (patch) | |
| tree | 82948c24dade5e0da6924ab5e706f146bce4692a /src | |
| parent | cdce73b226cc4da6a073b79bec02a6780d32ff1a (diff) | |
| download | luasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.gz luasocket-944305dc21350fd2ec32a9552d893da86894fd62.tar.bz2 luasocket-944305dc21350fd2ec32a9552d893da86894fd62.zip | |
Added gettimeout for completeness.
Also documented.
Rordered manuals so order is alphabetical.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tcp.c | 8 | ||||
| -rw-r--r-- | src/timeout.c | 10 | ||||
| -rw-r--r-- | src/timeout.h | 1 | ||||
| -rw-r--r-- | src/udp.c | 7 |
4 files changed, 26 insertions, 0 deletions
| @@ -36,6 +36,7 @@ static int meth_accept(lua_State *L); | |||
| 36 | static int meth_close(lua_State *L); | 36 | static int meth_close(lua_State *L); |
| 37 | static int meth_getoption(lua_State *L); | 37 | static int meth_getoption(lua_State *L); |
| 38 | static int meth_setoption(lua_State *L); | 38 | static int meth_setoption(lua_State *L); |
| 39 | static int meth_gettimeout(lua_State *L); | ||
| 39 | static int meth_settimeout(lua_State *L); | 40 | static int meth_settimeout(lua_State *L); |
| 40 | static int meth_getfd(lua_State *L); | 41 | static int meth_getfd(lua_State *L); |
| 41 | static int meth_setfd(lua_State *L); | 42 | static int meth_setfd(lua_State *L); |
| @@ -65,6 +66,7 @@ static luaL_Reg tcp_methods[] = { | |||
| 65 | {"setpeername", meth_connect}, | 66 | {"setpeername", meth_connect}, |
| 66 | {"setsockname", meth_bind}, | 67 | {"setsockname", meth_bind}, |
| 67 | {"settimeout", meth_settimeout}, | 68 | {"settimeout", meth_settimeout}, |
| 69 | {"gettimeout", meth_gettimeout}, | ||
| 68 | {"shutdown", meth_shutdown}, | 70 | {"shutdown", meth_shutdown}, |
| 69 | {NULL, NULL} | 71 | {NULL, NULL} |
| 70 | }; | 72 | }; |
| @@ -350,6 +352,12 @@ static int meth_settimeout(lua_State *L) | |||
| 350 | return timeout_meth_settimeout(L, &tcp->tm); | 352 | return timeout_meth_settimeout(L, &tcp->tm); |
| 351 | } | 353 | } |
| 352 | 354 | ||
| 355 | static int meth_gettimeout(lua_State *L) | ||
| 356 | { | ||
| 357 | p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1); | ||
| 358 | return timeout_meth_gettimeout(L, &tcp->tm); | ||
| 359 | } | ||
| 360 | |||
| 353 | /*=========================================================================*\ | 361 | /*=========================================================================*\ |
| 354 | * Library functions | 362 | * Library functions |
| 355 | \*=========================================================================*/ | 363 | \*=========================================================================*/ |
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) { | |||
| 173 | return 1; | 173 | return 1; |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | /*-------------------------------------------------------------------------*\ | ||
| 177 | * Gets timeout values for IO operations | ||
| 178 | * Lua Output: block, total | ||
| 179 | \*-------------------------------------------------------------------------*/ | ||
| 180 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { | ||
| 181 | lua_pushnumber(L, tm->block); | ||
| 182 | lua_pushnumber(L, tm->total); | ||
| 183 | return 2; | ||
| 184 | } | ||
| 185 | |||
| 176 | /*=========================================================================*\ | 186 | /*=========================================================================*\ |
| 177 | * Test support functions | 187 | * Test support functions |
| 178 | \*=========================================================================*/ | 188 | \*=========================================================================*/ |
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); | |||
| 22 | double timeout_getstart(p_timeout tm); | 22 | double timeout_getstart(p_timeout tm); |
| 23 | double timeout_gettime(void); | 23 | double timeout_gettime(void); |
| 24 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); | 24 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); |
| 25 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm); | ||
| 25 | 26 | ||
| 26 | #define timeout_iszero(tm) ((tm)->block == 0.0) | 27 | #define timeout_iszero(tm) ((tm)->block == 0.0) |
| 27 | 28 | ||
| @@ -36,6 +36,7 @@ static int meth_receivefrom(lua_State *L); | |||
| 36 | static int meth_getfamily(lua_State *L); | 36 | static int meth_getfamily(lua_State *L); |
| 37 | static int meth_getsockname(lua_State *L); | 37 | static int meth_getsockname(lua_State *L); |
| 38 | static int meth_getpeername(lua_State *L); | 38 | static int meth_getpeername(lua_State *L); |
| 39 | static int meth_gettimeout(lua_State *L); | ||
| 39 | static int meth_setsockname(lua_State *L); | 40 | static int meth_setsockname(lua_State *L); |
| 40 | static int meth_setpeername(lua_State *L); | 41 | static int meth_setpeername(lua_State *L); |
| 41 | static int meth_close(lua_State *L); | 42 | static int meth_close(lua_State *L); |
| @@ -66,6 +67,7 @@ static luaL_Reg udp_methods[] = { | |||
| 66 | {"setpeername", meth_setpeername}, | 67 | {"setpeername", meth_setpeername}, |
| 67 | {"setsockname", meth_setsockname}, | 68 | {"setsockname", meth_setsockname}, |
| 68 | {"settimeout", meth_settimeout}, | 69 | {"settimeout", meth_settimeout}, |
| 70 | {"gettimeout", meth_gettimeout}, | ||
| 69 | {NULL, NULL} | 71 | {NULL, NULL} |
| 70 | }; | 72 | }; |
| 71 | 73 | ||
| @@ -347,6 +349,11 @@ static int meth_settimeout(lua_State *L) { | |||
| 347 | return timeout_meth_settimeout(L, &udp->tm); | 349 | return timeout_meth_settimeout(L, &udp->tm); |
| 348 | } | 350 | } |
| 349 | 351 | ||
| 352 | static int meth_gettimeout(lua_State *L) { | ||
| 353 | p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); | ||
| 354 | return timeout_meth_gettimeout(L, &udp->tm); | ||
| 355 | } | ||
| 356 | |||
| 350 | /*-------------------------------------------------------------------------*\ | 357 | /*-------------------------------------------------------------------------*\ |
| 351 | * Turns a master udp object into a client object. | 358 | * Turns a master udp object into a client object. |
| 352 | \*-------------------------------------------------------------------------*/ | 359 | \*-------------------------------------------------------------------------*/ |
