aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorE. Westbrook <github@westbrook.io>2019-02-25 16:01:04 -0700
committerE. Westbrook <github@westbrook.io>2019-02-25 16:01:04 -0700
commit87c2dee13e05d5474e2acde7f5dca29edd589335 (patch)
tree34804c01be6c540780302c6941933c308b923bf7 /src
parent525d703e16c1f557b95f742f7d2681ad6815f92f (diff)
downloadluasocket-87c2dee13e05d5474e2acde7f5dca29edd589335.tar.gz
luasocket-87c2dee13e05d5474e2acde7f5dca29edd589335.tar.bz2
luasocket-87c2dee13e05d5474e2acde7f5dca29edd589335.zip
timeout.c: use LUASOCKET_PRIVATE
Diffstat (limited to 'src')
-rw-r--r--src/timeout.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/timeout.c b/src/timeout.c
index 5a601d5..8fb8f55 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -2,9 +2,7 @@
2* Timeout management functions 2* Timeout management functions
3* LuaSocket toolkit 3* LuaSocket toolkit
4\*=========================================================================*/ 4\*=========================================================================*/
5#include <stdio.h> 5#include "luasocket.h"
6#include <limits.h>
7#include <float.h>
8 6
9#include "lua.h" 7#include "lua.h"
10#include "lauxlib.h" 8#include "lauxlib.h"
@@ -13,6 +11,10 @@
13#include "auxiliar.h" 11#include "auxiliar.h"
14#include "timeout.h" 12#include "timeout.h"
15 13
14#include <stdio.h>
15#include <limits.h>
16#include <float.h>
17
16#ifdef _WIN32 18#ifdef _WIN32
17#include <windows.h> 19#include <windows.h>
18#else 20#else
@@ -46,7 +48,7 @@ static luaL_Reg func[] = {
46/*-------------------------------------------------------------------------*\ 48/*-------------------------------------------------------------------------*\
47* Initialize structure 49* Initialize structure
48\*-------------------------------------------------------------------------*/ 50\*-------------------------------------------------------------------------*/
49void timeout_init(p_timeout tm, double block, double total) { 51LUASOCKET_PRIVATE void timeout_init(p_timeout tm, double block, double total) {
50 tm->block = block; 52 tm->block = block;
51 tm->total = total; 53 tm->total = total;
52} 54}
@@ -59,7 +61,7 @@ void timeout_init(p_timeout tm, double block, double total) {
59* Returns 61* Returns
60* 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
61\*-------------------------------------------------------------------------*/ 63\*-------------------------------------------------------------------------*/
62double timeout_get(p_timeout tm) { 64LUASOCKET_PRIVATE double timeout_get(p_timeout tm) {
63 if (tm->block < 0.0 && tm->total < 0.0) { 65 if (tm->block < 0.0 && tm->total < 0.0) {
64 return -1; 66 return -1;
65 } else if (tm->block < 0.0) { 67 } else if (tm->block < 0.0) {
@@ -80,7 +82,7 @@ double timeout_get(p_timeout tm) {
80* Returns 82* Returns
81* start field of structure 83* start field of structure
82\*-------------------------------------------------------------------------*/ 84\*-------------------------------------------------------------------------*/
83double timeout_getstart(p_timeout tm) { 85LUASOCKET_PRIVATE double timeout_getstart(p_timeout tm) {
84 return tm->start; 86 return tm->start;
85} 87}
86 88
@@ -92,7 +94,7 @@ double timeout_getstart(p_timeout tm) {
92* Returns 94* Returns
93* 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
94\*-------------------------------------------------------------------------*/ 96\*-------------------------------------------------------------------------*/
95double timeout_getretry(p_timeout tm) { 97LUASOCKET_PRIVATE double timeout_getretry(p_timeout tm) {
96 if (tm->block < 0.0 && tm->total < 0.0) { 98 if (tm->block < 0.0 && tm->total < 0.0) {
97 return -1; 99 return -1;
98 } else if (tm->block < 0.0) { 100 } else if (tm->block < 0.0) {
@@ -112,7 +114,7 @@ double timeout_getretry(p_timeout tm) {
112* Input 114* Input
113* tm: timeout control structure 115* tm: timeout control structure
114\*-------------------------------------------------------------------------*/ 116\*-------------------------------------------------------------------------*/
115p_timeout timeout_markstart(p_timeout tm) { 117LUASOCKET_PRIVATE p_timeout timeout_markstart(p_timeout tm) {
116 tm->start = timeout_gettime(); 118 tm->start = timeout_gettime();
117 return tm; 119 return tm;
118} 120}
@@ -123,7 +125,7 @@ p_timeout timeout_markstart(p_timeout tm) {
123* time in s. 125* time in s.
124\*-------------------------------------------------------------------------*/ 126\*-------------------------------------------------------------------------*/
125#ifdef _WIN32 127#ifdef _WIN32
126double timeout_gettime(void) { 128LUASOCKET_PRIVATE double timeout_gettime(void) {
127 FILETIME ft; 129 FILETIME ft;
128 double t; 130 double t;
129 GetSystemTimeAsFileTime(&ft); 131 GetSystemTimeAsFileTime(&ft);
@@ -133,7 +135,7 @@ double timeout_gettime(void) {
133 return (t - 11644473600.0); 135 return (t - 11644473600.0);
134} 136}
135#else 137#else
136double timeout_gettime(void) { 138LUASOCKET_PRIVATE double timeout_gettime(void) {
137 struct timeval v; 139 struct timeval v;
138 gettimeofday(&v, (struct timezone *) NULL); 140 gettimeofday(&v, (struct timezone *) NULL);
139 /* Unix Epoch time (time since January 1, 1970 (UTC)) */ 141 /* Unix Epoch time (time since January 1, 1970 (UTC)) */
@@ -144,7 +146,7 @@ double timeout_gettime(void) {
144/*-------------------------------------------------------------------------*\ 146/*-------------------------------------------------------------------------*\
145* Initializes module 147* Initializes module
146\*-------------------------------------------------------------------------*/ 148\*-------------------------------------------------------------------------*/
147int timeout_open(lua_State *L) { 149LUASOCKET_PRIVATE int timeout_open(lua_State *L) {
148 luaL_setfuncs(L, func, 0); 150 luaL_setfuncs(L, func, 0);
149 return 0; 151 return 0;
150} 152}
@@ -155,7 +157,7 @@ int timeout_open(lua_State *L) {
155* time: time out value in seconds 157* time: time out value in seconds
156* mode: "b" for block timeout, "t" for total timeout. (default: b) 158* mode: "b" for block timeout, "t" for total timeout. (default: b)
157\*-------------------------------------------------------------------------*/ 159\*-------------------------------------------------------------------------*/
158int timeout_meth_settimeout(lua_State *L, p_timeout tm) { 160LUASOCKET_PRIVATE int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
159 double t = luaL_optnumber(L, 2, -1); 161 double t = luaL_optnumber(L, 2, -1);
160 const char *mode = luaL_optstring(L, 3, "b"); 162 const char *mode = luaL_optstring(L, 3, "b");
161 switch (*mode) { 163 switch (*mode) {
@@ -177,7 +179,7 @@ int timeout_meth_settimeout(lua_State *L, p_timeout tm) {
177* Gets timeout values for IO operations 179* Gets timeout values for IO operations
178* Lua Output: block, total 180* Lua Output: block, total
179\*-------------------------------------------------------------------------*/ 181\*-------------------------------------------------------------------------*/
180int timeout_meth_gettimeout(lua_State *L, p_timeout tm) { 182LUASOCKET_PRIVATE int timeout_meth_gettimeout(lua_State *L, p_timeout tm) {
181 lua_pushnumber(L, tm->block); 183 lua_pushnumber(L, tm->block);
182 lua_pushnumber(L, tm->total); 184 lua_pushnumber(L, tm->total);
183 return 2; 185 return 2;
@@ -199,7 +201,7 @@ static int timeout_lua_gettime(lua_State *L)
199* Sleep for n seconds. 201* Sleep for n seconds.
200\*-------------------------------------------------------------------------*/ 202\*-------------------------------------------------------------------------*/
201#ifdef _WIN32 203#ifdef _WIN32
202int timeout_lua_sleep(lua_State *L) 204LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L)
203{ 205{
204 double n = luaL_checknumber(L, 1); 206 double n = luaL_checknumber(L, 1);
205 if (n < 0.0) n = 0.0; 207 if (n < 0.0) n = 0.0;
@@ -209,7 +211,7 @@ int timeout_lua_sleep(lua_State *L)
209 return 0; 211 return 0;
210} 212}
211#else 213#else
212int timeout_lua_sleep(lua_State *L) 214LUASOCKET_PRIVATE int timeout_lua_sleep(lua_State *L)
213{ 215{
214 double n = luaL_checknumber(L, 1); 216 double n = luaL_checknumber(L, 1);
215 struct timespec t, r; 217 struct timespec t, r;