Skip to content

Commit 1b88ec4

Browse files
committed
Fix. multi:info_read correctly remove easy handle.
1 parent b2e6bca commit 1b88ec4

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

examples/cURLv3/multi2.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

src/lua/cURL/impl/cURL.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,16 @@ function Multi:remove_handle(e)
393393
return remove_handle(self, h)
394394
end
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

398407
end
399408
-------------------------------------------

0 commit comments

Comments
 (0)