-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
system_listener.go
47 lines (37 loc) · 1.27 KB
/
system_listener.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
package internet
import (
"context"
"syscall"
"v2ray.com/core/common/net"
"v2ray.com/core/common/session"
)
var (
effectiveListener = DefaultListener{}
)
type DefaultListener struct{}
func (*DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.Listener, error) {
var lc net.ListenConfig
if sockopt != nil {
lc.Control = func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
if err := applyInboundSocketOptions(network, fd, sockopt); err != nil {
newError("failed to apply socket options to incoming connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
}
})
}
}
return lc.Listen(ctx, addr.Network(), addr.String())
}
func (*DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.PacketConn, error) {
var lc net.ListenConfig
if sockopt != nil {
lc.Control = func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
if err := applyInboundSocketOptions(network, fd, sockopt); err != nil {
newError("failed to apply socket options to incoming connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
}
})
}
}
return lc.ListenPacket(ctx, addr.Network(), addr.String())
}