module 是邪恶的
local ngx_socket_tcp = ngx.socket.tcp -- ①
local _M = { _VERSION = '0.06' } -- ②
local mt = { __index = _M } -- ③
function _M.new(self)
local sock, err = ngx_socket_tcp() -- ④
if not sock then
return nil, err
end
return setmetatable({ sock = sock }, mt) -- ⑤
end
function _M.set_timeout(self, timeout)
local sock = self.sock
if not sock then
return nil, "not initialized"
end
return sock:settimeout(timeout)
end
-- ... 其他功能代码,这里简略
return _MLast updated