diff --git a/src/lceasy.c b/src/lceasy.c index af6bcfe..6019731 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -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){ diff --git a/test/test_easy.lua b/test/test_easy.lua index 09a2988..964b80a 100644 --- a/test/test_easy.lua +++ b/test/test_easy.lua @@ -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