Skip to content

Commit

Permalink
Replace pool with bytes in readLoop
Browse files Browse the repository at this point in the history
Replace pool with bytes in readLoop
  • Loading branch information
cnderrauber committed Apr 24, 2024
1 parent a9e88d2 commit d851a44
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions datachannel.go
Expand Up @@ -349,18 +349,11 @@ func (d *DataChannel) onError(err error) {
}
}

// See https://github.com/pion/webrtc/issues/1516
// nolint:gochecknoglobals
var rlBufPool = sync.Pool{New: func() interface{} {
return make([]byte, dataChannelBufferSize)
}}

func (d *DataChannel) readLoop() {
buffer := make([]byte, dataChannelBufferSize)
for {
buffer := rlBufPool.Get().([]byte) //nolint:forcetypeassert
n, isString, err := d.dataChannel.ReadDataChannel(buffer)
if err != nil {
rlBufPool.Put(buffer) // nolint:staticcheck
d.setReadyState(DataChannelStateClosed)
if !errors.Is(err, io.EOF) {
d.onError(err)
Expand All @@ -371,8 +364,6 @@ func (d *DataChannel) readLoop() {

m := DataChannelMessage{Data: make([]byte, n), IsString: isString}
copy(m.Data, buffer[:n])
// The 'staticcheck' pragma is a false positive on the part of the CI linter.
rlBufPool.Put(buffer) // nolint:staticcheck

// NB: Why was DataChannelMessage not passed as a pointer value?
d.onMessage(m) // nolint:staticcheck
Expand Down

0 comments on commit d851a44

Please sign in to comment.