Skip to content

Commit

Permalink
Add closed handling in heartbeat read
Browse files Browse the repository at this point in the history
mingyech committed Feb 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 6b779e2 commit 6ede634
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/dtls/heartbeat.go
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package dtls
import (
"bytes"
"errors"
"net"
"sync"
"sync/atomic"
"time"
@@ -101,18 +102,22 @@ func (c *hbConn) Write(b []byte) (n int, err error) {
}

func (c *hbConn) Read(b []byte) (int, error) {
readBytes := <-c.recvCh
if readBytes.err != nil {
return 0, readBytes.err
}
select {
case <-c.closed:
return 0, net.ErrClosed
case readBytes := <-c.recvCh:
if readBytes.err != nil {
return 0, readBytes.err
}

if len(b) < len(readBytes.b) {
return 0, ErrInsufficientBuffer
}
if len(b) < len(readBytes.b) {
return 0, ErrInsufficientBuffer
}

n := copy(b, readBytes.b)
n := copy(b, readBytes.b)

return n, nil
return n, nil
}
}

func (c *hbConn) BufferedAmount() uint64 {

0 comments on commit 6ede634

Please sign in to comment.