summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua')
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua40
1 files changed, 2 insertions, 38 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua b/Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua
index ea88353838d..1c418542f43 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/src/tp.lua
@@ -1,29 +1,11 @@
------------------------------------------------------------------------------
--- Unified SMTP/FTP subsystem
--- LuaSocket toolkit.
--- Author: Diego Nehab
------------------------------------------------------------------------------
-
------------------------------------------------------------------------------
--- Declare module and import dependencies
------------------------------------------------------------------------------
local base = _G
local string = require("string")
local socket = socket or require("socket")
local ltn12 = ltn12 or require("ltn12")
-
socket.tp = {}
local _M = socket.tp
-
------------------------------------------------------------------------------
--- Program constants
------------------------------------------------------------------------------
+module("socket.tp")
_M.TIMEOUT = 60
-
------------------------------------------------------------------------------
--- Implementation
------------------------------------------------------------------------------
--- gets server reply (works for SMTP and FTP)
local function get_reply(c)
local code, current, sep
local line, err = c:receive()
@@ -37,23 +19,17 @@ local function get_reply(c)
if err then return nil, err end
current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
reply = reply .. "\n" .. line
- -- reply ends with same code
until code == current and sep == " "
end
return code, reply
end
-
--- metatable for sock object
local metat = { __index = {} }
-
function metat.__index:getpeername()
return self.c:getpeername()
end
-
function metat.__index:getsockname()
return self.c:getpeername()
end
-
function metat.__index:check(ok)
local code, reply = get_reply(self.c)
if not code then return nil, reply end
@@ -71,7 +47,6 @@ function metat.__index:check(ok)
end
else return ok(base.tonumber(code), reply) end
end
-
function metat.__index:command(cmd, arg)
cmd = string.upper(cmd)
if arg then
@@ -80,45 +55,34 @@ function metat.__index:command(cmd, arg)
return self.c:send(cmd .. "\r\n")
end
end
-
function metat.__index:sink(snk, pat)
local chunk, err = self.c:receive(pat)
return snk(chunk, err)
end
-
function metat.__index:send(data)
return self.c:send(data)
end
-
function metat.__index:receive(pat)
return self.c:receive(pat)
end
-
function metat.__index:getfd()
return self.c:getfd()
end
-
function metat.__index:dirty()
return self.c:dirty()
end
-
function metat.__index:getcontrol()
return self.c
end
-
function metat.__index:source(source, step)
local sink = socket.sink("keep-open", self.c)
local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step)
return ret, err
end
-
--- closes the underlying c
function metat.__index:close()
self.c:close()
return 1
end
-
--- connect with server and return c object
function _M.connect(host, port, timeout, create)
local c, e = (create or socket.tcp)()
if not c then return nil, e end
@@ -130,5 +94,5 @@ function _M.connect(host, port, timeout, create)
end
return base.setmetatable({c = c}, metat)
end
-
+socket.tp = _M
return _M