Software /
code /
prosody
Changeset
7573:0f0a6febbc5a
net.server_epoll: Add some comments
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Aug 2016 01:52:18 +0200 |
parents | 7564:f95ffd24e042 |
children | 7574:97b8506118a9 |
files | net/server_epoll.lua |
diffstat | 1 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/net/server_epoll.lua Tue Aug 16 14:53:29 2016 +0200 +++ b/net/server_epoll.lua Thu Aug 18 01:52:18 2016 +0200 @@ -40,17 +40,24 @@ t[2] = noop; end +-- Set to true when timers have changed local resort_timers = false; + +-- Add absolute timer local function at(time, f) local timer = { time, f, close = closetimer }; t_insert(timers, timer); resort_timers = true; return timer; end + +-- Add relative timer local function addtimer(timeout, f) return at(gettime() + timeout, f); end +-- Run callbacks of expired timers +-- Return time until next timeout local function runtimers() if resort_timers then -- Sort earliest timers to the end @@ -76,6 +83,7 @@ local t, f = timer[1], timer[2]; local now = gettime(); -- inside or before the loop? if t > now then + -- This timer should not fire yet local diff = t - now; if diff < next_delay then next_delay = diff; @@ -92,7 +100,7 @@ end if resort_timers or next_delay < 1e-6 then -- Timers may be added from within a timer callback. - -- Those would not be considered for next_dela, + -- Those would not be considered for next_delay, -- and we might sleep for too long, so instead -- we return a shorter timeout so we can -- properly sort all new timers. @@ -222,6 +230,7 @@ return true; end +-- Called when socket is readable function interface:onreadable() local data, err, partial = self.conn:receive(self._pattern); if data or partial then @@ -242,6 +251,7 @@ end end +-- Called when socket is writable function interface:onwriteable() local buffer = self.writebuffer; local data = t_concat(buffer);