File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -303,13 +303,22 @@ function setopt_headerfunction() end
303303-- A callback accepting one or two parameters.
304304-- The first is the reader context if any, and the second is the maximum amount of data to be read.
305305-- You can ignore second argument and pass as mach data as you need. lcurl can split data.
306- -- Function must return data to continue operation. To stop operation it must return empty string on nil.
306+ -- Function must return data to continue operation. To stop operation it must return empty string or nil or nothing .
307307-- Otherwise the transfer will be aborted with an error.
308+ --
308309--
309310-- @tparam function reader
310311-- @param[opt] context reader context
311312-- @return[1] self
312313--
314+ -- @usage
315+ -- local counter = 10
316+ -- c:setopt_readfunction(function()
317+ -- if counter > 0 then
318+ -- counter = counter - 1
319+ -- return 'a'
320+ -- end
321+ -- end)
313322function setopt_readfunction() end
314323
315324--- Set reader function.
Original file line number Diff line number Diff line change @@ -714,7 +714,7 @@ static size_t lcurl_read_callback(lua_State *L,
714714 }
715715
716716 if (lua_gettop (L ) == top ){
717- return CURL_READFUNC_ABORT ;
717+ return 0 ;
718718 }
719719
720720 assert (lua_gettop (L ) >= top );
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ local function make_iterator(self, perform)
9393 ok = e :getinfo_response_code () or ok
9494 buffers :append (e , " done" , ok )
9595 else buffers :append (e , " error" , err ) end
96+ self :remove_handle (e )
9697 end
9798 remain = n
9899 end
Original file line number Diff line number Diff line change @@ -514,10 +514,10 @@ function teardown()
514514end
515515
516516function test_abort_01 ()
517- assert_equal (c , c :setopt_readfunction (function () end ))
518-
519- local _ , e = assert_nil (c :perform ())
520- assert_equal (curl .error (curl .ERROR_EASY , curl .E_ABORTED_BY_CALLBACK ), e )
517+ -- assert_equal(c, c:setopt_readfunction(function() end))
518+ --
519+ -- local _, e = assert_nil(c:perform())
520+ -- assert_equal(curl.error(curl.ERROR_EASY, curl.E_ABORTED_BY_CALLBACK), e)
521521end
522522
523523function test_abort_02 ()
@@ -611,6 +611,7 @@ function test_readbuffer()
611611end
612612
613613function test_pass_01 ()
614+ -- We need this to support file:read() method which returns nil as EOF
614615 assert_equal (c , c :setopt_readfunction (function () return nil end ))
615616
616617 assert_equal (c , c :perform ())
@@ -619,6 +620,21 @@ function test_pass_01()
619620 assert_equal (0 , # data )
620621end
621622
623+ function test_pass_02 ()
624+ local counter = 10
625+ assert_equal (c , c :setopt_readfunction (function ()
626+ if counter > 0 then
627+ counter = counter - 1
628+ return ' a'
629+ end
630+ end ))
631+
632+ assert_equal (c , c :perform ())
633+ c :close ()
634+ local data = read_file (fname )
635+ assert_equal ((' a' ):rep (10 ), data )
636+ end
637+
622638end
623639
624640local _ENV = TEST_CASE ' escape' if ENABLE then
You can’t perform that action at this time.
0 commit comments