net.server_epoll: Add some comments
authorKim Alvefur <zash@zash.se>
Thu, 18 Aug 2016 01:52:18 +0200
changeset 7576 0f0a6febbc5a
parent 7567 f95ffd24e042
child 7577 97b8506118a9
net.server_epoll: Add some comments
net/server_epoll.lua
--- 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);