File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ local cURL = require (" cURL" )
2+
3+ local f1 = io.open (" lua.html" , " w+b" )
4+ local f2 = io.open (" luajit.html" , " w+b" )
5+
6+ -- setup easy and url
7+ c1 = cURL .easy {url = " http://www.lua.org/" , writefunction = f1 }
8+ c2 = cURL .easy {url = " http://luajit.org/" , writefunction = f2 }
9+ c3 = cURL .easy {url = " ****://luajit.org/" } -- UNSUPPORTED_PROTOCOL
10+
11+ m = cURL .multi ()
12+ :add_handle (c1 )
13+ :add_handle (c2 )
14+ :add_handle (c3 )
15+
16+ local remain = 3
17+ while remain > 0 do
18+ local last = m :perform () -- do some work
19+ if last < remain then -- we have done some tasks
20+ while true do -- proceed results/errors
21+ local e , ok , err = m :info_read (true ) -- get result and remove handle
22+ if e == 0 then break end -- no more finished tasks
23+ if ok then -- succeed
24+ print (e :getinfo_effective_url (), ' -' , e :getinfo_response_code ())
25+ else -- failure
26+ print (e :getinfo_effective_url (), ' -' , err )
27+ end
28+ e :close ()
29+ end
30+ end
31+ remain = last
32+
33+ -- wait while libcurl do io select
34+ m :wait ()
35+ end
Original file line number Diff line number Diff line change @@ -393,7 +393,16 @@ function Multi:remove_handle(e)
393393 return remove_handle (self , h )
394394end
395395
396- -- ! @fixme Multi:info_read(true) should also remove easy handle from self._easy
396+ function Multi :info_read (...)
397+ local h , ok , err = self :handle ():info_read (... )
398+ if not h then return nil , ok end
399+ if h == 0 then return h end
400+
401+ if ... and self ._easy [h ] then
402+ self ._easy [h ], self ._easy .n = nil , self ._easy .n - 1
403+ end
404+ return h , ok , err
405+ end
397406
398407end
399408---- ---------------------------------------
You can’t perform that action at this time.
0 commit comments