updated netutil to use the documentation library's type signature system

This commit is contained in:
Izaya 2020-05-11 01:00:13 +10:00
parent cae7c916ae
commit d59cc53340

View File

@ -5,7 +5,7 @@ local ufs = require "unionfs"
local rpc = require "rpc"
local netutil = {}
function netutil.importfs(host,rpath,lpath) -- import filesystem *rpath* from *host* and attach it to *lpath*
function netutil.importfs(host,rpath,lpath) -- string string string -- boolean -- Import filesystem *rpath* from *host* and attach it to *lpath*.
local px = rpc.proxy(host,rpath.."_")
function px.getLabel()
return host..":"..rpath
@ -14,7 +14,7 @@ function netutil.importfs(host,rpath,lpath) -- import filesystem *rpath* from *h
return fs.mount(lpath,px)
end
function netutil.exportfs(path) -- export the directory *path* over RPC
function netutil.exportfs(path) -- string -- boolean -- Export the directory *path* over RPC.
local path = "/"..table.concat(fs.segments(path),"/")
local px = ufs.create(path)
for k,v in pairs(px) do
@ -24,7 +24,7 @@ function netutil.exportfs(path) -- export the directory *path* over RPC
return true
end
function netutil.ping(addr,times,timeout, silent) -- Request acknowledgment from *addr*, waiting *timeout* seconds each try, and try *times* times. If *silent* is true, don't print status. Returns true if there was at least one successful ping, the number of successes, the number of failures, and the average round trip time.
function netutil.ping(addr,times,timeout,silent) -- string number number boolean -- boolean number number number -- Request acknowledgment from *addr*, waiting *timeout* seconds each try, and try *times* times. If *silent* is true, don't print status. Returns true if there was at least one successful ping, the number of successes, the number of failures, and the average round trip time.
local times, timeout = times or 5, timeout or 30
local success, fail, time, avg = 0, 0, 0, 0
for i = 1, times do
@ -46,7 +46,7 @@ function netutil.ping(addr,times,timeout, silent) -- Request acknowledgment from
return success > 0, success, fail, avg
end
function netutil.nc(host,port)
function netutil.nc(host,port) -- string number -- boolean -- Starts an interactive Minitel socket connection to *host* on *port*, primarily for remote login. Returns whether the attempt was successful.
port = port or 22
local socket = minitel.open(host,port)
if not socket then return false end
@ -66,6 +66,7 @@ function netutil.nc(host,port)
socket:write(b.."\n")
end
until socket.state ~= "open"
return true
end
return netutil