Simplify code of cURL module.
This commit is contained in:
parent
c2f8fc99f9
commit
e0dfc3a490
@ -32,11 +32,10 @@ local function wrap_setopt_flags(k, flags)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------
|
local function class(ctor)
|
||||||
local Easy = {} do
|
local C = {}
|
||||||
|
C.__index = function(self, k)
|
||||||
Easy.__index = function(self, k)
|
local fn = C[k]
|
||||||
local fn = Easy[k]
|
|
||||||
|
|
||||||
if not fn and self._handle[k] then
|
if not fn and self._handle[k] then
|
||||||
fn = wrap_function(k)
|
fn = wrap_function(k)
|
||||||
@ -45,8 +44,8 @@ Easy.__index = function(self, k)
|
|||||||
return fn
|
return fn
|
||||||
end
|
end
|
||||||
|
|
||||||
function Easy:new()
|
function C:new()
|
||||||
local h, err = curl.easy()
|
local h, err = ctor()
|
||||||
if not h then return nil, err end
|
if not h then return nil, err end
|
||||||
|
|
||||||
local o = setmetatable({
|
local o = setmetatable({
|
||||||
@ -56,10 +55,16 @@ function Easy:new()
|
|||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function Easy:handle()
|
function C:handle()
|
||||||
return self._handle
|
return self._handle
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
end
|
||||||
|
|
||||||
|
-------------------------------------------
|
||||||
|
local Easy = class(curl.easy) do
|
||||||
|
|
||||||
local perform = wrap_function("perform")
|
local perform = wrap_function("perform")
|
||||||
local setopt_share = wrap_function("setopt_share")
|
local setopt_share = wrap_function("setopt_share")
|
||||||
local setopt_readfunction = wrap_function("setopt_readfunction")
|
local setopt_readfunction = wrap_function("setopt_readfunction")
|
||||||
@ -196,33 +201,7 @@ end
|
|||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
local Multi = {} do
|
local Multi = class(curl.multi) do
|
||||||
|
|
||||||
Multi.__index = function(self, k)
|
|
||||||
local fn = Multi[k]
|
|
||||||
|
|
||||||
if not fn and self._handle[k] then
|
|
||||||
fn = wrap_function(k)
|
|
||||||
self[k] = fn
|
|
||||||
end
|
|
||||||
return fn
|
|
||||||
end
|
|
||||||
|
|
||||||
function Multi:new()
|
|
||||||
local h, err = curl.multi()
|
|
||||||
if not h then return nil, err end
|
|
||||||
|
|
||||||
local o = setmetatable({
|
|
||||||
_handle = h;
|
|
||||||
_easy = {};
|
|
||||||
}, self)
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Multi:handle()
|
|
||||||
return self._handle
|
|
||||||
end
|
|
||||||
|
|
||||||
local perform = wrap_function("perform")
|
local perform = wrap_function("perform")
|
||||||
local add_handle = wrap_function("add_handle")
|
local add_handle = wrap_function("add_handle")
|
||||||
@ -309,32 +288,7 @@ end
|
|||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
local Share = {} do
|
local Share = class(curl.share) do
|
||||||
|
|
||||||
Share.__index = function(self, k)
|
|
||||||
local fn = Share[k]
|
|
||||||
|
|
||||||
if not fn and self._handle[k] then
|
|
||||||
fn = wrap_function(k)
|
|
||||||
self[k] = fn
|
|
||||||
end
|
|
||||||
return fn
|
|
||||||
end
|
|
||||||
|
|
||||||
function Share:new()
|
|
||||||
local h, err = curl.share()
|
|
||||||
if not h then return nil, err end
|
|
||||||
|
|
||||||
local o = setmetatable({
|
|
||||||
_handle = h
|
|
||||||
}, self)
|
|
||||||
|
|
||||||
return o
|
|
||||||
end
|
|
||||||
|
|
||||||
function Share:handle()
|
|
||||||
return self._handle
|
|
||||||
end
|
|
||||||
|
|
||||||
Share.setopt_share = wrap_setopt_flags("share", {
|
Share.setopt_share = wrap_setopt_flags("share", {
|
||||||
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
|
[ "COOKIE" ] = curl.LOCK_DATA_COOKIE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user