Use DialTimeout.

This commit is contained in:
Vladimir Mihailenco 2012-10-26 18:21:14 +03:00
parent 1fa1eee592
commit 096f017b69
1 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"net"
"os"
"sync"
"time"
)
// Package logger.
@ -17,13 +18,17 @@ type InitConnFunc func(*Client) error
func TCPConnector(addr string) OpenConnFunc {
return func() (net.Conn, error) {
return net.Dial("tcp", addr)
return net.DialTimeout("tcp", addr, 3*time.Second)
}
}
func TLSConnector(addr string, tlsConfig *tls.Config) OpenConnFunc {
return func() (net.Conn, error) {
return tls.Dial("tcp", addr, tlsConfig)
conn, err := net.DialTimeout("tcp", addr, 3*time.Second)
if err != nil {
return nil, err
}
return tls.Client(conn, tlsConfig)
}
}