Diff

net/server.lua @ 989:ec239c044f31

net.server: Add server.setquitting() to gracefully quit the socket loop
author Matthew Wild <mwild1@gmail.com>
date Sun, 12 Apr 2009 02:54:45 +0100
parent 962:872f5d85636e
child 994:8fd4efc3ed96
line wrap: on
line diff
--- 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,
-
 }