]> Cypherpunks repositories - gostls13.git/commitdiff
all: use time.Until where applicable
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 30 Aug 2016 01:05:18 +0000 (01:05 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 30 Aug 2016 01:23:46 +0000 (01:23 +0000)
Updates #14595

Change-Id: Idf60b3004c7a0ebb59dd48389ab62c854069e09f
Reviewed-on: https://go-review.googlesource.com/28073
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/context/context.go
src/crypto/tls/tls.go
src/net/fd_poll_runtime.go
src/net/http/client.go
src/net/http/serve_test.go

index f8ce9ccdb85254b38e7dbadb7163b62a793750a4..e40b63ef3cde5cc7cf0c8dc87f0b6782f9d7e93a 100644 (file)
@@ -376,7 +376,7 @@ func WithDeadline(parent Context, deadline time.Time) (Context, CancelFunc) {
                deadline:  deadline,
        }
        propagateCancel(parent, c)
-       d := deadline.Sub(time.Now())
+       d := time.Until(deadline)
        if d <= 0 {
                c.cancel(true, DeadlineExceeded) // deadline has already passed
                return c, func() { c.cancel(true, Canceled) }
@@ -406,7 +406,7 @@ func (c *timerCtx) Deadline() (deadline time.Time, ok bool) {
 }
 
 func (c *timerCtx) String() string {
-       return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, c.deadline.Sub(time.Now()))
+       return fmt.Sprintf("%v.WithDeadline(%s [%s])", c.cancelCtx.Context, c.deadline, time.Until(c.deadline))
 }
 
 func (c *timerCtx) cancel(removeFromParent bool, err error) {
index 8eef884a0f10eaeb4c18d69eb392c65a071350f6..e11e7dd5672184b81581c35dc671ebe0bcf3acda 100644 (file)
@@ -102,7 +102,7 @@ func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (*
        timeout := dialer.Timeout
 
        if !dialer.Deadline.IsZero() {
-               deadlineTimeout := dialer.Deadline.Sub(time.Now())
+               deadlineTimeout := time.Until(dialer.Deadline)
                if timeout == 0 || deadlineTimeout < timeout {
                        timeout = deadlineTimeout
                }
index bfa62c9f2d08d79bf6e9bcd3613eb89a7bbbcd7d..62b69fcbf150541304db4f6c116969ac82ddd3ad 100644 (file)
@@ -122,7 +122,7 @@ func (fd *netFD) setWriteDeadline(t time.Time) error {
 }
 
 func setDeadlineImpl(fd *netFD, t time.Time, mode int) error {
-       diff := int64(t.Sub(time.Now()))
+       diff := int64(time.Until(t))
        d := runtimeNano() + diff
        if d <= 0 && diff > 0 {
                // If the user has a deadline in the future, but the delay calculation
index 993c247eef536adcc3350ca208ce6613d7c4d191..58b584c8abe262dc4fd4309795d9088868a6e874 100644 (file)
@@ -324,7 +324,7 @@ func setRequestCancel(req *Request, rt RoundTripper, deadline time.Time) (stopTi
        var once sync.Once
        stopTimer = func() { once.Do(func() { close(stopTimerCh) }) }
 
-       timer := time.NewTimer(deadline.Sub(time.Now()))
+       timer := time.NewTimer(time.Until(deadline))
        go func() {
                select {
                case <-initialReqCancel:
index 3cfe57dd04844a07ff50e8863a2b38db323b7840..360d3a37b39043d6c459b3b2446cbebee5b7b533 100644 (file)
@@ -1737,7 +1737,7 @@ restart:
                if !c.rd.IsZero() {
                        // If the deadline falls in the middle of our sleep window, deduct
                        // part of the sleep, then return a timeout.
-                       if remaining := c.rd.Sub(time.Now()); remaining < cue {
+                       if remaining := time.Until(c.rd); remaining < cue {
                                c.script[0] = cue - remaining
                                time.Sleep(remaining)
                                return 0, syscall.ETIMEDOUT