-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathendpoint_server.go
More file actions
69 lines (53 loc) · 1.12 KB
/
endpoint_server.go
File metadata and controls
69 lines (53 loc) · 1.12 KB
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
package gomavlib
import (
"fmt"
"io"
"net"
"github.com/bluenviron/gomavlib/v3/pkg/timednetconn"
)
type endpointServer struct {
node *Node
conf EndpointCustomServer
listener net.Listener
// in
terminate chan struct{}
}
func (e *endpointServer) initialize() error {
var err error
e.listener, err = e.conf.Listen()
if err != nil {
return err
}
e.terminate = make(chan struct{})
return nil
}
func (e *endpointServer) isEndpoint() {}
func (e *endpointServer) Conf() EndpointConf {
return e.conf
}
func (e *endpointServer) close() {
close(e.terminate)
e.listener.Close()
}
func (e *endpointServer) oneChannelAtAtime() bool {
return false
}
func (e *endpointServer) provide() (string, io.ReadWriteCloser, error) {
nconn, err := e.listener.Accept()
// wait termination, do not report errors
if err != nil {
<-e.terminate
return "", nil, errTerminated
}
label := fmt.Sprintf("%s:%s", func() string {
if e.conf.Label != "" {
return e.conf.Label
}
return "custom"
}(), nconn.RemoteAddr())
conn := timednetconn.New(
e.node.IdleTimeout,
e.node.WriteTimeout,
nconn)
return label, conn, nil
}