1
0
mirror of https://github.com/golang/go synced 2024-10-04 11:21:21 -06:00
go/src/net/dial_gen.go
Mikio Hara afd2d2b6df net: add Source field to OpError
Not only by network, transport-layer intermediaries but by
virtualization stuff in a node, it is hard to identify the root cause of
weird faults without information of packet flows after disaster
happened.

This change adds Source field to OpError to be able to represent a
5-tuple of internet transport protocols for helping dealing with
complicated systems.

Also clarifies the usage of Source and Addr fields.

Updates #4856.

Change-Id: I96a523fe391ed14406bfb21604c461d4aac2fa19
Reviewed-on: https://go-review.googlesource.com/9231
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-04-29 22:37:30 +00:00

41 lines
1.1 KiB
Go

// 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
import "time"
// 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) {
if deadline.IsZero() {
return dialer(noDeadline)
}
timeout := deadline.Sub(time.Now())
if timeout <= 0 {
return nil, &OpError{Op: "dial", Net: net, Source: nil, Addr: ra, Err: errTimeout}
}
t := time.NewTimer(timeout)
defer t.Stop()
type racer struct {
Conn
error
}
ch := make(chan racer, 1)
go func() {
testHookDialChannel()
c, err := dialer(noDeadline)
ch <- racer{c, err}
}()
select {
case <-t.C:
return nil, &OpError{Op: "dial", Net: net, Source: nil, Addr: ra, Err: errTimeout}
case racer := <-ch:
return racer.Conn, racer.error
}
}