From 25de4549ed9b374fbdd9f885b3dc90dee955331d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Apr 2009 02:54:45 +0100 Subject: net.server: Add server.setquitting() to gracefully quit the socket loop --- net/server.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/server.lua b/net/server.lua index 755b369e..d151e61d 100644 --- a/net/server.lua +++ b/net/server.lua @@ -724,8 +724,16 @@ stats = function( ) return _readtraffic, _sendtraffic, _readlistlen, _sendlistlen, _timerlistlen end +local dontstop = true; + +setquitting = function (quit) + dontstop = not quit; + return; +end + loop = function( ) -- this is the main loop of the program - while true do + while dontstop do + out_put(tostring(dontstop)) local read, write, err = socket_select( _readlist, _sendlist, _selecttimeout ) for i, socket in ipairs( write ) do -- send data waiting in writequeues local handler = _socketlist[ socket ] @@ -760,6 +768,7 @@ loop = function( ) -- this is the main loop of the program socket_sleep( _sleeptime ) -- wait some time --collectgarbage( ) end + return "quitting" end --// EXPERIMENTAL //-- @@ -833,7 +842,7 @@ return { addtimer = addtimer, addserver = addserver, getsettings = getsettings, + setquitting = setquitting, removeserver = removeserver, changesettings = changesettings, - } -- cgit v1.2.3