# HG changeset patch # User Matthew Wild # Date 1239501285 -3600 # Node ID ec239c044f31b8b5a889909d8edaf8a8c938aa93 # Parent 8cb9a0d59e782ccdfff3ae9584ae7be616717717 net.server: Add server.setquitting() to gracefully quit the socket loop diff -r 8cb9a0d59e78 -r ec239c044f31 net/server.lua --- a/net/server.lua Sun Apr 12 02:53:50 2009 +0100 +++ b/net/server.lua Sun Apr 12 02:54:45 2009 +0100 @@ -724,8 +724,16 @@ 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 @@ socket_sleep( _sleeptime ) -- wait some time --collectgarbage( ) end + return "quitting" end --// EXPERIMENTAL //-- @@ -833,7 +842,7 @@ addtimer = addtimer, addserver = addserver, getsettings = getsettings, + setquitting = setquitting, removeserver = removeserver, changesettings = changesettings, - }