summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-06-29 14:56:33 +0000
committerSteven Barth <steven@midlink.org>2008-06-29 14:56:33 +0000
commit62c61045d8fe1b9458f608264ab392a2f43badf9 (patch)
treebe50bf2912717e9f4641466d3d95b55e30a32dbc
parentb8240f3516945b5969bfcfeb1fcc057759f5dd4b (diff)
* luci/httpd: Handle timeouts on socket writes correctly
-rw-r--r--libs/httpd/luasrc/httpd.lua18
-rw-r--r--libs/httpd/luasrc/httpd/server.lua5
2 files changed, 21 insertions, 2 deletions
diff --git a/libs/httpd/luasrc/httpd.lua b/libs/httpd/luasrc/httpd.lua
index 201ece616..196101950 100644
--- a/libs/httpd/luasrc/httpd.lua
+++ b/libs/httpd/luasrc/httpd.lua
@@ -55,6 +55,24 @@ function corecv(socket, ...)
end
end
+function cosend(socket, chunk, i, ...)
+ threadi[socket] = true
+ i = i or 1
+
+ while true do
+ local stat, err, sent = socket:send(chunk, i, ...)
+
+ if err ~= "timeout" then
+ threadi[socket] = false
+ return stat, err, sent
+ else
+ i = sent and (sent + 1) or 1
+ end
+
+ coroutine.yield()
+ end
+end
+
function register(socket, s_clhandler, s_errhandler)
table.insert(reading, socket)
clhandler[socket] = s_clhandler
diff --git a/libs/httpd/luasrc/httpd/server.lua b/libs/httpd/luasrc/httpd/server.lua
index 7bfac6862..9ec8961b8 100644
--- a/libs/httpd/luasrc/httpd/server.lua
+++ b/libs/httpd/luasrc/httpd/server.lua
@@ -111,7 +111,8 @@ function Server.process( self, client )
-- Setup sockets and sources
local thread = {
- receive = function(self, ...) return luci.httpd.corecv(client, ...) end
+ receive = function(self, ...) return luci.httpd.corecv(client, ...) end,
+ send = function(self, ...) return luci.httpd.cosend(client, ...) end
}
client:settimeout( 0 )
@@ -206,7 +207,7 @@ function Server.process( self, client )
end
- local sinkout = socket.sink(sinkmode, client)
+ local sinkout = socket.sink(sinkmode, thread)
local header =
message.env.SERVER_PROTOCOL .. " " ..