Fix. Return nil from read callback means EOF.

This commit is contained in:
Alexey Melnichuk 2014-09-08 10:45:52 +05:00
parent c79e255662
commit f2ab8ee8a6
2 changed files with 38 additions and 1 deletions

View File

@ -711,7 +711,10 @@ static size_t lcurl_read_callback(lua_State *L,
if(lua_type(L, top + 1) != LUA_TSTRING){
if(lua_isnil(L, top + 1)){
if(lua_gettop(L) == (top+1)) lua_settop(L, top);
if(lua_gettop(L) == (top+1)){// only nil -> EOF
lua_settop(L, top);
return 0;
}
}
else{
if(lua_type(L, top + 1) == LUA_TNUMBER){

View File

@ -382,6 +382,7 @@ function setup()
f = assert(scurl.form())
c = assert(scurl.easy{
url = url,
timeout = 60,
})
assert_equal(c, c:setopt_writefunction(table.insert, t))
end
@ -441,6 +442,23 @@ function test_abort_05()
assert_error_match("READERROR", function() c:perform() end)
end
function test_abort_06()
assert_equal(f, f:add_stream('SSSSS', 128, function() return false end))
assert_equal(c, c:setopt_httppost(f))
local _, e = assert_nil(c:perform())
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
end
function test_pass_01()
assert_equal(c, c:setopt_timeout(10))
assert_equal(f, f:add_stream('SSSSS', 128, function() return nil end))
assert_equal(c, c:setopt_httppost(f))
local _, e = assert_nil(c:perform())
assert_equal(curl.error(curl.ERROR_EASY, curl.E_OPERATION_TIMEDOUT), e)
end
function test_pause()
local counter = 0
assert_equal(f, f:add_stream('SSSSS', 128, function()
@ -529,6 +547,13 @@ function test_abort_05()
assert_error_match("READERROR", function() c:perform() end)
end
function test_abort_06()
assert_equal(c, c:setopt_readfunction(function() return false end))
local _, e = assert_nil(c:perform())
assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
end
function test_pause()
local counter = 0
assert_equal(c, c:setopt_readfunction(function()
@ -576,6 +601,15 @@ function test_readbuffer()
assert_equal(("s"):rep(N), data)
end
function test_pass_01()
assert_equal(c, c:setopt_readfunction(function() return nil end))
assert_equal(c, c:perform())
c:close()
local data = read_file(fname)
assert_equal(0, #data)
end
end
local _ENV = TEST_CASE'escape' if ENABLE then