* libs/httpd: Fixed garbage collection
[project/luci.git] / libs / httpd / luasrc / httpd.lua
index 9263dcc6d8e59cd7f74fae7bc511ed1029e0b39c..541063cc7e21cf16c6132076d75e76fb868b3615 100644 (file)
@@ -30,6 +30,11 @@ local threads = {}
 local threadm = {}
 local threadi = {}
 
+local _meta = {__mode = "k"}
+setmetatable(threadm, _meta)
+setmetatable(threadi, _meta)
+
+
 function Socket(ip, port)
        local sock, err = socket.bind( ip, port )
 
@@ -103,10 +108,8 @@ function step()
                coroutine.resume(thread, client)
                local now = os.time()
                if coroutine.status(thread) == "dead" then
-                       threads[client] = nil
                        threadc = threadc - 1
-                       threadm[client] = nil
-                       threadi[client] = nil
+                       threads[client] = nil
                elseif threadm[client] and threadm[client] + THREAD_TIMEOUT < now then
                        threads[client] = nil
                        threadc = threadc - 1   
@@ -118,6 +121,7 @@ function step()
        end
        
        if idle then
+               collectgarbage()
                socket.sleep(THREAD_IDLEWAIT)
        end
 end