2013-07-16 08:54:42 +02:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// +build windows plan9
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
2015-10-31 01:59:47 +01:00
|
|
|
import "time"
|
2013-07-16 08:54:42 +02:00
|
|
|
|
2013-11-06 20:49:01 +01:00
|
|
|
// dialChannel is the simple pure-Go implementation of dial, still
|
|
|
|
// used on operating systems where the deadline hasn't been pushed
|
|
|
|
// down into the pollserver. (Plan 9 and some old versions of Windows)
|
|
|
|
func dialChannel(net string, ra Addr, dialer func(time.Time) (Conn, error), deadline time.Time) (Conn, error) {
|
2015-10-31 01:59:47 +01:00
|
|
|
if deadline.IsZero() {
|
|
|
|
return dialer(noDeadline)
|
2013-07-16 08:54:42 +02:00
|
|
|
}
|
2015-10-31 01:59:47 +01:00
|
|
|
timeout := deadline.Sub(time.Now())
|
2013-07-16 08:54:42 +02:00
|
|
|
if timeout <= 0 {
|
2015-10-31 01:59:47 +01:00
|
|
|
return nil, &OpError{Op: "dial", Net: net, Source: nil, Addr: ra, Err: errTimeout}
|
2013-07-16 08:54:42 +02:00
|
|
|
}
|
|
|
|
t := time.NewTimer(timeout)
|
|
|
|
defer t.Stop()
|
2013-11-06 20:49:01 +01:00
|
|
|
type racer struct {
|
2013-07-16 08:54:42 +02:00
|
|
|
Conn
|
|
|
|
error
|
|
|
|
}
|
2013-11-06 20:49:01 +01:00
|
|
|
ch := make(chan racer, 1)
|
2013-07-16 08:54:42 +02:00
|
|
|
go func() {
|
2015-10-31 01:59:47 +01:00
|
|
|
testHookDialChannel()
|
2013-11-06 20:49:01 +01:00
|
|
|
c, err := dialer(noDeadline)
|
|
|
|
ch <- racer{c, err}
|
2013-07-16 08:54:42 +02:00
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-t.C:
|
2015-10-31 01:59:47 +01:00
|
|
|
return nil, &OpError{Op: "dial", Net: net, Source: nil, Addr: ra, Err: errTimeout}
|
2013-11-06 20:49:01 +01:00
|
|
|
case racer := <-ch:
|
|
|
|
return racer.Conn, racer.error
|
2013-07-16 08:54:42 +02:00
|
|
|
}
|
|
|
|
}
|