Changeset

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
parents 988:8cb9a0d59e78
children 990:235abebc896e
files net/server.lua
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
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,
-
 }