Lua-cURLv3/examples/cURLv2/multi.lua

22 lines
527 B
Lua
Raw Permalink Normal View History

2014-09-10 03:32:04 -07:00
local cURL = require("cURL")
2014-08-29 00:07:34 -07:00
-- setup easy
2014-09-10 03:32:04 -07:00
c1 = cURL.easy_init()
2014-08-29 00:07:34 -07:00
c2 = cURL.easy_init()
-- setup url
2014-09-10 03:32:04 -07:00
c1:setopt_url("http://www.lua.org/")
2014-08-29 00:07:34 -07:00
c2:setopt_url("http://luajit.org/")
m = cURL.multi_init()
2014-09-10 03:32:04 -07:00
m:add_handle(c1)
2014-08-29 00:07:34 -07:00
m:add_handle(c2)
local f1 = io.open("lua.html","a+")
local f2 = io.open("luajit.html","a+")
for data, type, easy in m:perform() do
-- if (type == "header") then print(data) end
2014-09-10 03:32:04 -07:00
if (type == "data" and c1 == easy) then f1:write(data) end
2014-08-29 00:07:34 -07:00
if (type == "data" and c2 == easy) then f2:write(data) end
end