Fix. Returns nil from write callback treat as write error.

This commit is contained in:
Alexey Melnichuk 2014-09-04 18:11:03 +05:00
parent 3d34167f92
commit 8f4a0980ca
2 changed files with 41 additions and 4 deletions

View File

@ -625,7 +625,10 @@ static size_t lcurl_write_callback_(lua_State*L,
} }
if(lua_gettop(L) > top){ if(lua_gettop(L) > top){
if(lua_isnil(L, top + 1)) return 0; if(lua_isnil(L, top + 1)){
if(lua_gettop(L) == (top+1)) lua_settop(L, top);
return 0;
}
if(lua_isnumber(L, top + 1)){ if(lua_isnumber(L, top + 1)){
ret = (size_t)lua_tonumber(L, top + 1); ret = (size_t)lua_tonumber(L, top + 1);
} }

View File

@ -38,8 +38,7 @@ function test_write_to_file()
assert_equal(c, c:perform()) assert_equal(c, c:perform())
end end
function test_write_to_file_abort() function test_write_to_file_abort_01()
f = assert(io.open(fname, "w+b"))
c = assert(scurl.easy{ c = assert(scurl.easy{
url = url; url = url;
writefunction = function(str) writefunction = function(str)
@ -48,8 +47,43 @@ function test_write_to_file_abort()
}) })
local _, e = assert_nil(c:perform()) local _, e = assert_nil(c:perform())
assert_equal(e, curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR)) assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e)
end
function test_write_to_file_abort_02()
c = assert(scurl.easy{
url = url;
writefunction = function(str)
return false
end;
})
local _, e = assert_nil(c:perform())
assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e)
end
function test_write_to_file_abort_03()
c = assert(scurl.easy{
url = url;
writefunction = function(str)
return nil, "WRITEERROR"
end;
})
local _, e = assert_nil(c:perform())
assert_equal("WRITEERROR", e)
end
function test_write_to_file_abort_04()
c = assert(scurl.easy{
url = url;
writefunction = function(str)
return nil
end;
})
local _, e = assert_nil(c:perform())
assert_equal(curl.error(curl.ERROR_EASY, curl.E_WRITE_ERROR), e)
end end
function test_reset_write_callback() function test_reset_write_callback()