-function Thread.resume(self, ...)
- return coroutine.resume(self.routine, self, ...)
-end
-
-function Thread.isdead(self)
- return coroutine.status(self.routine) == "dead"
-end
-
-function Thread.touch(self)
- self.stamp = os.time()
-end
-
-Daemon = luci.util.class()
-
-function Daemon.__init__(self, threadlimit, waittime, timeout)
- self.reading = {}
- self.threads = {}
- self.handler = {}
- self.waiting = {}
- self.threadc = 0
-
- setmetatable(self.waiting, {__mode = "v"})
-
- self.debug = false
- self.threadlimit = threadlimit
- self.waittime = waittime or 0.1
- self.timeout = timeout or 90
-end
-
-function Daemon.remove_dead(self, thread)
- if self.debug then
- self:dprint("Completed " .. tostring(thread))
- end
- thread.socket:close()
- self.threadc = self.threadc - 1
- self.threads[thread.socket] = nil
-end
-
-function Daemon.kill_timedout(self)
- local now = os.time()
-
- for sock, thread in pairs(self.threads) do
- if os.difftime(now, thread:touched()) > self.timeout then
- self.threads[sock] = nil
- self.threadc = self.threadc - 1
- sock:close()
- end
- end
+function h(sock)
+ local sink = socket.sink("close-when-done", sock)
+ local f = ltn12.source.file(io.open("/home/steven/workspace/ffluci/host/www/luci-static/openwrt.org/cascade.css"))
+ local s = luci.fs.stat("/home/steven/workspace/ffluci/host/www/luci-static/openwrt.org/cascade.css", "size")
+ sink("HTTP/1.1 200 OK\r\nContent-Length: " ..s.."\r\nConnection: close\r\n\r\n")
+ repeat
+ coroutine.yield()
+ eof = not ltn12.pump.step(f, sink)
+ until eof