diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-20 22:19:54 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-20 22:19:54 +0000 |
commit | f7579db9e830ef41f422a280d26c9077f48728e5 (patch) | |
tree | d96affac7f5e8203d2e9c4a053213a992cd76650 /src/timeout.c | |
parent | 5dc5c3ebe8f111bba01762ca0f5edba912c4f0b9 (diff) | |
download | luasocket-f7579db9e830ef41f422a280d26c9077f48728e5.tar.gz luasocket-f7579db9e830ef41f422a280d26c9077f48728e5.tar.bz2 luasocket-f7579db9e830ef41f422a280d26c9077f48728e5.zip |
Fixing bugs...
Diffstat (limited to 'src/timeout.c')
-rw-r--r-- | src/timeout.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/timeout.c b/src/timeout.c index 3472ca7..e089051 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -18,12 +18,6 @@ | |||
18 | #else | 18 | #else |
19 | #include <time.h> | 19 | #include <time.h> |
20 | #include <sys/time.h> | 20 | #include <sys/time.h> |
21 | #include <sys/times.h> | ||
22 | #include <unistd.h> | ||
23 | #ifndef CLK_TCK | ||
24 | /* CLI_TCK is now obsolete in Linux */ | ||
25 | #define CLK_TCK (sysconf(_SC_CLK_TCK)); | ||
26 | #endif | ||
27 | #endif | 21 | #endif |
28 | 22 | ||
29 | /* min and max macros */ | 23 | /* min and max macros */ |
@@ -37,11 +31,11 @@ | |||
37 | /*=========================================================================*\ | 31 | /*=========================================================================*\ |
38 | * Internal function prototypes | 32 | * Internal function prototypes |
39 | \*=========================================================================*/ | 33 | \*=========================================================================*/ |
40 | static int tm_lua_time(lua_State *L); | 34 | static int tm_lua_gettime(lua_State *L); |
41 | static int tm_lua_sleep(lua_State *L); | 35 | static int tm_lua_sleep(lua_State *L); |
42 | 36 | ||
43 | static luaL_reg func[] = { | 37 | static luaL_reg func[] = { |
44 | { "time", tm_lua_time }, | 38 | { "gettime", tm_lua_gettime }, |
45 | { "sleep", tm_lua_sleep }, | 39 | { "sleep", tm_lua_sleep }, |
46 | { NULL, NULL } | 40 | { NULL, NULL } |
47 | }; | 41 | }; |
@@ -141,8 +135,10 @@ int tm_gettime(void) | |||
141 | #else | 135 | #else |
142 | int tm_gettime(void) | 136 | int tm_gettime(void) |
143 | { | 137 | { |
144 | struct tms t; | 138 | struct timeval v; |
145 | return (times(&t)*1000)/CLK_TCK; | 139 | struct timezone z = {0, 0}; |
140 | gettimeofday(&v, &z); | ||
141 | return v.tv_sec * 1000 + v.tv_usec/1000; | ||
146 | } | 142 | } |
147 | #endif | 143 | #endif |
148 | 144 | ||
@@ -186,7 +182,7 @@ int tm_meth_settimeout(lua_State *L, p_tm tm) | |||
186 | /*-------------------------------------------------------------------------*\ | 182 | /*-------------------------------------------------------------------------*\ |
187 | * Returns the time the system has been up, in secconds. | 183 | * Returns the time the system has been up, in secconds. |
188 | \*-------------------------------------------------------------------------*/ | 184 | \*-------------------------------------------------------------------------*/ |
189 | static int tm_lua_time(lua_State *L) | 185 | static int tm_lua_gettime(lua_State *L) |
190 | { | 186 | { |
191 | lua_pushnumber(L, tm_gettime()/1000.0); | 187 | lua_pushnumber(L, tm_gettime()/1000.0); |
192 | return 1; | 188 | return 1; |
@@ -199,9 +195,13 @@ int tm_lua_sleep(lua_State *L) | |||
199 | { | 195 | { |
200 | double n = luaL_checknumber(L, 1); | 196 | double n = luaL_checknumber(L, 1); |
201 | #ifdef _WIN32 | 197 | #ifdef _WIN32 |
202 | Sleep((int)n*1000); | 198 | Sleep((int)(n*1000)); |
203 | #else | 199 | #else |
204 | sleep((int)n); | 200 | struct timespec t, r; |
201 | t.tv_sec = (int) n; | ||
202 | n -= t.tv_sec; | ||
203 | t.tv_nsec = (int) (n * 1000000000) % 1000000000; | ||
204 | nanosleep(&t, &r); | ||
205 | #endif | 205 | #endif |
206 | return 0; | 206 | return 0; |
207 | } | 207 | } |