diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2019-03-11 00:08:41 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-11 00:08:41 -0300 |
| commit | c89a931cc31f219d51dd32a8a253d5ee3fbd31be (patch) | |
| tree | 1fc604d7cbd6a42c801b92b145651d91c458dfa2 /src/timeout.c | |
| parent | 2af4872a401cbd0c1255e19ee26620f0431dd9f5 (diff) | |
| parent | 21514304be9e98a4386cb18542582068a59c5586 (diff) | |
| download | luasocket-c89a931cc31f219d51dd32a8a253d5ee3fbd31be.tar.gz luasocket-c89a931cc31f219d51dd32a8a253d5ee3fbd31be.tar.bz2 luasocket-c89a931cc31f219d51dd32a8a253d5ee3fbd31be.zip | |
Merge pull request #271 from ewestbrook/pragmavisibility
Use visibility pragma around declarations instead of attributes on definitions
Diffstat (limited to 'src/timeout.c')
| -rw-r--r-- | src/timeout.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/timeout.c b/src/timeout.c index 8fb8f55..2bdc069 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
| @@ -4,10 +4,6 @@ | |||
| 4 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
| 5 | #include "luasocket.h" | 5 | #include "luasocket.h" |
| 6 | 6 | ||
| 7 | #include "lua.h" | ||
| 8 | #include "lauxlib.h" | ||
| 9 | #include "compat.h" | ||
| 10 | |||
| 11 | #include "auxiliar.h" | 7 | #include "auxiliar.h" |
| 12 | #include "timeout.h" | 8 | #include "timeout.h" |
| 13 | 9 | ||
| @@ -48,7 +44,7 @@ static luaL_Reg func[] = { | |||
| 48 | /*-------------------------------------------------------------------------*\ | 44 | /*-------------------------------------------------------------------------*\ |
| 49 | * Initialize structure | 45 | * Initialize structure |
| 50 | \*-------------------------------------------------------------------------*/ | 46 | \*-------------------------------------------------------------------------*/ |
| 51 | LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { | 47 | void timeout_init(p_timeout tm, double block, double total) { |
| 52 | tm->block = block; | 48 | tm->block = block; |
| 53 | tm->total = total; | 49 | tm->total = total; |
| 54 | } | 50 | } |
| @@ -61,7 +57,7 @@ LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { | |||
| 61 | * Returns | 57 | * Returns |
| 62 | * the number of ms left or -1 if there is no time limit | 58 | * the number of ms left or -1 if there is no time limit |
| 63 | \*-------------------------------------------------------------------------*/ | 59 | \*-------------------------------------------------------------------------*/ |
| 64 | LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { | 60 | double timeout_get(p_timeout tm) { |
| 65 | if (tm->block < 0.0 && tm->total < 0.0) { | 61 | if (tm->block < 0.0 && tm->total < 0.0) { |
| 66 | return -1; | 62 | return -1; |
| 67 | } else if (tm->block < 0.0) { | 63 | } else if (tm->block < 0.0) { |
| @@ -82,7 +78,7 @@ LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { | |||
| 82 | * Returns | 78 | * Returns |
| 83 | * start field of structure | 79 | * start field of structure |
| 84 | \*-------------------------------------------------------------------------*/ | 80 | \*-------------------------------------------------------------------------*/ |
| 85 | LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { | 81 | double timeout_getstart(p_timeout tm) { |
| 86 | return tm->start; | 82 | return tm->start; |
| 87 | } | 83 | } |
| 88 | 84 | ||
| @@ -94,7 +90,7 @@ LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { | |||
| 94 | * Returns | 90 | * Returns |
| 95 | * the number of ms left or -1 if there is no time limit | 91 | * the number of ms left or -1 if there is no time limit |
| 96 | \*-------------------------------------------------------------------------*/ | 92 | \*-------------------------------------------------------------------------*/ |
| 97 | LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { | 93 | double timeout_getretry(p_timeout tm) { |
| 98 | if (tm->block < 0.0 && tm->total < 0.0) { | 94 | if (tm->block < 0.0 && tm->total < 0.0) { |
| 99 | return -1; | 95 | return -1; |
| 100 | } else if (tm->block < 0.0) { | 96 | } else if (tm->block < 0.0) { |
| @@ -114,7 +110,7 @@ LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { | |||
| 114 | * Input | 110 | * Input |
| 115 | * tm: timeout control structure | 111 | * tm: timeout control structure |
| 116 | \*-------------------------------------------------------------------------*/ | 112 | \*-------------------------------------------------------------------------*/ |
| 117 | LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { | 113 | p_timeout timeout_markstart(p_timeout tm) { |
| 118 | tm->start = timeout_gettime(); | 114 | tm->start = timeout_gettime(); |
| 119 | return tm; | 115 | return tm; |
| 120 | } | 116 | } |
| @@ -125,7 +121,7 @@ LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { | |||
| 125 | * time in s. | 121 | * time in s. |
| 126 | \*-------------------------------------------------------------------------*/ | 122 | \*-------------------------------------------------------------------------*/ |
| 127 | #ifdef _WIN32 | 123 | #ifdef _WIN32 |
| 128 | LUASOCKET_PRIVATE double timeout_gettime(void) { | 124 | double timeout_gettime(void) { |
| 129 | FILETIME ft; | 125 | FILETIME ft; |
| 130 | double t; | 126 | double t; |
| 131 | GetSystemTimeAsFileTime(&ft); | 127 | GetSystemTimeAsFileTime(&ft); |
| @@ -135,7 +131,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { | |||
| 135 | return (t - 11644473600.0); | 131 | return (t - 11644473600.0); |
| 136 | } | 132 | } |
| 137 | #else | 133 | #else |
| 138 | LUASOCKET_PRIVATE double timeout_gettime(void) { | 134 | double timeout_gettime(void) { |
| 139 | struct timeval v; | 135 | struct timeval v; |
| 140 | gettimeofday(&v, (struct timezone *) NULL); | 136 | gettimeofday(&v, (struct timezone *) NULL); |
| 141 | /* Unix Epoch time (time since January 1, 1970 (UTC)) */ | 137 | /* Unix Epoch time (time since January 1, 1970 (UTC)) */ |
| @@ -146,7 +142,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { | |||
| 146 | /*-------------------------------------------------------------------------*\ | 142 | /*-------------------------------------------------------------------------*\ |
| 147 | * Initializes module | 143 | * Initializes module |
| 148 | \*-------------------------------------------------------------------------*/ | 144 | \*-------------------------------------------------------------------------*/ |
| 149 | LUASOCKET_PRIVATE int timeout_open(lua_State *L) { | 145 | int timeout_open(lua_State *L) { |
| 150 | luaL_setfuncs(L, func, 0); | 146 | luaL_setfuncs(L, func, 0); |
| 151 | return 0; | 147 | return 0; |
| 152 | } | 148 | } |
| @@ -157,7 +153,7 @@ LUASOCKET_PRIVATE int timeout_open(lua_State *L) { | |||
| 157 | * time: time out value in seconds | 153 | * time: time out value in seconds |
| 158 | * mode: "b" for block timeout, "t" for total timeout. (default: b) | 154 | * mode: "b" for block timeout, "t" for total timeout. (default: b) |
| 159 | \*-------------------------------------------------------------------------*/ | 155 | \*-------------------------------------------------------------------------*/ |
| 160 | LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { | 156 | int timeout_meth_settimeout(lua_State *L, p_timeout tm) { |
| 161 | double t = luaL_optnumber(L, 2, -1); | 157 | double t = luaL_optnumber(L, 2, -1); |
| 162 | const char *mode = luaL_optstring(L, 3, "b"); | 158 | const char *mode = luaL_optstring(L, 3, "b"); |
| 163 | switch (*mode) { | 159 | switch (*mode) { |
| @@ -179,7 +175,7 @@ LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { | |||
| 179 | * Gets timeout values for IO operations | 175 | * Gets timeout values for IO operations |
| 180 | * Lua Output: block, total | 176 | * Lua Output: block, total |
| 181 | \*-------------------------------------------------------------------------*/ | 177 | \*-------------------------------------------------------------------------*/ |
| 182 | LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { | 178 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { |
| 183 | lua_pushnumber(L, tm->block); | 179 | lua_pushnumber(L, tm->block); |
| 184 | lua_pushnumber(L, tm->total); | 180 | lua_pushnumber(L, tm->total); |
| 185 | return 2; | 181 | return 2; |
| @@ -201,7 +197,7 @@ static int timeout_lua_gettime(lua_State *L) | |||
| 201 | * Sleep for n seconds. | 197 | * Sleep for n seconds. |
| 202 | \*-------------------------------------------------------------------------*/ | 198 | \*-------------------------------------------------------------------------*/ |
| 203 | #ifdef _WIN32 | 199 | #ifdef _WIN32 |
| 204 | LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | 200 | int timeout_lua_sleep(lua_State *L) |
| 205 | { | 201 | { |
| 206 | double n = luaL_checknumber(L, 1); | 202 | double n = luaL_checknumber(L, 1); |
| 207 | if (n < 0.0) n = 0.0; | 203 | if (n < 0.0) n = 0.0; |
| @@ -211,7 +207,7 @@ LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | |||
| 211 | return 0; | 207 | return 0; |
| 212 | } | 208 | } |
| 213 | #else | 209 | #else |
| 214 | LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | 210 | int timeout_lua_sleep(lua_State *L) |
| 215 | { | 211 | { |
| 216 | double n = luaL_checknumber(L, 1); | 212 | double n = luaL_checknumber(L, 1); |
| 217 | struct timespec t, r; | 213 | struct timespec t, r; |
