diff options
| author | E. Westbrook <git@westbrook.io> | 2020-03-28 15:14:18 -0600 |
|---|---|---|
| committer | Eric Westbrook <github@westbrook.io> | 2020-03-28 22:21:23 +0000 |
| commit | c8b4fdf85829d98e185256fba10d50f5b35735a8 (patch) | |
| tree | a09801bb1dc0b18809a2d0d53deaa3faf8e35270 | |
| parent | 84e5336e8b9f364e675c3a55a8bb04c1fddb68bc (diff) | |
| download | luasocket-c8b4fdf85829d98e185256fba10d50f5b35735a8.tar.gz luasocket-c8b4fdf85829d98e185256fba10d50f5b35735a8.tar.bz2 luasocket-c8b4fdf85829d98e185256fba10d50f5b35735a8.zip | |
test/getoptions: guard calls with pcall(); check result of getoption"linger"
| -rwxr-xr-x | test/tcp-getoptions | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/tcp-getoptions b/test/tcp-getoptions index d98b189..fbcc884 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions | |||
| @@ -4,18 +4,32 @@ local socket = require"socket" | |||
| 4 | 4 | ||
| 5 | port = 8765 | 5 | port = 8765 |
| 6 | 6 | ||
| 7 | function pcalltest(msg, o, opt) | ||
| 8 | local a = { pcall(o.getoption, o, opt) } | ||
| 9 | if a[1] then | ||
| 10 | print(msg, opt, unpack(a)) | ||
| 11 | else | ||
| 12 | print(msg, opt, 'fail: ' .. a[2]) | ||
| 13 | end | ||
| 14 | end | ||
| 15 | |||
| 7 | function options(o) | 16 | function options(o) |
| 8 | print("options for", o) | 17 | print("options for", o) |
| 9 | 18 | ||
| 10 | for _, opt in ipairs{ | 19 | for _, opt in ipairs{ |
| 11 | "keepalive", "reuseaddr", | 20 | "keepalive", "reuseaddr", |
| 12 | "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do | 21 | "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do |
| 13 | print("getoption", opt, o:getoption(opt)) | 22 | pcalltest("getoption", o, opt) |
| 14 | end | 23 | end |
| 15 | 24 | ||
| 16 | print("getoption", "linger", | 25 | r = o:getoption'linger' |
| 17 | "on", o:getoption("linger").on, | 26 | if r then |
| 18 | "timeout", o:getoption("linger").timeout) | 27 | print("getoption", "linger", |
| 28 | "on", r.on, | ||
| 29 | "timeout", r.timeout) | ||
| 30 | else | ||
| 31 | print("getoption", "linger", "no result") | ||
| 32 | end | ||
| 19 | end | 33 | end |
| 20 | 34 | ||
| 21 | local m = socket.tcp() | 35 | local m = socket.tcp() |
