Repository navigation
Expand file tree
/
Copy pathstack_go_conn_options.go
More file actions
87 lines (77 loc) · 1.86 KB
/
Copy pathstack_go_conn_options.go
File metadata and controls
87 lines (77 loc) · 1.86 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package tun
import (
"net"
"time"
)
const (
goKeepaliveDefaultIdle = 5 * time.Minute
goKeepaliveDefaultInterval = 75 * time.Second
goKeepaliveDefaultCount = 9
goKeepaliveMaxCount = 127
)
func (c *GoConn) SetKeepAlive(keepalive bool) error {
c.access.Lock()
c.keepaliveEnabled = keepalive
c.access.Unlock()
c.engine.postMessage(&c.keepaliveMessage)
return nil
}
func (c *GoConn) SetKeepAlivePeriod(d time.Duration) error {
c.access.Lock()
c.setKeepaliveIdle(d)
c.access.Unlock()
c.engine.postMessage(&c.keepaliveMessage)
return nil
}
func (c *GoConn) SetKeepAliveConfig(config net.KeepAliveConfig) error {
c.access.Lock()
c.keepaliveEnabled = config.Enable
c.setKeepaliveIdle(config.Idle)
switch {
case config.Interval == 0:
c.keepaliveInterval = goKeepaliveDefaultInterval
case config.Interval > 0:
c.keepaliveInterval = config.Interval
}
switch {
case config.Count == 0:
c.keepaliveCount = goKeepaliveDefaultCount
case config.Count > 0:
c.keepaliveCount = uint8(min(config.Count, goKeepaliveMaxCount))
}
c.access.Unlock()
c.engine.postMessage(&c.keepaliveMessage)
return nil
}
func (c *GoConn) setKeepaliveIdle(idle time.Duration) {
switch {
case idle == 0:
c.keepaliveIdle = goKeepaliveDefaultIdle
case idle > 0:
c.keepaliveIdle = idle
}
}
func (c *GoConn) SetNoDelay(noDelay bool) error {
c.access.Lock()
c.nagle = !noDelay
c.access.Unlock()
return nil
}
func (c *GoConn) SetLinger(sec int) error {
c.access.Lock()
c.linger = sec
c.access.Unlock()
return nil
}
func (c *GoConn) SetReadBuffer(size int) error {
c.access.Lock()
c.receiveCapacityMax = uint64(min(max(size, goSlabSize), goReceiveCapacityMax))
c.access.Unlock()
return nil
}
func (c *GoConn) SetWriteBuffer(size int) error {
c.access.Lock()
c.transmitCapacity = uint64(min(max(size, goSlabSize), goTransmitCapacityMax))
c.access.Unlock()
return nil
}