mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 11:32:19 +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()
|
m.lock.Lock()
|
||||||
defer m.lock.Unlock()
|
defer m.lock.Unlock()
|
||||||
|
|
||||||
pendingPackets := make([][]byte, len(m.pendingPackets))
|
pendingPackets := make([][]byte, 0, len(m.pendingPackets))
|
||||||
for _, buf := range m.pendingPackets {
|
for _, buf := range m.pendingPackets {
|
||||||
if matchFunc(buf) {
|
if matchFunc(buf) {
|
||||||
if _, err := endpoint.buffer.Write(buf); err != nil {
|
if _, err := endpoint.buffer.Write(buf); err != nil {
|
||||||
m.log.Warnf("Warning: mux: error writing packet to endpoint from pending queue: %s", err)
|
m.log.Warnf("Warning: mux: error writing packet to endpoint from pending queue: %s", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pendingPackets = append(pendingPackets, buf) //nolint:makezero // todo fix
|
pendingPackets = append(pendingPackets, buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.pendingPackets = pendingPackets
|
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
|
// 2. A Mux stops this chain. It won't close the underlying
|
||||||
// Conn if one of the endpoints is closed down. To
|
// Conn if one of the endpoints is closed down. To
|
||||||
// continue the chain the Mux has to be closed.
|
// continue the chain the Mux has to be closed.
|
||||||
closeErrs := make([]error, 4)
|
closeErrs := make([]error, 0, 4)
|
||||||
|
|
||||||
doGracefulCloseOps := func() []error {
|
doGracefulCloseOps := func() []error {
|
||||||
if !shouldGracefullyClose {
|
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)
|
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4)
|
||||||
pc.mu.Lock()
|
pc.mu.Lock()
|
||||||
for _, t := range pc.rtpTransceivers {
|
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 {
|
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()
|
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)
|
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #6)
|
||||||
if pc.sctpTransport != nil {
|
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)
|
// 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)
|
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8, #9, #10)
|
||||||
if pc.iceTransport != nil && !shouldGracefullyClose {
|
if pc.iceTransport != nil && !shouldGracefullyClose {
|
||||||
// we will stop gracefully in doGracefulCloseOps
|
// 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)
|
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #11)
|
||||||
pc.updateConnectionState(pc.ICEConnectionState(), pc.dtlsTransport.State())
|
pc.updateConnectionState(pc.ICEConnectionState(), pc.dtlsTransport.State())
|
||||||
|
|
||||||
closeErrs = append(closeErrs, doGracefulCloseOps()...) //nolint:makezero // todo fix
|
closeErrs = append(closeErrs, doGracefulCloseOps()...)
|
||||||
|
|
||||||
pc.statsGetter = nil
|
pc.statsGetter = nil
|
||||||
cleanupStats(pc.statsID)
|
cleanupStats(pc.statsID)
|
||||||
|
|
||||||
// Interceptor closes at the end to prevent Bind from being called after interceptor is closed
|
// 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)
|
return util.FlattenErrs(closeErrs)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user