From 73b3e2301ebbaa4f940006b0869a158156613b4b Mon Sep 17 00:00:00 2001 From: Dave Cheney Date: Mon, 26 Nov 2012 10:59:43 +1100 Subject: [PATCH] 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 --- src/pkg/net/fd_unix.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pkg/net/fd_unix.go b/src/pkg/net/fd_unix.go index 16da53f0f5..19d3ac9fe0 100644 --- a/src/pkg/net/fd_unix.go +++ b/src/pkg/net/fd_unix.go @@ -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 {