mirror of
https://github.com/pion/webrtc.git
synced 2025-09-26 19:21:12 +08:00
Prefer makezero with a cap
This commit is contained in:
@@ -202,14 +202,14 @@ func (m *Mux) handlePendingPackets(endpoint *Endpoint, matchFunc MatchFunc) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
pendingPackets := make([][]byte, len(m.pendingPackets))
|
||||
pendingPackets := make([][]byte, 0, len(m.pendingPackets))
|
||||
for _, buf := range m.pendingPackets {
|
||||
if matchFunc(buf) {
|
||||
if _, err := endpoint.buffer.Write(buf); err != nil {
|
||||
m.log.Warnf("Warning: mux: error writing packet to endpoint from pending queue: %s", err)
|
||||
}
|
||||
} else {
|
||||
pendingPackets = append(pendingPackets, buf) //nolint:makezero // todo fix
|
||||
pendingPackets = append(pendingPackets, buf)
|
||||
}
|
||||
}
|
||||
m.pendingPackets = pendingPackets
|
||||
|
@@ -2414,7 +2414,7 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc
|
||||
// 2. A Mux stops this chain. It won't close the underlying
|
||||
// Conn if one of the endpoints is closed down. To
|
||||
// continue the chain the Mux has to be closed.
|
||||
closeErrs := make([]error, 4)
|
||||
closeErrs := make([]error, 0, 4)
|
||||
|
||||
doGracefulCloseOps := func() []error {
|
||||
if !shouldGracefullyClose {
|
||||
@@ -2448,10 +2448,10 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4)
|
||||
pc.mu.Lock()
|
||||
for _, t := range pc.rtpTransceivers {
|
||||
closeErrs = append(closeErrs, t.Stop()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, t.Stop())
|
||||
}
|
||||
if nonMediaBandwidthProbe, ok := pc.nonMediaBandwidthProbe.Load().(*RTPReceiver); ok {
|
||||
closeErrs = append(closeErrs, nonMediaBandwidthProbe.Stop()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, nonMediaBandwidthProbe.Stop())
|
||||
}
|
||||
pc.mu.Unlock()
|
||||
|
||||
@@ -2464,28 +2464,28 @@ func (pc *PeerConnection) close(shouldGracefullyClose bool) error { //nolint:cyc
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #6)
|
||||
if pc.sctpTransport != nil {
|
||||
closeErrs = append(closeErrs, pc.sctpTransport.Stop()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, pc.sctpTransport.Stop())
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #7)
|
||||
closeErrs = append(closeErrs, pc.dtlsTransport.Stop()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, pc.dtlsTransport.Stop())
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8, #9, #10)
|
||||
if pc.iceTransport != nil && !shouldGracefullyClose {
|
||||
// we will stop gracefully in doGracefulCloseOps
|
||||
closeErrs = append(closeErrs, pc.iceTransport.Stop()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, pc.iceTransport.Stop())
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #11)
|
||||
pc.updateConnectionState(pc.ICEConnectionState(), pc.dtlsTransport.State())
|
||||
|
||||
closeErrs = append(closeErrs, doGracefulCloseOps()...) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, doGracefulCloseOps()...)
|
||||
|
||||
pc.statsGetter = nil
|
||||
cleanupStats(pc.statsID)
|
||||
|
||||
// Interceptor closes at the end to prevent Bind from being called after interceptor is closed
|
||||
closeErrs = append(closeErrs, pc.api.interceptor.Close()) //nolint:makezero // todo fix
|
||||
closeErrs = append(closeErrs, pc.api.interceptor.Close())
|
||||
|
||||
return util.FlattenErrs(closeErrs)
|
||||
}
|
||||
|
Reference in New Issue
Block a user