aboutsummaryrefslogtreecommitdiff
path: root/test/tcp-getoptions
blob: fbcc8846b2f70c0182f040ffd56ee1c854179184 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)