net.server, net.timer, net.server_select: Rearrange dependencies between these three modules. server.addtimer() is no longer a public function (renamed to _addtimer) and is not available at all from server_event (compat code removed to prevent traceback) (thanks Nulani)

2012-05-03

author
Matthew Wild <mwild1@gmail.com>
date
Thu May 03 16:48:34 2012 +0100
changeset 4808
07d0a3a75c8a
parent 4807
2999f0fd1347
child 4810
3bf0100d7303

net.server, net.timer, net.server_select: Rearrange dependencies between these three modules. server.addtimer() is no longer a public function (renamed to _addtimer) and is not available at all from server_event (compat code removed to prevent traceback) (thanks Nulani)

net/server.lua file | annotate | diff | revisions
net/server_select.lua file | annotate | diff | revisions
util/timer.lua file | annotate | diff | revisions
     1.1 --- a/net/server.lua	Wed May 02 18:21:47 2012 +0100
     1.2 +++ b/net/server.lua	Thu May 03 16:48:34 2012 +0100
     1.3 @@ -18,19 +18,8 @@
     1.4  local server;
     1.5  
     1.6  if use_luaevent then
     1.7 -	server = require "net.server_event";
     1.8 -	-- util.timer requires "net.server", so instead of having
     1.9 -	-- Lua look for, and load us again (causing a loop) - set this here
    1.10 -	-- (usually it isn't set until we return, look down there...)
    1.11 -	package.loaded["net.server"] = server;
    1.12 -	
    1.13 -	-- Backwards compatibility for timers, addtimer
    1.14 -	-- called a function roughly every second
    1.15 -	local add_task = require "util.timer".add_task;
    1.16 -	function server.addtimer(f)
    1.17 -		return add_task(1, function (...) f(...); return 1; end);
    1.18 -	end
    1.19 -	
    1.20 +	server = require "net.server_select";
    1.21 +
    1.22  	-- Overwrite signal.signal() because we need to ask libevent to
    1.23  	-- handle them instead
    1.24  	local ok, signal = pcall(require, "util.signal");
    1.25 @@ -48,7 +37,6 @@
    1.26  	end
    1.27  else
    1.28  	server = require "net.server_select";
    1.29 -	package.loaded["net.server"] = server;
    1.30  end
    1.31  
    1.32  -- require "net.server" shall now forever return this,
     2.1 --- a/net/server_select.lua	Wed May 02 18:21:47 2012 +0100
     2.2 +++ b/net/server_select.lua	Thu May 03 16:48:34 2012 +0100
     2.3 @@ -75,7 +75,6 @@
     2.4  local loop
     2.5  local stats
     2.6  local idfalse
     2.7 -local addtimer
     2.8  local closeall
     2.9  local addsocket
    2.10  local addserver
    2.11 @@ -921,6 +920,7 @@
    2.12  ----------------------------------// PUBLIC INTERFACE //--
    2.13  
    2.14  return {
    2.15 +	_addtimer = addtimer,
    2.16  
    2.17  	addclient = addclient,
    2.18  	wrapclient = wrapclient,
    2.19 @@ -930,7 +930,6 @@
    2.20  	step = step,
    2.21  	stats = stats,
    2.22  	closeall = closeall,
    2.23 -	addtimer = addtimer,
    2.24  	addserver = addserver,
    2.25  	getserver = getserver,
    2.26  	setlogger = setlogger,
     3.1 --- a/util/timer.lua	Wed May 02 18:21:47 2012 +0100
     3.2 +++ b/util/timer.lua	Thu May 03 16:48:34 2012 +0100
     3.3 @@ -6,11 +6,7 @@
     3.4  -- COPYING file in the source package for more information.
     3.5  --
     3.6  
     3.7 -
     3.8 -local ns_addtimer = require "net.server".addtimer;
     3.9 -local event = require "net.server".event;
    3.10 -local event_base = require "net.server".event_base;
    3.11 -
    3.12 +local server = require "net.server";
    3.13  local math_min = math.min
    3.14  local math_huge = math.huge
    3.15  local get_time = require "socket".gettime;
    3.16 @@ -24,7 +20,7 @@
    3.17  module "timer"
    3.18  
    3.19  local _add_task;
    3.20 -if not event then
    3.21 +if not server.event then
    3.22  	function _add_task(delay, callback)
    3.23  		local current_time = get_time();
    3.24  		delay = delay + current_time;
    3.25 @@ -38,7 +34,7 @@
    3.26  		end
    3.27  	end
    3.28  
    3.29 -	ns_addtimer(function()
    3.30 +	server._addtimer(function()
    3.31  		local current_time = get_time();
    3.32  		if #new_data > 0 then
    3.33  			for _, d in pairs(new_data) do
    3.34 @@ -64,7 +60,10 @@
    3.35  		return next_time;
    3.36  	end);
    3.37  else
    3.38 +	local event = require "net.server".event;
    3.39 +	local event_base = require "net.server".event_base;
    3.40  	local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1;
    3.41 +
    3.42  	function _add_task(delay, callback)
    3.43  		local event_handle;
    3.44  		event_handle = event_base:addevent(nil, 0, function ()

mercurial