-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener_warp.go
75 lines (64 loc) · 1.31 KB
/
listener_warp.go
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
package goginx
import (
"net"
"os"
"sync"
"syscall"
"time"
)
func newGoginxListener(l net.Listener, wg *sync.WaitGroup) *goginxListener {
return &goginxListener{
Listener: l,
wg: wg,
}
}
type goginxListener struct {
net.Listener
stopped bool
wg *sync.WaitGroup
}
func (this *goginxListener) Accept() (net.Conn, error) {
conn, err := this.Listener.(*net.TCPListener).AcceptTCP()
if err != nil {
return nil, err
}
conn.SetKeepAlive(true) // see http.tcpKeepAliveListener
conn.SetKeepAlivePeriod(3 * time.Minute) // see http.tcpKeepAliveListener
nxconn := goginxConn{
Conn: conn,
wg: this.wg,
}
this.wg.Add(1)
return nxconn, nil
}
func (this *goginxListener) Close() error {
if this.stopped {
return syscall.EINVAL
}
this.stopped = true
return this.Listener.Close()
}
func (this *goginxListener) File() (*os.File, error) {
// returns a dup(2) - FD_CLOEXEC flag *not* set
//tl := this.Listener.(*net.TCPListener)
//fl, _ := tl.File()
tl, err := this.Listener.(filer).File()
return tl, err
}
type filer interface {
File() (*os.File, error)
}
type goginxTlsListenner struct {
goginxListener
}
type goginxConn struct {
net.Conn
wg *sync.WaitGroup
}
func (nxc goginxConn) Close() error {
err := nxc.Conn.Close()
if err == nil {
nxc.wg.Done()
}
return err
}