forked from smallnest/rpcx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_unix.go
35 lines (29 loc) · 882 Bytes
/
server_unix.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
// +build linux darwin dragonfly freebsd netbsd openbsd rumprun
package rpcx
import (
"crypto/tls"
"net"
reuseport "github.com/kavu/go_reuseport"
quicconn "github.com/marten-seemann/quic-conn"
kcp "github.com/xtaci/kcp-go"
)
// block can be nil if the caller wishes to skip encryption in kcp.
// tlsConfig can be nil iff we are not using network "quic".
func makeListener(network, address string, block kcp.BlockCrypt, tlsConfig *tls.Config) (ln net.Listener, err error) {
switch network {
case "kcp":
ln, err = kcp.ListenWithOptions(address, block, 10, 3)
case "reuseport":
if validIP4(address) {
network = "tcp4"
} else {
network = "tcp6"
}
ln, err = reuseport.NewReusablePortListener(network, address)
case "quic":
ln, err = quicconn.Listen("udp", address, tlsConfig)
default: //tcp
ln, err = net.Listen(network, address)
}
return ln, err
}