-
Notifications
You must be signed in to change notification settings - Fork 3
/
misc.go
72 lines (60 loc) · 1.42 KB
/
misc.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
package pfilter
import (
"net"
"sync"
"golang.org/x/net/ipv4"
)
var (
errTimeout = &netError{
msg: "i/o timeout",
timeout: true,
temporary: true,
}
errClosed = &netError{
msg: "use of closed network connection",
timeout: false,
temporary: false,
}
errNotSupported = &netError{
msg: "not supported",
timeout: false,
temporary: false,
}
// Compile time interface assertion.
_ net.Error = (*netError)(nil)
)
type netError struct {
msg string
timeout bool
temporary bool
}
func (e *netError) Error() string { return e.msg }
func (e *netError) Timeout() bool { return e.timeout }
func (e *netError) Temporary() bool { return e.temporary }
type filteredConnList []*filteredConn
func (r filteredConnList) Len() int { return len(r) }
func (r filteredConnList) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r filteredConnList) Less(i, j int) bool { return r[i].priority < r[j].priority }
type messageWithError struct {
ipv4.Message
Err error
}
func (m *messageWithError) Copy(pool *sync.Pool) messageWithError {
buf := pool.Get().([]byte)
oobBuf := pool.Get().([]byte)
copy(buf, m.Buffers[0][:m.N])
if m.NN > 0 {
copy(oobBuf, m.OOB[:m.NN])
}
return messageWithError{
Message: ipv4.Message{
Buffers: [][]byte{buf[:m.N]},
OOB: oobBuf[:m.NN],
Addr: m.Addr,
N: m.N,
NN: m.NN,
Flags: m.Flags,
},
Err: m.Err,
}
}