diff --git a/conn.go b/conn.go index df83253..d2a7464 100644 --- a/conn.go +++ b/conn.go @@ -35,6 +35,7 @@ import ( ) const CHUNK_SIZE = 1024 +const TCP_TIMEOUT = time.Second * 2 type CLAMDConn struct { net.Conn @@ -111,8 +112,13 @@ func (c *CLAMDConn) readResponse() (chan string, sync.WaitGroup, error) { } func newCLAMDTcpConn(address string) (*CLAMDConn, error) { - conn, err := net.Dial("tcp", address) + conn, err := net.DialTimeout("tcp", address, TCP_TIMEOUT) + if err != nil { + if nerr, isOk := err.(net.Error); isOk && nerr.Timeout() { + return nil, nerr + } + return nil, err }