func client(wg *sync.WaitGroup, host string, port, len int, duration time.Duration, chStat chan int) { defer func() { if r := recover(); r != nil { log.Printf("error: %s", r) } log.Printf("disconnected") wg.Done() }() log.Printf("connecting to %s:%d, len %d, duration %s", host, port, len, duration.String()) conn, err := utp.DialTimeout(fmt.Sprintf("%s:%d", host, port), time.Second) if err != nil { panic(err) } defer conn.Close() log.Printf("connected") buf := bytes.Repeat([]byte("H"), len) ts := time.Now() for time.Since(ts) < duration { n, err := conn.Write(buf) if err != nil { if err == io.EOF { break } panic(err) } chStat <- n } }
func (d *Dialer) Dial(rnet string, raddr string) (net.Conn, error) { if d.LocalAddr != nil { s, err := utp.NewSocket(d.LocalAddr.Network(), d.LocalAddr.String()) if err != nil { return nil, err } // zero timeout is the same as calling s.Dial() return s.DialTimeout(raddr, d.Timeout) } return utp.DialTimeout(raddr, d.Timeout) }