1
0
mirror of https://github.com/golang/go synced 2024-11-12 05:40:22 -07:00

net: never return -1 bytes read from netFD.Read

If the a network read would block, and a packet arrived just before the timeout expired, then the number of bytes from the previous (blocking) read, -1, would be returned.

This change restores the previous logic, where n would be unconditionally set to 0 if err != nil, but was skipped due to a change in CL 6851096.

The test for this change is CL 6851061.

R=bradfitz, mikioh.mikioh, dvyukov, rsc
CC=golang-dev
https://golang.org/cl/6852085
This commit is contained in:
Dave Cheney 2012-11-26 10:59:43 +11:00
parent f97bb12bb0
commit 73b3e2301e

View File

@ -431,6 +431,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) {
}
n, err = syscall.Read(int(fd.sysfd), p)
if err == syscall.EAGAIN {
n = 0
err = errTimeout
if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil {
@ -467,6 +468,7 @@ func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err error) {
}
n, sa, err = syscall.Recvfrom(fd.sysfd, p, 0)
if err == syscall.EAGAIN {
n = 0
err = errTimeout
if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil {
@ -501,6 +503,7 @@ func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
}
n, oobn, flags, sa, err = syscall.Recvmsg(fd.sysfd, p, oob, 0)
if err == syscall.EAGAIN {
n = 0
err = errTimeout
if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil {