mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 03:58:21 +01:00
test/getoptions: guard calls with pcall(); check result of getoption"linger"
This commit is contained in:
parent
84e5336e8b
commit
c8b4fdf858
@ -4,18 +4,32 @@ local socket = require"socket"
|
|||||||
|
|
||||||
port = 8765
|
port = 8765
|
||||||
|
|
||||||
|
function pcalltest(msg, o, opt)
|
||||||
|
local a = { pcall(o.getoption, o, opt) }
|
||||||
|
if a[1] then
|
||||||
|
print(msg, opt, unpack(a))
|
||||||
|
else
|
||||||
|
print(msg, opt, 'fail: ' .. a[2])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function options(o)
|
function options(o)
|
||||||
print("options for", o)
|
print("options for", o)
|
||||||
|
|
||||||
for _, opt in ipairs{
|
for _, opt in ipairs{
|
||||||
"keepalive", "reuseaddr",
|
"keepalive", "reuseaddr",
|
||||||
"tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
|
"tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
|
||||||
print("getoption", opt, o:getoption(opt))
|
pcalltest("getoption", o, opt)
|
||||||
end
|
end
|
||||||
|
|
||||||
print("getoption", "linger",
|
r = o:getoption'linger'
|
||||||
"on", o:getoption("linger").on,
|
if r then
|
||||||
"timeout", o:getoption("linger").timeout)
|
print("getoption", "linger",
|
||||||
|
"on", r.on,
|
||||||
|
"timeout", r.timeout)
|
||||||
|
else
|
||||||
|
print("getoption", "linger", "no result")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local m = socket.tcp()
|
local m = socket.tcp()
|
||||||
|
Loading…
Reference in New Issue
Block a user