forked from getlantern/go-udtwrapper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdial.go
56 lines (47 loc) · 1.58 KB
/
dial.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
package udt
import (
"errors"
"net"
)
type Dialer struct {
LocalAddr net.Addr
}
var errMissingAddress = errors.New("missing address")
// DialUDT connects to the remote address raddr on the network net,
// which must be "udt", "udt4", or "udt6".
func (d *Dialer) DialUDT(network string, raddr *UDTAddr) (*UDTConn, error) {
switch network {
case "udt", "udt4", "udt6":
default:
return nil, &net.OpError{Op: "dial", Net: network, Addr: raddr, Err: net.UnknownNetworkError(network)}
}
if raddr == nil {
return nil, &net.OpError{Op: "dial", Net: network, Addr: nil, Err: errMissingAddress}
}
laddr, ok := d.LocalAddr.(*UDTAddr)
if !ok {
laddr = nil
}
return dialConn(laddr, raddr)
}
// Dial connects to the remote address raddr on the network net,
// which must be "udt", "udt4", or "udt6".
func (d *Dialer) Dial(network, address string) (c net.Conn, err error) {
raddr, err := ResolveUDTAddr(network, address)
if err != nil {
return nil, err
}
return d.DialUDT(network, raddr)
}
// Dial connects to the remote address raddr on the network net,
// which must be "udt", "udt4", or "udt6". If laddr is not nil, it is
// used as the local address for the connection.
func Dial(network, address string) (c net.Conn, err error) {
return (&Dialer{}).Dial(network, address)
}
// DialUDT connects to the remote address raddr on the network net,
// which must be "udt", "udt4", or "udt6". If laddr is not nil, it is
// used as the local address for the connection.
func DialUDT(net string, laddr, raddr *UDTAddr) (*UDTConn, error) {
return (&Dialer{LocalAddr: laddr}).DialUDT(net, raddr)
}