Skip to content

Commit 81afa8a

Browse files
committed
netconn: Avoid returning 0, nil in NetConn.Read
Closes #367
1 parent a02cbef commit 81afa8a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

netconn.go

+13
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ func (nc *netConn) Read(p []byte) (int, error) {
141141
nc.readMu.forceLock()
142142
defer nc.readMu.unlock()
143143

144+
for {
145+
n, err := nc.read(p)
146+
if err != nil {
147+
return n, err
148+
}
149+
if n == 0 {
150+
continue
151+
}
152+
return n, nil
153+
}
154+
}
155+
156+
func (nc *netConn) read(p []byte) (int, error) {
144157
if atomic.LoadInt64(&nc.readExpired) == 1 {
145158
return 0, fmt.Errorf("failed to read: %w", context.DeadlineExceeded)
146159
}

0 commit comments

Comments
 (0)