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
|
|
|
|
|
|
|
|
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
|
2012-02-27 22:26:23 +01:00
|
|
|
print("getoption", opt, o:getoption(opt))
|
|
|
|
end
|
|
|
|
|
|
|
|
print("getoption", "linger",
|
|
|
|
"on", o:getoption("linger").on,
|
|
|
|
"timeout", o:getoption("linger").timeout)
|
|
|
|
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)
|
|
|
|
|