* libs/httpd: Added performance ;-)
This commit is contained in:
parent
d5deb7a99a
commit
02cce96c83
2 changed files with 41 additions and 27 deletions
|
@ -27,6 +27,6 @@ io.stderr:write("Starting LuCI HTTPD on port " .. PORT .. "...\n")
|
||||||
io.stderr:write("Point your browser to http://localhost:" .. PORT .. "/luci\n")
|
io.stderr:write("Point your browser to http://localhost:" .. PORT .. "/luci\n")
|
||||||
|
|
||||||
daemon = luci.httpd.Daemon()
|
daemon = luci.httpd.Daemon()
|
||||||
daemon.debug = true
|
--daemon.debug = true
|
||||||
daemon:register(serversocket, server:create_daemon_handlers())
|
daemon:register(serversocket, server:create_daemon_handlers())
|
||||||
daemon:run()
|
daemon:run()
|
||||||
|
|
|
@ -67,28 +67,36 @@ function Daemon.step(self)
|
||||||
for i, connection in ipairs(input) do
|
for i, connection in ipairs(input) do
|
||||||
|
|
||||||
local sock = connection:accept()
|
local sock = connection:accept()
|
||||||
|
|
||||||
-- check capacity
|
if sock then
|
||||||
if not self.threadlimit or #self.running < self.threadlimit then
|
-- check capacity
|
||||||
|
if not self.threadlimit or #self.running < self.threadlimit then
|
||||||
self:dprint("Accepted incoming connection from " .. sock:getpeername())
|
|
||||||
|
if self.debug then
|
||||||
table.insert( self.running, {
|
self:dprint("Accepted incoming connection from " .. sock:getpeername())
|
||||||
coroutine.create( self.handler[connection].clhandler ),
|
end
|
||||||
sock
|
|
||||||
} )
|
table.insert( self.running, {
|
||||||
|
coroutine.create( self.handler[connection].clhandler ),
|
||||||
self:dprint("Created " .. tostring(self.running[#self.running][1]))
|
sock
|
||||||
|
} )
|
||||||
-- reject client
|
|
||||||
else
|
if self.debug then
|
||||||
self:dprint("Rejected incoming connection from " .. sock:getpeername())
|
self:dprint("Created " .. tostring(self.running[#self.running][1]))
|
||||||
|
end
|
||||||
if self.handler[connection].errhandler then
|
|
||||||
self.handler[connection].errhandler( sock )
|
-- reject client
|
||||||
|
else
|
||||||
|
if self.debug then
|
||||||
|
self:dprint("Rejected incoming connection from " .. sock:getpeername())
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.handler[connection].errhandler then
|
||||||
|
self.handler[connection].errhandler( sock )
|
||||||
|
end
|
||||||
|
|
||||||
|
sock:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
sock:close()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,16 +105,22 @@ function Daemon.step(self)
|
||||||
|
|
||||||
-- reap dead clients
|
-- reap dead clients
|
||||||
if coroutine.status( client[1] ) == "dead" then
|
if coroutine.status( client[1] ) == "dead" then
|
||||||
self:dprint("Completed " .. tostring(client[1]))
|
if self.debug then
|
||||||
|
self:dprint("Completed " .. tostring(client[1]))
|
||||||
|
end
|
||||||
table.remove( self.running, i )
|
table.remove( self.running, i )
|
||||||
else
|
else
|
||||||
self:dprint("Resuming " .. tostring(client[1]))
|
if self.debug then
|
||||||
|
self:dprint("Resuming " .. tostring(client[1]))
|
||||||
|
end
|
||||||
|
|
||||||
local stat, err = coroutine.resume( client[1], client[2] )
|
local stat, err = coroutine.resume( client[1], client[2] )
|
||||||
|
|
||||||
|
if self.debug then
|
||||||
|
self:dprint(tostring(client[1]) .. " returned")
|
||||||
|
end
|
||||||
|
|
||||||
self:dprint(tostring(client[1]) .. " returned")
|
if not stat and self.debug then
|
||||||
|
|
||||||
if not stat then
|
|
||||||
self:dprint("Error in " .. tostring(client[1]) .. " " .. err)
|
self:dprint("Error in " .. tostring(client[1]) .. " " .. err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue