aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_select.lua
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2015-01-15 09:03:00 -0500
committerdaurnimator <quae@daurnimator.com>2015-01-15 09:03:00 -0500
commit037dd40bb4814f85e4bdfe40d51786350a7742ee (patch)
treeecf5bd4809a99cd7469e15c7721fe6a2af8cbe81 /net/server_select.lua
parent700bd13b7735b21f4e303637e2211c5d4450a510 (diff)
downloadprosody-037dd40bb4814f85e4bdfe40d51786350a7742ee.tar.gz
prosody-037dd40bb4814f85e4bdfe40d51786350a7742ee.zip
net.server_select: Fix timers not being fired until another timer fixes (or 1 second passes)
Diffstat (limited to 'net/server_select.lua')
-rw-r--r--net/server_select.lua24
1 files changed, 8 insertions, 16 deletions
diff --git a/net/server_select.lua b/net/server_select.lua
index d8404001..6d98ccac 100644
--- a/net/server_select.lua
+++ b/net/server_select.lua
@@ -115,8 +115,6 @@ local _checkinterval
local _sendtimeout
local _readtimeout
-local _timer
-
local _maxselectlen
local _maxfd
@@ -890,8 +888,15 @@ end
loop = function(once) -- this is the main loop of the program
if quitting then return "quitting"; end
if once then quitting = "once"; end
- local next_timer_time = math_huge;
+ _currenttime = luasocket_gettime( )
repeat
+ -- Fire timers
+ local next_timer_time = math_huge;
+ for i = 1, _timerlistlen do
+ local t = _timerlist[ i ]( _currenttime ) -- fire timers
+ if t then next_timer_time = math_min(next_timer_time, t); end
+ end
+
local read, write, err = socket_select( _readlist, _sendlist, math_min(_selecttimeout, next_timer_time) )
for i, socket in ipairs( write ) do -- send data waiting in writequeues
local handler = _socketlist[ socket ]
@@ -940,18 +945,6 @@ loop = function(once) -- this is the main loop of the program
end
end
- -- Fire timers
- if _currenttime - _timer >= math_min(next_timer_time, 1) then
- next_timer_time = math_huge;
- for i = 1, _timerlistlen do
- local t = _timerlist[ i ]( _currenttime ) -- fire timers
- if t then next_timer_time = math_min(next_timer_time, t); end
- end
- _timer = _currenttime
- else
- next_timer_time = next_timer_time - (_currenttime - _timer);
- end
-
-- wait some time (0 by default)
socket_sleep( _sleeptime )
until quitting;
@@ -1037,7 +1030,6 @@ use "setmetatable" ( _socketlist, { __mode = "k" } )
use "setmetatable" ( _readtimes, { __mode = "k" } )
use "setmetatable" ( _writetimes, { __mode = "k" } )
-_timer = luasocket_gettime( )
_starttime = luasocket_gettime( )
local function setlogger(new_logger)