diff options
| author | ruki <[email protected]> | 2017-09-07 09:09:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-07 09:09:51 +0800 |
| commit | 9b6227b244cb19fccbed759ef0997c568a4b1191 (patch) | |
| tree | e57459941e88fcccfcb3160b374236ced6bf91b3 | |
| parent | fb3073e85fd00ae0a596761698284a0d7acd5bbd (diff) | |
improve ping cache
| -rw-r--r-- | xmake/modules/net/ping.lua | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/xmake/modules/net/ping.lua b/xmake/modules/net/ping.lua index 48f97e394..a3629b193 100644 --- a/xmake/modules/net/ping.lua +++ b/xmake/modules/net/ping.lua @@ -67,25 +67,37 @@ function main(hosts, opt) if timeval then results[host] = timeval else - -- ping it + -- ping it, timeout: 1s local data = nil if os.host() == "windows" then - data = os.iorun("%s -n 1 %s", ping, host) + data = os.iorun("%s -n 1 -w 1000 %s", ping, host) else - data = os.iorun("%s -c 1 %s", ping, host) + data = os.iorun("%s -c 1 -t 1 %s", ping, host) end -- find time - local time = data:match("time=(.-)ms", 1, true) - if time then - local timeval = tonumber(time:trim()) - results[host] = timeval - if cacheinfo then - cacheinfo[host] = timeval - end + local timeval = data:match("time=(.-)ms", 1, true) or "65535" + if timeval then + timeval = tonumber(timeval:trim()) + end + results[host] = timeval + if cacheinfo then + cacheinfo[host] = timeval + end + end + end, + catch + { + function (errors) + + -- no network + local timeval = 65535 + results[host] = timeval + if cacheinfo then + cacheinfo[host] = timeval end end - end + } } end end, #hosts) |
