summaryrefslogtreecommitdiffhomepage
path: root/libs/httpd
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-25 16:48:48 +0000
committerSteven Barth <steven@midlink.org>2008-06-25 16:48:48 +0000
commit215e225fe9965be0852f4f4f2f72dca1d0c608f0 (patch)
treec5383596d356a21ba7cd7267e76a246e98926a6c /libs/httpd
parent7a4aa85dd64f72b9edcbf9310d0d95e59960d84e (diff)
* libs/httpd: Automatically remove timed out threads
Diffstat (limited to 'libs/httpd')
-rw-r--r--libs/httpd/luasrc/httpd.lua16
1 files changed, 11 insertions, 5 deletions
diff --git a/libs/httpd/luasrc/httpd.lua b/libs/httpd/luasrc/httpd.lua
index a9b1ccbb4..9eaa9a68d 100644
--- a/libs/httpd/luasrc/httpd.lua
+++ b/libs/httpd/luasrc/httpd.lua
@@ -36,8 +36,8 @@ function Thread.__init__(self, socket, func)
self.waiting = false
end
-function Thread.getidletime(self)
- return os.difftime(os.time(), self.stamp)
+function Thread.touched(self)
+ return self.stamp
end
function Thread.iswaiting(self)
@@ -71,7 +71,7 @@ end
Daemon = luci.util.class()
-function Daemon.__init__(self, threadlimit, timeout)
+function Daemon.__init__(self, threadlimit, waittime, timeout)
self.reading = {}
self.threads = {}
self.handler = {}
@@ -82,7 +82,8 @@ function Daemon.__init__(self, threadlimit, timeout)
self.debug = false
self.threadlimit = threadlimit
- self.timeout = timeout or 0.1
+ self.waittime = waittime or 0.1
+ self.timeout = timeout or 90
end
function Daemon.dprint(self, msg)
@@ -144,6 +145,7 @@ function Daemon.step(self)
-- create client handler
for sock, thread in pairs( self.threads ) do
+ local now = os.time()
-- reap dead clients
if thread:status() == "dead" then
@@ -153,6 +155,10 @@ function Daemon.step(self)
sock:close()
self.threadc = self.threadc - 1
self.threads[sock] = nil
+
+ elseif os.difftime(now, thread:touched()) > self.timeout then
+ self.threads[sock] = nil
+ sock:close()
-- resume working threads
elseif not thread:iswaiting() then
if self.debug then
@@ -199,6 +205,6 @@ function Daemon.step(self)
end
if err == "timeout" and not working then
- socket.sleep(self.timeout)
+ socket.sleep(self.waittime)
end
end