Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170)

Delta Between Two Patch Sets: src/pkg/net/dial_gen.go

Issue 9315043: code review 9315043: [release-branch.go1.1] net: fix dial race on plan9 and ... (Closed)
Left Patch Set: Created 11 years, 10 months ago
Right Patch Set: diff -r 9e1dac980adb https://code.google.com/p/go Created 11 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/net/dial_gen_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2012 The Go Authors. All rights reserved. 1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build windows plan9 5 // +build windows plan9
6 6
7 package net 7 package net
8 8
9 import ( 9 import (
10 "time" 10 "time"
11 ) 11 )
12 12
13 var testingIssue5349 bool // used during tests
14
13 // resolveAndDialChannel is the simple pure-Go implementation of 15 // resolveAndDialChannel is the simple pure-Go implementation of
14 // resolveAndDial, still used on operating systems where the deadline 16 // resolveAndDial, still used on operating systems where the deadline
15 // hasn't been pushed down into the pollserver. (Plan 9 and some old 17 // hasn't been pushed down into the pollserver. (Plan 9 and some old
16 // versions of Windows) 18 // versions of Windows)
17 func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) { 19 func resolveAndDialChannel(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) {
18 » timeout := deadline.Sub(time.Now()) 20 » var timeout time.Duration
19 » if timeout < 0 { 21 » if !deadline.IsZero() {
20 » » timeout = 0 22 » » timeout = deadline.Sub(time.Now())
23 » }
24 » if timeout <= 0 {
25 » » ra, err := resolveAddr("dial", net, addr, noDeadline)
26 » » if err != nil {
27 » » » return nil, err
28 » » }
29 » » return dial(net, addr, localAddr, ra, noDeadline)
21 } 30 }
22 t := time.NewTimer(timeout) 31 t := time.NewTimer(timeout)
23 defer t.Stop() 32 defer t.Stop()
24 type pair struct { 33 type pair struct {
25 Conn 34 Conn
26 error 35 error
27 } 36 }
28 ch := make(chan pair, 1) 37 ch := make(chan pair, 1)
29 resolvedAddr := make(chan Addr, 1) 38 resolvedAddr := make(chan Addr, 1)
30 go func() { 39 go func() {
40 if testingIssue5349 {
41 time.Sleep(time.Millisecond)
42 }
31 ra, err := resolveAddr("dial", net, addr, noDeadline) 43 ra, err := resolveAddr("dial", net, addr, noDeadline)
32 if err != nil { 44 if err != nil {
33 ch <- pair{nil, err} 45 ch <- pair{nil, err}
34 return 46 return
35 } 47 }
36 resolvedAddr <- ra // in case we need it for OpError 48 resolvedAddr <- ra // in case we need it for OpError
37 c, err := dial(net, addr, localAddr, ra, noDeadline) 49 c, err := dial(net, addr, localAddr, ra, noDeadline)
38 ch <- pair{c, err} 50 ch <- pair{c, err}
39 }() 51 }()
40 select { 52 select {
(...skipping 11 matching lines...) Expand all
52 Op: "dial", 64 Op: "dial",
53 Net: net, 65 Net: net,
54 Addr: ra, 66 Addr: ra,
55 Err: &timeoutError{}, 67 Err: &timeoutError{},
56 } 68 }
57 return nil, err 69 return nil, err
58 case p := <-ch: 70 case p := <-ch:
59 return p.Conn, p.error 71 return p.Conn, p.error
60 } 72 }
61 } 73 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b