aboutsummaryrefslogtreecommitdiff
path: root/test/tcp-getoptions
blob: 777ccc31ad3a6866fb134a29ed95e2605aa42cfb (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
#!/usr/bin/env lua

require"socket"

port = 8765

function options(o)
    print("options for", o)

    for _, opt in ipairs{
    		"keepalive", "reuseaddr",
     		"tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do
        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)