forked from bluenviron/mediamtx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-tcpl.go
52 lines (41 loc) · 824 Bytes
/
server-tcpl.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 main
import (
"net"
)
type serverTcpListener struct {
p *program
nconn *net.TCPListener
done chan struct{}
}
func newServerTcpListener(p *program) (*serverTcpListener, error) {
nconn, err := net.ListenTCP("tcp", &net.TCPAddr{
Port: p.conf.RtspPort,
})
if err != nil {
return nil, err
}
l := &serverTcpListener{
p: p,
nconn: nconn,
done: make(chan struct{}),
}
l.log("opened on :%d", p.conf.RtspPort)
return l, nil
}
func (l *serverTcpListener) log(format string, args ...interface{}) {
l.p.log("[TCP listener] "+format, args...)
}
func (l *serverTcpListener) run() {
for {
nconn, err := l.nconn.AcceptTCP()
if err != nil {
break
}
l.p.events <- programEventClientNew{nconn}
}
close(l.done)
}
func (l *serverTcpListener) close() {
l.nconn.Close()
<-l.done
}