2012-02-27 22:26:23 +01:00
|
|
|
#!/usr/bin/env lua
|
|
|
|
|
2020-03-27 23:55:04 +01:00
|
|
|
local socket = require"socket"
|
2012-02-27 22:26:23 +01:00
|
|
|
|
|
|
|
port = 8765
|
|
|
|
|
2020-03-28 22:14:18 +01:00
|
|
|
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
|
|
|
|
|
2012-02-27 22:26:23 +01:00
|
|
|
function options(o)
|
|
|
|
print("options for", o)
|
|
|
|
|
2014-12-05 13:17:50 +01:00
|
|
|
for _, opt in ipairs{
|
|
|
|
"keepalive", "reuseaddr",
|
|
|
|
"tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
|
2020-03-28 22:14:18 +01:00
|
|
|
pcalltest("getoption", o, opt)
|
2012-02-27 22:26:23 +01:00
|
|
|
end
|
|
|
|
|
2020-03-28 22:14:18 +01:00
|
|
|
r = o:getoption'linger'
|
|
|
|
if r then
|
|
|
|
print("getoption", "linger",
|
|
|
|
"on", r.on,
|
|
|
|
"timeout", r.timeout)
|
|
|
|
else
|
|
|
|
print("getoption", "linger", "no result")
|
|
|
|
end
|
2012-02-27 22:26:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local m = socket.tcp()
|
|
|
|
|
|
|
|
options(m)
|
|
|
|
|
|
|
|
assert(m:bind("*", port))
|
|
|
|
assert(m:listen())
|
|
|
|
|
|
|
|
options(m)
|
|
|
|
|
|
|
|
m:close()
|
|
|
|
|
|
|
|
local m = socket.bind("*", port)
|
|
|
|
|
|
|
|
options(m)
|
|
|
|
|
|
|
|
local c = socket.connect("localhost", port)
|
|
|
|
|
|
|
|
options(c)
|
|
|
|
|
|
|
|
local s = m:accept()
|
|
|
|
|
|
|
|
options(s)
|
|
|
|
|