aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-11-06 01:08:30 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-11-06 01:08:30 +0500
commit412be2f3dfc56e255b619a1ac8c0fd61e71c3ea8 (patch)
tree60bcaf43bd9211b06aba6b93b4e79b1a0d7f8b43
parent55a44c817e40d01e7cf7194e434d3f169ef7d951 (diff)
downloadprosody-412be2f3dfc56e255b619a1ac8c0fd61e71c3ea8.tar.gz
prosody-412be2f3dfc56e255b619a1ac8c0fd61e71c3ea8.zip
util.httpstream: A little refactoring of the coroutine control flow.
-rw-r--r--util/httpstream.lua8
1 files changed, 5 insertions, 3 deletions
diff --git a/util/httpstream.lua b/util/httpstream.lua
index bef3350c..fac38d81 100644
--- a/util/httpstream.lua
+++ b/util/httpstream.lua
@@ -7,7 +7,8 @@ coroutine.resume(deadroutine);
module("httpstream")
-local function parser(data, success_cb, parser_type)
+local function parser(success_cb, parser_type)
+ local data = coroutine.yield();
local function readline()
local pos = data:find("\r\n", nil, true);
while not pos do
@@ -94,14 +95,15 @@ end
function new(success_cb, error_cb, parser_type)
local co = coroutine.create(parser);
+ coroutine.resume(co, success_cb, parser_type)
return {
feed = function(self, data)
if not data then
- if parser_type == "client" then coroutine.resume(co, "", success_cb, parser_type); end
+ if parser_type == "client" then coroutine.resume(co, ""); end
co = deadroutine;
return error_cb();
end
- local success, result = coroutine.resume(co, data, success_cb, parser_type);
+ local success, result = coroutine.resume(co, data);
if result then
co = deadroutine;
return error_cb(result);