forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl.go
64 lines (48 loc) · 1.46 KB
/
impl.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
package sockettransport
import (
"net"
"github.com/gogf/greuse"
)
type impl interface {
// Dial the socket.
Dial(network, local, remote string) (net.Conn, error)
// Redial the socket.
Redial(oldConn net.Conn) (net.Conn, error)
// Receive a TLV packet on the socket.
Read(tr *transport, buf []byte) (n int, e error)
}
var implByNetwork = map[string]impl{}
// noLocalAddrDialer dials with only remote addr.
type noLocalAddrDialer struct{}
func (noLocalAddrDialer) Dial(network, _, remote string) (net.Conn, error) {
dialer := net.Dialer{
Control: greuse.Control,
}
return dialer.Dial(network, remote)
}
// localAddrRedialer redials reusing local addr.
type localAddrRedialer struct{}
func (localAddrRedialer) Redial(oldConn net.Conn) (net.Conn, error) {
local, remote := oldConn.LocalAddr(), oldConn.RemoteAddr()
oldConn.Close() // ignore error
dialer := net.Dialer{
LocalAddr: local,
Control: greuse.Control,
}
return dialer.Dial(remote.Network(), remote.String())
}
// noLocalAddrRedialer redials with only remote addr.
type noLocalAddrRedialer struct{}
func (noLocalAddrRedialer) Redial(oldConn net.Conn) (net.Conn, error) {
remote := oldConn.RemoteAddr()
oldConn.Close() // ignore error
dialer := net.Dialer{
Control: greuse.Control,
}
return dialer.Dial(remote.Network(), remote.String())
}
// nopRedialer redials by doing nothing.
type nopRedialer struct{}
func (nopRedialer) Redial(oldConn net.Conn) (net.Conn, error) {
return oldConn, nil
}