summaryrefslogtreecommitdiff
path: root/ThirdParty/luasocket/test/tcp-getoptions
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-10-20 13:40:34 +0800
committerchai <chaifix@163.com>2021-10-20 13:40:34 +0800
commitff0f488c97fe8b554b909a0057cebc4c860eac8f (patch)
tree4e47262b52ffce7e9cfeaaeeab46371243bcaa78 /ThirdParty/luasocket/test/tcp-getoptions
parentdde719dd575090b36aaa3ad85bb3cabf33f36c5a (diff)
+luasocket src
Diffstat (limited to 'ThirdParty/luasocket/test/tcp-getoptions')
-rw-r--r--ThirdParty/luasocket/test/tcp-getoptions57
1 files changed, 57 insertions, 0 deletions
diff --git a/ThirdParty/luasocket/test/tcp-getoptions b/ThirdParty/luasocket/test/tcp-getoptions
new file mode 100644
index 0000000..fbcc884
--- /dev/null
+++ b/ThirdParty/luasocket/test/tcp-getoptions
@@ -0,0 +1,57 @@
+#!/usr/bin/env lua
+
+local socket = require"socket"
+
+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)
+ print("options for", o)
+
+ for _, opt in ipairs{
+ "keepalive", "reuseaddr",
+ "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
+ pcalltest("getoption", o, opt)
+ end
+
+ r = o:getoption'linger'
+ if r then
+ print("getoption", "linger",
+ "on", r.on,
+ "timeout", r.timeout)
+ else
+ print("getoption", "linger", "no result")
+ end
+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)
+