~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/net/dial.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        // destination is a host name that has multiple address family
45
45
        // DNS records.
46
46
        DualStack bool
 
47
 
 
48
        // KeepAlive specifies the keep-alive period for an active
 
49
        // network connection.
 
50
        // If zero, keep-alives are not enabled. Network protocols
 
51
        // that do not support keep-alives ignore this field.
 
52
        KeepAlive time.Duration
47
53
}
48
54
 
49
55
// Return either now+Timeout or Deadline, whichever comes first.
162
168
                        return dialMulti(network, address, d.LocalAddr, ras, deadline)
163
169
                }
164
170
        }
165
 
        return dial(network, ra.toAddr(), dialer, d.deadline())
 
171
        c, err := dial(network, ra.toAddr(), dialer, d.deadline())
 
172
        if d.KeepAlive > 0 && err == nil {
 
173
                if tc, ok := c.(*TCPConn); ok {
 
174
                        tc.SetKeepAlive(true)
 
175
                        tc.SetKeepAlivePeriod(d.KeepAlive)
 
176
                        testHookSetKeepAlive()
 
177
                }
 
178
        }
 
179
        return c, err
166
180
}
167
181
 
 
182
var testHookSetKeepAlive = func() {} // changed by dial_test.go
 
183
 
168
184
// dialMulti attempts to establish connections to each destination of
169
185
// the list of addresses. It will return the first established
170
186
// connection and close the other connections. Otherwise it returns
172
188
func dialMulti(net, addr string, la Addr, ras addrList, deadline time.Time) (Conn, error) {
173
189
        type racer struct {
174
190
                Conn
175
 
                Addr
176
191
                error
177
192
        }
178
193
        // Sig controls the flow of dial results on lane. It passes a
184
199
                go func(ra Addr) {
185
200
                        c, err := dialSingle(net, addr, la, ra, deadline)
186
201
                        if _, ok := <-sig; ok {
187
 
                                lane <- racer{c, ra, err}
 
202
                                lane <- racer{c, err}
188
203
                        } else if err == nil {
189
204
                                // We have to return the resources
190
205
                                // that belong to the other
195
210
                }(ra.toAddr())
196
211
        }
197
212
        defer close(sig)
198
 
        var failAddr Addr
199
213
        lastErr := errTimeout
200
214
        nracers := len(ras)
201
215
        for nracers > 0 {
205
219
                        if racer.error == nil {
206
220
                                return racer.Conn, nil
207
221
                        }
208
 
                        failAddr = racer.Addr
209
222
                        lastErr = racer.error
210
223
                        nracers--
211
224
                }
212
225
        }
213
 
        return nil, &OpError{Op: "dial", Net: net, Addr: failAddr, Err: lastErr}
 
226
        return nil, lastErr
214
227
}
215
228
 
216
229
// dialSingle attempts to establish and returns a single connection to