mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-22 12:04:20 -05:00
made netutil.ping actually return useful values
This commit is contained in:
parent
0712210768
commit
90afc8d18d
@ -1,5 +1,6 @@
|
|||||||
local computer = require "computer"
|
local computer = require "computer"
|
||||||
local minitel = require "minitel"
|
local minitel = require "minitel"
|
||||||
|
local event = require "event"
|
||||||
local rpc = require "rpc"
|
local rpc = require "rpc"
|
||||||
local netutil = {}
|
local netutil = {}
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ function netutil.importfs(host,rpath,lpath)
|
|||||||
return host..":"..rpath
|
return host..":"..rpath
|
||||||
end
|
end
|
||||||
fs.mount(lpath,px)
|
fs.mount(lpath,px)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function netutil.exportfs(path)
|
function netutil.exportfs(path)
|
||||||
@ -18,21 +20,29 @@ function netutil.exportfs(path)
|
|||||||
rpcs.register(path.."_"..k,v)
|
rpcs.register(path.."_"..k,v)
|
||||||
print(path.."_"..k)
|
print(path.."_"..k)
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function netutil.ping(addr,times,timeout)
|
function netutil.ping(addr,times,timeout, silent)
|
||||||
local times, timeout = times or 5, timeout or 30
|
local times, timeout = times or 5, timeout or 30
|
||||||
|
local success, fail, time, avg = 0, 0, 0, 0
|
||||||
for i = 1, times do
|
for i = 1, times do
|
||||||
local ipt = computer.uptime()
|
local ipt = computer.uptime()
|
||||||
local pid = minitel.genPacketID()
|
local pid = minitel.genPacketID()
|
||||||
computer.pushSignal("net_send",1,addr,0,"ping",pid)
|
computer.pushSignal("net_send",1,addr,0,"ping",pid)
|
||||||
local t,a = event.pull(timeout,"net_ack")
|
local t,a = event.pull(timeout,"net_ack")
|
||||||
if t == "net_ack" and a == pid then
|
if t == "net_ack" and a == pid then
|
||||||
print("Ping reply: "..tostring(computer.uptime()-ipt).." seconds.")
|
if not silent then print("Ping reply: "..tostring(computer.uptime()-ipt).." seconds.") end
|
||||||
|
success = success + 1
|
||||||
|
time = time + computer.uptime()-ipt
|
||||||
|
avg = time / success
|
||||||
else
|
else
|
||||||
print("Timed out.")
|
if not silent then print("Timed out.") end
|
||||||
|
fail = fail + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if not silent then print(string.format("%d packets transmitted, %d received, %0.0f%% packet loss, %0.1fs",times,success,fail/times*100,time)) end
|
||||||
|
return success > 0, success, fail, avg
|
||||||
end
|
end
|
||||||
|
|
||||||
return netutil
|
return netutil
|
||||||
|
Loading…
Reference in New Issue
Block a user