Skip to content

Commit

Permalink
netconn: Avoid returning 0, nil in NetConn.Read
Browse files Browse the repository at this point in the history
Closes #367
  • Loading branch information
nhooyr committed Oct 13, 2023
1 parent a02cbef commit 81afa8a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions netconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ func (nc *netConn) Read(p []byte) (int, error) {
nc.readMu.forceLock()
defer nc.readMu.unlock()

for {
n, err := nc.read(p)
if err != nil {
return n, err
}
if n == 0 {
continue
}
return n, nil
}
}

func (nc *netConn) read(p []byte) (int, error) {
if atomic.LoadInt64(&nc.readExpired) == 1 {
return 0, fmt.Errorf("failed to read: %w", context.DeadlineExceeded)
}
Expand Down

0 comments on commit 81afa8a

Please sign in to comment.