-
Notifications
You must be signed in to change notification settings - Fork 3
/
conn_oob.go
52 lines (40 loc) · 1.06 KB
/
conn_oob.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
package pfilter
import (
"net"
"time"
"github.com/quic-go/quic-go"
)
var _ quic.OOBCapablePacketConn = (*filteredConnObb)(nil)
type filteredConnObb struct {
*filteredConn
}
func (r *filteredConnObb) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error) {
return r.source.oobConn.WriteMsgUDP(b, oob, addr)
}
func (r *filteredConnObb) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *net.UDPAddr, err error) {
select {
case <-r.closed:
return 0, 0, 0, nil, errClosed
default:
}
var timeout <-chan time.Time
if deadline, ok := r.deadline.Load().(time.Time); ok && !deadline.IsZero() {
timer := time.NewTimer(deadline.Sub(time.Now()))
timeout = timer.C
defer timer.Stop()
}
select {
case <-timeout:
return 0, 0, 0, nil, errTimeout
case msg := <-r.recvBuffer:
n, nn, err := copyBuffers(msg, b, oob)
r.source.returnBuffers(msg.Message)
udpAddr, ok := msg.Addr.(*net.UDPAddr)
if !ok && err == nil {
err = errNotSupported
}
return n, nn, msg.Flags, udpAddr, err
case <-r.closed:
return 0, 0, 0, nil, errClosed
}
}