-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsock.go
84 lines (78 loc) · 2.14 KB
/
sock.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
76
77
78
79
80
81
82
83
84
// ©Hayabusa Cloud Co., Ltd. 2024. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package sox
func Listen(network string, address string) (listener Listener, err error) {
switch network {
case "tcp", "tcp4", "tcp6":
a, err := ResolveTCPAddr(network, address)
if err != nil {
return nil, err
}
return ListenTCP(network, a)
case "sctp", "sctp4", "sctp6":
a, err := ResolveSCTPAddr(network, address)
if err != nil {
return nil, err
}
return ListenSCTP(network, a)
case "unix", "unixpacket":
addr, err := ResolveUnixAddr(network, address)
if err != nil {
return nil, err
}
return ListenUnix(addr)
}
return nil, &OpError{Op: "listen", Net: network, Source: nil, Addr: nil, Err: UnknownNetworkError(network)}
}
func ListenTCP(network string, laddr *TCPAddr) (listener Listener, err error) {
if laddr == nil {
laddr = &TCPAddr{}
}
switch network {
case "tcp":
if ipFamily(laddr.IP) == NetworkIPv4 {
return ListenTCP4(laddr)
}
return ListenTCP6(laddr)
case "tcp4":
return ListenTCP4(laddr)
case "tcp6":
return ListenTCP6(laddr)
}
return nil, &OpError{Op: "listen", Net: network, Source: nil, Addr: laddr, Err: UnknownNetworkError(network)}
}
func ListenUDP(network string, laddr *UDPAddr) (conn *UDPConn, err error) {
if laddr == nil {
laddr = &UDPAddr{}
}
switch network {
case "udp":
if ipFamily(laddr.IP) == NetworkIPv4 {
return ListenUDP4(laddr)
}
return ListenUDP6(laddr)
case "udp4":
return ListenUDP4(laddr)
case "udp6":
return ListenUDP6(laddr)
}
return nil, &OpError{Op: "listen", Net: network, Source: nil, Addr: laddr, Err: UnknownNetworkError(network)}
}
func ListenSCTP(network string, laddr *SCTPAddr) (listener Listener, err error) {
if laddr == nil {
laddr = &SCTPAddr{}
}
switch network {
case "sctp":
if ipFamily(laddr.IP) == NetworkIPv4 {
return ListenSCTP4(laddr)
}
return ListenSCTP6(laddr)
case "sctp4":
return ListenSCTP4(laddr)
case "sctp6":
return ListenSCTP6(laddr)
}
return nil, &OpError{Op: "listen", Net: network, Source: nil, Addr: laddr, Err: UnknownNetworkError(network)}
}