ServerUDPListener: set writeTimeout once

This commit is contained in:
aler9
2021-01-07 21:07:51 +01:00
parent 0680ffa9a3
commit 87bd5bde32
3 changed files with 9 additions and 5 deletions

View File

@@ -37,7 +37,10 @@ func newServer(conf ServerConf, address string) (*Server, error) {
if conf.UDPRTPListener != nil {
conf.UDPRTPListener.streamType = StreamTypeRTP
conf.UDPRTPListener.writeTimeout = conf.WriteTimeout
conf.UDPRTCPListener.streamType = StreamTypeRTCP
conf.UDPRTCPListener.writeTimeout = conf.WriteTimeout
}
listener, err := conf.Listen("tcp", address)

View File

@@ -809,14 +809,14 @@ func (sc *ServerConn) WriteFrame(trackID int, streamType StreamType, payload []b
track := sc.tracks[trackID]
if streamType == StreamTypeRTP {
return sc.conf.UDPRTPListener.write(sc.conf.WriteTimeout, payload, &net.UDPAddr{
return sc.conf.UDPRTPListener.write(payload, &net.UDPAddr{
IP: sc.ip(),
Zone: sc.zone(),
Port: track.rtpPort,
})
}
return sc.conf.UDPRTCPListener.write(sc.conf.WriteTimeout, payload, &net.UDPAddr{
return sc.conf.UDPRTCPListener.write(payload, &net.UDPAddr{
IP: sc.ip(),
Zone: sc.zone(),
Port: track.rtcpPort,

View File

@@ -39,7 +39,8 @@ func (p *publisherAddr) fill(ip net.IP, port int) {
// ServerUDPListener is a UDP server that can be used to send and receive RTP and RTCP packets.
type ServerUDPListener struct {
streamType StreamType
streamType StreamType
writeTimeout time.Duration
pc *net.UDPConn
readBuf *multibuffer.MultiBuffer
@@ -116,11 +117,11 @@ func (s *ServerUDPListener) port() int {
return s.pc.LocalAddr().(*net.UDPAddr).Port
}
func (s *ServerUDPListener) write(writeTimeout time.Duration, buf []byte, addr *net.UDPAddr) error {
func (s *ServerUDPListener) write(buf []byte, addr *net.UDPAddr) error {
s.writeMutex.Lock()
defer s.writeMutex.Unlock()
s.pc.SetWriteDeadline(time.Now().Add(writeTimeout))
s.pc.SetWriteDeadline(time.Now().Add(s.writeTimeout))
_, err := s.pc.WriteTo(buf, addr)
return err
}