Thank you for your comments and your testing. In order to resolve the
changes to sockopt_posix.go I have converted fd_windows.go to use a
deadline type. Other solutions exist, but they probably mean more code
duplication. If it turns out that the same race exists on Windows as it
does in Unix, then resolving it would be simple.
// TODO(dfc) I'd be interested in merging the common fields and methods
from fd_unix.go:netFD and fd_windows.go:netFD
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.goFile src/pkg/net/fd_unix.go (right):
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode44src/pkg/net/fd_unix.go:44: // read and write deadlines (nsec since 1970
or 0 if not set)
On 2012/11/28 14:21:03, bradfitz wrote:
I'd move the parenthetical part to the deadline type's docs
Done.
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode54src/pkg/net/fd_unix.go:54: type deadline struct {
On 2012/11/28 14:21:03, bradfitz wrote:
no need for the struct. just:
// deadline is an atomically-accessed number of nanoseconds since 1970
// or 0, if no deadline is set.
type deadline int64
Done. Originally having this as a struct allowed me to find all the
places in the code (like sendfile_linux.go) where fd.{r,w}deadline was
being accessed.
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode63src/pkg/net/fd_unix.go:63: func (d *deadline) set(v int64) {
On 2012/11/28 14:21:03, bradfitz wrote:
also add
func (d *deadline) setTime(t time.Time) {
if t.IsZero() {
d.set(0)
} else {
d.set(t.UnixNano())
}
}
Done.
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode213src/pkg/net/fd_unix.go:213: t = t - time.Now().UnixNano()
On 2012/11/28 14:21:03, bradfitz wrote:
make a new variable for this now.
time.Time is a deadline, which can use variable "t".
a timeout is a time.Duration, which shouldn't use "t".
no need to stay in pre-Go1 int64 world here just because that's when this code
was written.
Actually the logic is a little tricky, t is use later int the method,
i've renamed t to deadline, PTAL.
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode617src/pkg/net/fd_unix.go:617: if t.IsZero() {
On 2012/11/28 14:21:03, bradfitz wrote:
these can be both simplified now with fd.[rw]deadline.setTime(t)
Done. I have added a TODO to see if can be further improved.
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/fd_unix.go#newcode635src/pkg/net/fd_unix.go:635: if err := setReadDeadline(fd, t); err != nil
{
On 2012/11/28 14:21:03, bradfitz wrote:
unnecessary err check. I'd just do:
fd.rdeadline.setTime(t)
fd.wdeadline.setTime(t)
return nil
Done, see above, I want to make this simpler in general
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/sockopt_posix.goFile src/pkg/net/sockopt_posix.go (left):
https://codereview.appspot.com/6855110/diff/8001/src/pkg/net/sockopt_posix.go#oldcode122src/pkg/net/sockopt_posix.go:122: func setReadDeadline(fd *netFD, t
time.Time) error {
On 2012/11/28 10:29:34, dvyukov wrote:
This was also used for windows. Windows build will be broken with this
change.
Done.
https://codereview.appspot.com/6855110/