FAQ
Reviewers: jsing, bradfitz, mikio, rsc,

Message:
Hello jsing@google.com, bradfitz@golang.org, mikioh.mikioh@gmail.com,
rsc@golang.org (cc: fullung@gmail.com, golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go


Description:
net: move deadline logic into pollServer

Update issue 4434.

The proposal attempts to reduce the number of places where
fd,{r,w}deadline is checked and updated in preparation for issue 4434.
In doing so the deadline logic is simplified by letting the pollster
return errTimeout from netFD.Wait{Read,Write} as part of the wakeup
logic.

The behaviour of setting n = 0 has been restored to match rev
2a55e349097f, which was the previous change to fd_unix.go before CL
6851096.

Please review this at http://codereview.appspot.com/6850110/

Affected files:
M src/pkg/net/fd_unix.go


Index: src/pkg/net/fd_unix.go
===================================================================
--- a/src/pkg/net/fd_unix.go
+++ b/src/pkg/net/fd_unix.go
@@ -181,12 +181,10 @@
delete(s.pending, key)
if mode == 'r' {
s.poll.DelFD(fd.sysfd, mode)
- fd.rdeadline = -1
} else {
s.poll.DelFD(fd.sysfd, mode)
- fd.wdeadline = -1
}
- s.WakeFD(fd, mode, nil)
+ s.WakeFD(fd, mode, errTimeout)
} else if nextDeadline == 0 || t < nextDeadline {
nextDeadline = t
}
@@ -329,14 +327,10 @@

func (fd *netFD) connect(ra syscall.Sockaddr) error {
err := syscall.Connect(fd.sysfd, ra)
- hadTimeout := fd.wdeadline > 0
if err == syscall.EINPROGRESS {
if err = fd.pollServer.WaitWrite(fd); err != nil {
return err
}
- if hadTimeout && fd.wdeadline < 0 {
- return errTimeout
- }
var e int
e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET,
syscall.SO_ERROR)
if err != nil {
@@ -430,18 +424,15 @@
}
}
n, err = syscall.Read(int(fd.sysfd), p)
- if err == syscall.EAGAIN {
+ if err != nil {
n = 0
- err = errTimeout
- if fd.rdeadline >= 0 {
+ if err == syscall.EAGAIN {
if err = fd.pollServer.WaitRead(fd); err == nil {
continue
}
}
}
- if err != nil {
- n = 0
- } else if n == 0 && err == nil && fd.sotype != syscall.SOCK_DGRAM {
+ if n == 0 && err == nil && fd.sotype != syscall.SOCK_DGRAM {
err = io.EOF
}
break
@@ -467,18 +458,14 @@
}
}
n, sa, err = syscall.Recvfrom(fd.sysfd, p, 0)
- if err == syscall.EAGAIN {
+ if err != nil {
n = 0
- err = errTimeout
- if fd.rdeadline >= 0 {
+ if err == syscall.EAGAIN {
if err = fd.pollServer.WaitRead(fd); err == nil {
continue
}
}
}
- if err != nil {
- n = 0
- }
break
}
if err != nil && err != io.EOF {
@@ -502,10 +489,9 @@
}
}
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 != nil {
+ // TODO(dfc) should n and oobn be set to nil
+ if err == syscall.EAGAIN {
if err = fd.pollServer.WaitRead(fd); err == nil {
continue
}
@@ -518,7 +504,6 @@
}
if err != nil && err != io.EOF {
err = &OpError{"read", fd.net, fd.laddr, err}
- return
}
return
}
@@ -548,11 +533,8 @@
break
}
if err == syscall.EAGAIN {
- err = errTimeout
- if fd.wdeadline >= 0 {
- if err = fd.pollServer.WaitWrite(fd); err == nil {
- continue
- }
+ if err = fd.pollServer.WaitWrite(fd); err == nil {
+ continue
}
}
if err != nil {
@@ -586,11 +568,8 @@
}
err = syscall.Sendto(fd.sysfd, p, 0, sa)
if err == syscall.EAGAIN {
- err = errTimeout
- if fd.wdeadline >= 0 {
- if err = fd.pollServer.WaitWrite(fd); err == nil {
- continue
- }
+ if err = fd.pollServer.WaitWrite(fd); err == nil {
+ continue
}
}
break
@@ -619,11 +598,8 @@
}
err = syscall.Sendmsg(fd.sysfd, p, oob, sa, 0)
if err == syscall.EAGAIN {
- err = errTimeout
- if fd.wdeadline >= 0 {
- if err = fd.pollServer.WaitWrite(fd); err == nil {
- continue
- }
+ if err = fd.pollServer.WaitWrite(fd); err == nil {
+ continue
}
}
break
@@ -654,11 +630,8 @@
if err != nil {
syscall.ForkLock.RUnlock()
if err == syscall.EAGAIN {
- err = errTimeout
- if fd.rdeadline >= 0 {
- if err = fd.pollServer.WaitRead(fd); err == nil {
- continue
- }
+ if err = fd.pollServer.WaitRead(fd); err == nil {
+ continue
}
} else if err == syscall.ECONNABORTED {
// This means that a socket on the listen queue was closed

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 27, '12 at 9:18a
activeNov 28, '12 at 1:23a
posts15
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase