diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2009-05-27 09:31:38 +0000 |
| commit | bce60be30fe8e9c1b0eb33128c23c93d7bca5303 (patch) | |
| tree | 3927343c777fcb7764a0f2f89754a0ceab141c21 /src/timeout.c | |
| parent | d1a72435d5bd3528f3c334cd4d1da16dcead47bf (diff) | |
| download | luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.gz luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.tar.bz2 luasocket-bce60be30fe8e9c1b0eb33128c23c93d7bca5303.zip | |
Decent makefiles!
Diffstat (limited to 'src/timeout.c')
| -rw-r--r-- | src/timeout.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/timeout.c b/src/timeout.c index 863546e..fb015f9 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
| @@ -5,6 +5,8 @@ | |||
| 5 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
| 6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | #include <limits.h> | ||
| 9 | #include <float.h> | ||
| 8 | 10 | ||
| 9 | #include "lua.h" | 11 | #include "lua.h" |
| 10 | #include "lauxlib.h" | 12 | #include "lauxlib.h" |
| @@ -187,13 +189,23 @@ static int timeout_lua_gettime(lua_State *L) | |||
| 187 | /*-------------------------------------------------------------------------*\ | 189 | /*-------------------------------------------------------------------------*\ |
| 188 | * Sleep for n seconds. | 190 | * Sleep for n seconds. |
| 189 | \*-------------------------------------------------------------------------*/ | 191 | \*-------------------------------------------------------------------------*/ |
| 192 | #ifdef _WIN32 | ||
| 190 | int timeout_lua_sleep(lua_State *L) | 193 | int timeout_lua_sleep(lua_State *L) |
| 191 | { | 194 | { |
| 192 | double n = luaL_checknumber(L, 1); | 195 | double n = luaL_checknumber(L, 1); |
| 193 | #ifdef _WIN32 | 196 | if (n < 0.0) n = 0.0; |
| 194 | Sleep((int)(n*1000)); | 197 | if (n < DBL_MAX/1000.0) n *= 1000.0; |
| 198 | if (n > INT_MAX) n = INT_MAX; | ||
| 199 | Sleep((int)n); | ||
| 200 | return 0; | ||
| 201 | } | ||
| 195 | #else | 202 | #else |
| 203 | int timeout_lua_sleep(lua_State *L) | ||
| 204 | { | ||
| 205 | double n = luaL_checknumber(L, 1); | ||
| 196 | struct timespec t, r; | 206 | struct timespec t, r; |
| 207 | if (n < 0.0) n = 0.0; | ||
| 208 | if (n > INT_MAX) n = INT_MAX; | ||
| 197 | t.tv_sec = (int) n; | 209 | t.tv_sec = (int) n; |
| 198 | n -= t.tv_sec; | 210 | n -= t.tv_sec; |
| 199 | t.tv_nsec = (int) (n * 1000000000); | 211 | t.tv_nsec = (int) (n * 1000000000); |
| @@ -202,6 +214,6 @@ int timeout_lua_sleep(lua_State *L) | |||
| 202 | t.tv_sec = r.tv_sec; | 214 | t.tv_sec = r.tv_sec; |
| 203 | t.tv_nsec = r.tv_nsec; | 215 | t.tv_nsec = r.tv_nsec; |
| 204 | } | 216 | } |
| 205 | #endif | ||
| 206 | return 0; | 217 | return 0; |
| 207 | } | 218 | } |
| 219 | #endif | ||
