forked from fedesog/webdriver
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.go
46 lines (41 loc) · 940 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2013 Federico Sogaro. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package webdriver
import (
"errors"
"fmt"
"net"
"runtime"
"time"
)
var debug = false
func debugprint(message interface{}) {
if debug {
pc, _, line, ok := runtime.Caller(1)
if ok {
f := runtime.FuncForPC(pc)
fmt.Printf("%s:%d: %v\n", f.Name(), line, message)
} else {
fmt.Printf("?:?: %s\n", message)
}
}
}
//probe d.Port until get a reply or timeout is up
func probePort(port int, timeout time.Duration) error {
address := fmt.Sprintf("127.0.0.1:%d", port)
now := time.Now()
for {
if conn, err := net.Dial("tcp", address); err == nil {
if err = conn.Close(); err != nil {
return err
}
break
}
if time.Since(now) > timeout {
return errors.New("start failed: timeout expired")
}
time.Sleep(1 * time.Second)
}
return nil
}