doChecks executes and returns each attempt.
()
| 66 | |
| 67 | // doChecks executes and returns each attempt. |
| 68 | func (c Checker) doChecks() types.Attempts { |
| 69 | var conn net.Conn |
| 70 | |
| 71 | timeout := c.Timeout |
| 72 | if timeout == 0 { |
| 73 | timeout = 1 * time.Second |
| 74 | } |
| 75 | |
| 76 | checks := make(types.Attempts, c.Attempts) |
| 77 | for i := 0; i < c.Attempts; i++ { |
| 78 | var err error |
| 79 | start := time.Now() |
| 80 | |
| 81 | if c.Host != "" { |
| 82 | hostname := c.Host |
| 83 | m1 := new(dns.Msg) |
| 84 | m1.Id = dns.Id() |
| 85 | m1.RecursionDesired = true |
| 86 | m1.Question = make([]dns.Question, 1) |
| 87 | m1.Question[0] = dns.Question{Name: hostname, Qtype: dns.TypeA, Qclass: dns.ClassINET} |
| 88 | d := new(dns.Client) |
| 89 | _, _, err := d.Exchange(m1, c.URL) |
| 90 | if err != nil { |
| 91 | checks[i].Error = err.Error() |
| 92 | continue |
| 93 | } |
| 94 | } |
| 95 | if conn, err = net.DialTimeout("tcp", c.URL, c.Timeout); err != nil { |
| 96 | checks[i].Error = err.Error() |
| 97 | } else { |
| 98 | conn.Close() |
| 99 | } |
| 100 | checks[i].RTT = time.Since(start) |
| 101 | } |
| 102 | return checks |
| 103 | } |
| 104 | |
| 105 | // conclude takes the data in result from the attempts and |
| 106 | // computes remaining values needed to fill out the result. |