mirror of
https://github.com/aler9/gortsplib
synced 2025-11-03 03:03:31 +08:00
multicast: add readOnly flag (#423)
This commit is contained in:
@@ -25,6 +25,7 @@ type MultiConn struct {
|
||||
// NewMultiConn allocates a MultiConn.
|
||||
func NewMultiConn(
|
||||
address string,
|
||||
readOnly bool,
|
||||
listenPacket func(network, address string) (net.PacketConn, error),
|
||||
) (Conn, error) {
|
||||
addr, err := net.ResolveUDPAddr("udp4", address)
|
||||
@@ -67,8 +68,12 @@ func NewMultiConn(
|
||||
return nil, fmt.Errorf("no multicast-capable interfaces found")
|
||||
}
|
||||
|
||||
writeConns := make([]*net.UDPConn, len(enabledInterfaces))
|
||||
writeConnIPs := make([]*ipv4.PacketConn, len(enabledInterfaces))
|
||||
var writeConns []*net.UDPConn
|
||||
var writeConnIPs []*ipv4.PacketConn
|
||||
|
||||
if !readOnly {
|
||||
writeConns = make([]*net.UDPConn, len(enabledInterfaces))
|
||||
writeConnIPs = make([]*ipv4.PacketConn, len(enabledInterfaces))
|
||||
|
||||
for i, intf := range enabledInterfaces {
|
||||
tmp, err := listenPacket("udp4", "224.0.0.0:"+strconv.FormatInt(int64(addr.Port), 10))
|
||||
@@ -104,6 +109,7 @@ func NewMultiConn(
|
||||
writeConns[i] = writeConn
|
||||
writeConnIPs[i] = writeConnIP
|
||||
}
|
||||
}
|
||||
|
||||
return &MultiConn{
|
||||
addr: addr,
|
||||
|
||||
@@ -24,6 +24,7 @@ type MultiConn struct {
|
||||
// NewMultiConn allocates a MultiConn.
|
||||
func NewMultiConn(
|
||||
address string,
|
||||
readOnly bool,
|
||||
_ func(network, address string) (net.PacketConn, error),
|
||||
) (Conn, error) {
|
||||
addr, err := net.ResolveUDPAddr("udp4", address)
|
||||
@@ -84,6 +85,10 @@ func NewMultiConn(
|
||||
return nil, fmt.Errorf("no multicast-capable interfaces found")
|
||||
}
|
||||
|
||||
var writeFiles []*os.File
|
||||
var writeConns []net.PacketConn
|
||||
|
||||
if !readOnly {
|
||||
writeSocks := make([]int, len(enabledInterfaces))
|
||||
|
||||
for i, intf := range enabledInterfaces {
|
||||
@@ -145,15 +150,17 @@ func NewMultiConn(
|
||||
writeSocks[i] = writeSock
|
||||
}
|
||||
|
||||
readFile := os.NewFile(uintptr(readSock), "")
|
||||
readConn, _ := net.FilePacketConn(readFile)
|
||||
writeFiles := make([]*os.File, len(writeSocks))
|
||||
writeConns := make([]net.PacketConn, len(writeSocks))
|
||||
writeFiles = make([]*os.File, len(writeSocks))
|
||||
writeConns = make([]net.PacketConn, len(writeSocks))
|
||||
|
||||
for i, writeSock := range writeSocks {
|
||||
writeFiles[i] = os.NewFile(uintptr(writeSock), "")
|
||||
writeConns[i], _ = net.FilePacketConn(writeFiles[i])
|
||||
}
|
||||
}
|
||||
|
||||
readFile := os.NewFile(uintptr(readSock), "")
|
||||
readConn, _ := net.FilePacketConn(readFile)
|
||||
|
||||
return &MultiConn{
|
||||
addr: addr,
|
||||
|
||||
@@ -76,7 +76,7 @@ func newServerUDPListener(
|
||||
var listenIP net.IP
|
||||
if multicastEnable {
|
||||
var err error
|
||||
pc, err = multicast.NewMultiConn(address, listenPacket)
|
||||
pc, err = multicast.NewMultiConn(address, false, listenPacket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user