Commit 73b3e230 authored by Dave Cheney's avatar Dave Cheney

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
parent f97bb12b
...@@ -431,6 +431,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) { ...@@ -431,6 +431,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) {
} }
n, err = syscall.Read(int(fd.sysfd), p) n, err = syscall.Read(int(fd.sysfd), p)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
n = 0
err = errTimeout err = errTimeout
if fd.rdeadline >= 0 { if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil { 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) { ...@@ -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) n, sa, err = syscall.Recvfrom(fd.sysfd, p, 0)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
n = 0
err = errTimeout err = errTimeout
if fd.rdeadline >= 0 { if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil { 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 ...@@ -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) n, oobn, flags, sa, err = syscall.Recvmsg(fd.sysfd, p, oob, 0)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
n = 0
err = errTimeout err = errTimeout
if fd.rdeadline >= 0 { if fd.rdeadline >= 0 {
if err = fd.pollServer.WaitRead(fd); err == nil { if err = fd.pollServer.WaitRead(fd); err == nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment