Avoid some blocking issues
[project/luci.git] / libs / sgi-cgi / luasrc / sgi / cgi.lua
index 7f54e70..f78adea 100644 (file)
@@ -24,7 +24,7 @@ limitations under the License.
 
 ]]--
 module("luci.sgi.cgi", package.seeall)
-require("ltn12")
+local ltn12 = require("luci.ltn12")
 require("luci.http")
 require("luci.sys")
 require("luci.dispatcher")
@@ -37,6 +37,8 @@ function run()
        )
        
        local x = coroutine.create(luci.dispatcher.httpdispatch)
+       local hcache = ""
+       local active = true
        
        while coroutine.status(x) ~= "dead" do
                local res, id, data1, data2 = coroutine.resume(x, r)
@@ -48,15 +50,20 @@ function run()
                        break;
                end
 
-               if id == 1 then
-                       io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\r\n")
-               elseif id == 2 then
-                       io.write(data1 .. ": " .. data2 .. "\r\n")
-               elseif id == 3 then
-                       io.write("\r\n")
-               elseif id == 4 then
-                       io.write(data1)
+               if active then
+                       if id == 1 then
+                               io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\r\n")
+                       elseif id == 2 then
+                               hcache = hcache .. data1 .. ": " .. data2 .. "\r\n"
+                       elseif id == 3 then
+                               io.write(hcache)
+                               io.write("\r\n")
+                       elseif id == 4 then
+                               io.write(data1)
+                       elseif id == 5 then
+                               io.close()
+                               active = false
+                       end
                end
-               
        end
 end