Change. Returns nothing form reader callback means EOF.
Change. multi:iperform() remove easy handle when it done.
This commit is contained in:
parent
e6c2ffce5c
commit
aff3042434
@ -303,13 +303,22 @@ function setopt_headerfunction() end
|
||||
-- A callback accepting one or two parameters.
|
||||
-- The first is the reader context if any, and the second is the maximum amount of data to be read.
|
||||
-- You can ignore second argument and pass as mach data as you need. lcurl can split data.
|
||||
-- Function must return data to continue operation. To stop operation it must return empty string on nil.
|
||||
-- Function must return data to continue operation. To stop operation it must return empty string or nil or nothing.
|
||||
-- Otherwise the transfer will be aborted with an error.
|
||||
--
|
||||
--
|
||||
-- @tparam function reader
|
||||
-- @param[opt] context reader context
|
||||
-- @return[1] self
|
||||
--
|
||||
-- @usage
|
||||
-- local counter = 10
|
||||
-- c:setopt_readfunction(function()
|
||||
-- if counter > 0 then
|
||||
-- counter = counter - 1
|
||||
-- return 'a'
|
||||
-- end
|
||||
-- end)
|
||||
function setopt_readfunction() end
|
||||
|
||||
--- Set reader function.
|
||||
|
@ -714,7 +714,7 @@ static size_t lcurl_read_callback(lua_State *L,
|
||||
}
|
||||
|
||||
if(lua_gettop(L) == top){
|
||||
return CURL_READFUNC_ABORT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(lua_gettop(L) >= top);
|
||||
|
@ -93,6 +93,7 @@ local function make_iterator(self, perform)
|
||||
ok = e:getinfo_response_code() or ok
|
||||
buffers:append(e, "done", ok)
|
||||
else buffers:append(e, "error", err) end
|
||||
self:remove_handle(e)
|
||||
end
|
||||
remain = n
|
||||
end
|
||||
|
@ -514,10 +514,10 @@ function teardown()
|
||||
end
|
||||
|
||||
function test_abort_01()
|
||||
assert_equal(c, c:setopt_readfunction(function() end))
|
||||
|
||||
local _, e = assert_nil(c:perform())
|
||||
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
|
||||
-- assert_equal(c, c:setopt_readfunction(function() end))
|
||||
--
|
||||
-- local _, e = assert_nil(c:perform())
|
||||
-- assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
|
||||
end
|
||||
|
||||
function test_abort_02()
|
||||
@ -611,6 +611,7 @@ function test_readbuffer()
|
||||
end
|
||||
|
||||
function test_pass_01()
|
||||
-- We need this to support file:read() method which returns nil as EOF
|
||||
assert_equal(c, c:setopt_readfunction(function() return nil end))
|
||||
|
||||
assert_equal(c, c:perform())
|
||||
@ -619,6 +620,21 @@ function test_pass_01()
|
||||
assert_equal(0, #data)
|
||||
end
|
||||
|
||||
function test_pass_02()
|
||||
local counter = 10
|
||||
assert_equal(c, c:setopt_readfunction(function()
|
||||
if counter > 0 then
|
||||
counter = counter - 1
|
||||
return 'a'
|
||||
end
|
||||
end))
|
||||
|
||||
assert_equal(c, c:perform())
|
||||
c:close()
|
||||
local data = read_file(fname)
|
||||
assert_equal(('a'):rep(10), data)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local _ENV = TEST_CASE'escape' if ENABLE then
|
||||
|
Loading…
x
Reference in New Issue
Block a user