X-Git-Url: http://git.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fhttpd%2Fluasrc%2Fhttpd.lua;h=541063cc7e21cf16c6132076d75e76fb868b3615;hp=8b54f0e645810671793c6e550a33d70d5ea4efa3;hb=f0a0e503783d6571c1a0a90bf14e7531b2f2a176;hpb=50039c134e104632a7dfe10c9d39cf121aff9a0b diff --git a/libs/httpd/luasrc/httpd.lua b/libs/httpd/luasrc/httpd.lua index 8b54f0e645..541063cc7e 100644 --- a/libs/httpd/luasrc/httpd.lua +++ b/libs/httpd/luasrc/httpd.lua @@ -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 ) @@ -87,7 +92,6 @@ end function step() local idle = true - if not THREAD_LIMIT or threadc < THREAD_LIMIT then local now = os.time() for i, server in ipairs(reading) do @@ -104,8 +108,8 @@ function step() coroutine.resume(thread, client) local now = os.time() if coroutine.status(thread) == "dead" then - threads[client] = nil threadc = threadc - 1 + threads[client] = nil elseif threadm[client] and threadm[client] + THREAD_TIMEOUT < now then threads[client] = nil threadc = threadc - 1 @@ -117,6 +121,7 @@ function step() end if idle then + collectgarbage() socket.sleep(THREAD_IDLEWAIT) end -end \ No newline at end of file +end