-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
endpoint.go
78 lines (63 loc) · 1.54 KB
/
endpoint.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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package mux
import (
"errors"
"io"
"net"
"time"
"github.com/pion/ice/v2"
"github.com/pion/transport/v2/packetio"
)
// Endpoint implements net.Conn. It is used to read muxed packets.
type Endpoint struct {
mux *Mux
buffer *packetio.Buffer
}
// Close unregisters the endpoint from the Mux
func (e *Endpoint) Close() (err error) {
err = e.close()
if err != nil {
return err
}
e.mux.RemoveEndpoint(e)
return nil
}
func (e *Endpoint) close() error {
return e.buffer.Close()
}
// Read reads a packet of len(p) bytes from the underlying conn
// that are matched by the associated MuxFunc
func (e *Endpoint) Read(p []byte) (int, error) {
return e.buffer.Read(p)
}
// Write writes len(p) bytes to the underlying conn
func (e *Endpoint) Write(p []byte) (int, error) {
n, err := e.mux.nextConn.Write(p)
if errors.Is(err, ice.ErrNoCandidatePairs) {
return 0, nil
} else if errors.Is(err, ice.ErrClosed) {
return 0, io.ErrClosedPipe
}
return n, err
}
// LocalAddr is a stub
func (e *Endpoint) LocalAddr() net.Addr {
return e.mux.nextConn.LocalAddr()
}
// RemoteAddr is a stub
func (e *Endpoint) RemoteAddr() net.Addr {
return e.mux.nextConn.RemoteAddr()
}
// SetDeadline is a stub
func (e *Endpoint) SetDeadline(time.Time) error {
return nil
}
// SetReadDeadline is a stub
func (e *Endpoint) SetReadDeadline(time.Time) error {
return nil
}
// SetWriteDeadline is a stub
func (e *Endpoint) SetWriteDeadline(time.Time) error {
return nil
}