diff options
| author | E. Westbrook <github@westbrook.io> | 2019-02-27 21:01:16 -0700 |
|---|---|---|
| committer | E. Westbrook <github@westbrook.io> | 2019-03-10 00:04:20 -0700 |
| commit | 42a1a732b79fa6153c61da645b786da883bbd0b5 (patch) | |
| tree | a5783a545dd47714f4d973798fe9577c41bc829a | |
| parent | 86e1b3f45f57358d6b2a6666043df9a4a2f963c5 (diff) | |
| download | luasocket-42a1a732b79fa6153c61da645b786da883bbd0b5.tar.gz luasocket-42a1a732b79fa6153c61da645b786da883bbd0b5.tar.bz2 luasocket-42a1a732b79fa6153c61da645b786da883bbd0b5.zip | |
timeout: pragma visibility
| -rw-r--r-- | src/timeout.c | 36 | ||||
| -rw-r--r-- | src/timeout.h | 13 |
2 files changed, 30 insertions, 19 deletions
diff --git a/src/timeout.c b/src/timeout.c index 8fb8f55..0e3ee27 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 | ||
| @@ -30,6 +26,10 @@ | |||
| 30 | #define MAX(x, y) ((x) > (y) ? x : y) | 26 | #define MAX(x, y) ((x) > (y) ? x : y) |
| 31 | #endif | 27 | #endif |
| 32 | 28 | ||
| 29 | #ifndef _WIN32 | ||
| 30 | #pragma GCC visibility push(hidden) | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /*=========================================================================*\ | 33 | /*=========================================================================*\ |
| 34 | * Internal function prototypes | 34 | * Internal function prototypes |
| 35 | \*=========================================================================*/ | 35 | \*=========================================================================*/ |
| @@ -48,7 +48,7 @@ static luaL_Reg func[] = { | |||
| 48 | /*-------------------------------------------------------------------------*\ | 48 | /*-------------------------------------------------------------------------*\ |
| 49 | * Initialize structure | 49 | * Initialize structure |
| 50 | \*-------------------------------------------------------------------------*/ | 50 | \*-------------------------------------------------------------------------*/ |
| 51 | LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { | 51 | void timeout_init(p_timeout tm, double block, double total) { |
| 52 | tm->block = block; | 52 | tm->block = block; |
| 53 | tm->total = total; | 53 | tm->total = total; |
| 54 | } | 54 | } |
| @@ -61,7 +61,7 @@ LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) { | |||
| 61 | * Returns | 61 | * Returns |
| 62 | * the number of ms left or -1 if there is no time limit | 62 | * the number of ms left or -1 if there is no time limit |
| 63 | \*-------------------------------------------------------------------------*/ | 63 | \*-------------------------------------------------------------------------*/ |
| 64 | LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { | 64 | double timeout_get(p_timeout tm) { |
| 65 | if (tm->block < 0.0 && tm->total < 0.0) { | 65 | if (tm->block < 0.0 && tm->total < 0.0) { |
| 66 | return -1; | 66 | return -1; |
| 67 | } else if (tm->block < 0.0) { | 67 | } else if (tm->block < 0.0) { |
| @@ -82,7 +82,7 @@ LUASOCKET_PRIVATE double timeout_get(p_timeout tm) { | |||
| 82 | * Returns | 82 | * Returns |
| 83 | * start field of structure | 83 | * start field of structure |
| 84 | \*-------------------------------------------------------------------------*/ | 84 | \*-------------------------------------------------------------------------*/ |
| 85 | LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { | 85 | double timeout_getstart(p_timeout tm) { |
| 86 | return tm->start; | 86 | return tm->start; |
| 87 | } | 87 | } |
| 88 | 88 | ||
| @@ -94,7 +94,7 @@ LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) { | |||
| 94 | * Returns | 94 | * Returns |
| 95 | * the number of ms left or -1 if there is no time limit | 95 | * the number of ms left or -1 if there is no time limit |
| 96 | \*-------------------------------------------------------------------------*/ | 96 | \*-------------------------------------------------------------------------*/ |
| 97 | LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { | 97 | double timeout_getretry(p_timeout tm) { |
| 98 | if (tm->block < 0.0 && tm->total < 0.0) { | 98 | if (tm->block < 0.0 && tm->total < 0.0) { |
| 99 | return -1; | 99 | return -1; |
| 100 | } else if (tm->block < 0.0) { | 100 | } else if (tm->block < 0.0) { |
| @@ -114,7 +114,7 @@ LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) { | |||
| 114 | * Input | 114 | * Input |
| 115 | * tm: timeout control structure | 115 | * tm: timeout control structure |
| 116 | \*-------------------------------------------------------------------------*/ | 116 | \*-------------------------------------------------------------------------*/ |
| 117 | LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { | 117 | p_timeout timeout_markstart(p_timeout tm) { |
| 118 | tm->start = timeout_gettime(); | 118 | tm->start = timeout_gettime(); |
| 119 | return tm; | 119 | return tm; |
| 120 | } | 120 | } |
| @@ -125,7 +125,7 @@ LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) { | |||
| 125 | * time in s. | 125 | * time in s. |
| 126 | \*-------------------------------------------------------------------------*/ | 126 | \*-------------------------------------------------------------------------*/ |
| 127 | #ifdef _WIN32 | 127 | #ifdef _WIN32 |
| 128 | LUASOCKET_PRIVATE double timeout_gettime(void) { | 128 | double timeout_gettime(void) { |
| 129 | FILETIME ft; | 129 | FILETIME ft; |
| 130 | double t; | 130 | double t; |
| 131 | GetSystemTimeAsFileTime(&ft); | 131 | GetSystemTimeAsFileTime(&ft); |
| @@ -135,7 +135,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { | |||
| 135 | return (t - 11644473600.0); | 135 | return (t - 11644473600.0); |
| 136 | } | 136 | } |
| 137 | #else | 137 | #else |
| 138 | LUASOCKET_PRIVATE double timeout_gettime(void) { | 138 | double timeout_gettime(void) { |
| 139 | struct timeval v; | 139 | struct timeval v; |
| 140 | gettimeofday(&v, (struct timezone *) NULL); | 140 | gettimeofday(&v, (struct timezone *) NULL); |
| 141 | /* Unix Epoch time (time since January 1, 1970 (UTC)) */ | 141 | /* Unix Epoch time (time since January 1, 1970 (UTC)) */ |
| @@ -146,7 +146,7 @@ LUASOCKET_PRIVATE double timeout_gettime(void) { | |||
| 146 | /*-------------------------------------------------------------------------*\ | 146 | /*-------------------------------------------------------------------------*\ |
| 147 | * Initializes module | 147 | * Initializes module |
| 148 | \*-------------------------------------------------------------------------*/ | 148 | \*-------------------------------------------------------------------------*/ |
| 149 | LUASOCKET_PRIVATE int timeout_open(lua_State *L) { | 149 | int timeout_open(lua_State *L) { |
| 150 | luaL_setfuncs(L, func, 0); | 150 | luaL_setfuncs(L, func, 0); |
| 151 | return 0; | 151 | return 0; |
| 152 | } | 152 | } |
| @@ -157,7 +157,7 @@ LUASOCKET_PRIVATE int timeout_open(lua_State *L) { | |||
| 157 | * time: time out value in seconds | 157 | * time: time out value in seconds |
| 158 | * mode: "b" for block timeout, "t" for total timeout. (default: b) | 158 | * mode: "b" for block timeout, "t" for total timeout. (default: b) |
| 159 | \*-------------------------------------------------------------------------*/ | 159 | \*-------------------------------------------------------------------------*/ |
| 160 | LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { | 160 | int timeout_meth_settimeout(lua_State *L, p_timeout tm) { |
| 161 | double t = luaL_optnumber(L, 2, -1); | 161 | double t = luaL_optnumber(L, 2, -1); |
| 162 | const char *mode = luaL_optstring(L, 3, "b"); | 162 | const char *mode = luaL_optstring(L, 3, "b"); |
| 163 | switch (*mode) { | 163 | switch (*mode) { |
| @@ -179,7 +179,7 @@ LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) { | |||
| 179 | * Gets timeout values for IO operations | 179 | * Gets timeout values for IO operations |
| 180 | * Lua Output: block, total | 180 | * Lua Output: block, total |
| 181 | \*-------------------------------------------------------------------------*/ | 181 | \*-------------------------------------------------------------------------*/ |
| 182 | LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { | 182 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { |
| 183 | lua_pushnumber(L, tm->block); | 183 | lua_pushnumber(L, tm->block); |
| 184 | lua_pushnumber(L, tm->total); | 184 | lua_pushnumber(L, tm->total); |
| 185 | return 2; | 185 | return 2; |
| @@ -201,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L) | |||
| 201 | * Sleep for n seconds. | 201 | * Sleep for n seconds. |
| 202 | \*-------------------------------------------------------------------------*/ | 202 | \*-------------------------------------------------------------------------*/ |
| 203 | #ifdef _WIN32 | 203 | #ifdef _WIN32 |
| 204 | LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | 204 | int timeout_lua_sleep(lua_State *L) |
| 205 | { | 205 | { |
| 206 | double n = luaL_checknumber(L, 1); | 206 | double n = luaL_checknumber(L, 1); |
| 207 | if (n < 0.0) n = 0.0; | 207 | if (n < 0.0) n = 0.0; |
| @@ -211,7 +211,7 @@ LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | |||
| 211 | return 0; | 211 | return 0; |
| 212 | } | 212 | } |
| 213 | #else | 213 | #else |
| 214 | LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | 214 | int timeout_lua_sleep(lua_State *L) |
| 215 | { | 215 | { |
| 216 | double n = luaL_checknumber(L, 1); | 216 | double n = luaL_checknumber(L, 1); |
| 217 | struct timespec t, r; | 217 | struct timespec t, r; |
| @@ -228,3 +228,7 @@ LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L) | |||
| 228 | return 0; | 228 | return 0; |
| 229 | } | 229 | } |
| 230 | #endif | 230 | #endif |
| 231 | |||
| 232 | #ifndef _WIN32 | ||
| 233 | #pragma GCC visibility pop | ||
| 234 | #endif | ||
diff --git a/src/timeout.h b/src/timeout.h index af90231..df05eaf 100644 --- a/src/timeout.h +++ b/src/timeout.h | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | * Timeout management functions | 4 | * Timeout management functions |
| 5 | * LuaSocket toolkit | 5 | * LuaSocket toolkit |
| 6 | \*=========================================================================*/ | 6 | \*=========================================================================*/ |
| 7 | #include "lua.h" | 7 | #include "luasocket.h" |
| 8 | 8 | ||
| 9 | /* timeout control structure */ | 9 | /* timeout control structure */ |
| 10 | typedef struct t_timeout_ { | 10 | typedef struct t_timeout_ { |
| @@ -14,16 +14,23 @@ typedef struct t_timeout_ { | |||
| 14 | } t_timeout; | 14 | } t_timeout; |
| 15 | typedef t_timeout *p_timeout; | 15 | typedef t_timeout *p_timeout; |
| 16 | 16 | ||
| 17 | int timeout_open(lua_State *L); | 17 | #pragma GCC visibility push(hidden) |
| 18 | |||
| 18 | void timeout_init(p_timeout tm, double block, double total); | 19 | void timeout_init(p_timeout tm, double block, double total); |
| 19 | double timeout_get(p_timeout tm); | 20 | double timeout_get(p_timeout tm); |
| 21 | double timeout_getstart(p_timeout tm); | ||
| 20 | double timeout_getretry(p_timeout tm); | 22 | double timeout_getretry(p_timeout tm); |
| 21 | p_timeout timeout_markstart(p_timeout tm); | 23 | p_timeout timeout_markstart(p_timeout tm); |
| 22 | double timeout_getstart(p_timeout tm); | 24 | |
| 23 | double timeout_gettime(void); | 25 | double timeout_gettime(void); |
| 26 | |||
| 27 | int timeout_open(lua_State *L); | ||
| 28 | |||
| 24 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); | 29 | int timeout_meth_settimeout(lua_State *L, p_timeout tm); |
| 25 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm); | 30 | int timeout_meth_gettimeout(lua_State *L, p_timeout tm); |
| 26 | 31 | ||
| 32 | #pragma GCC visibility pop | ||
| 33 | |||
| 27 | #define timeout_iszero(tm) ((tm)->block == 0.0) | 34 | #define timeout_iszero(tm) ((tm)->block == 0.0) |
| 28 | 35 | ||
| 29 | #endif /* TIMEOUT_H */ | 36 | #endif /* TIMEOUT_H */ |
