From f70f574e61d3f951fcd360c7bff0d0bd8209fd8c Mon Sep 17 00:00:00 2001 From: Dolf Schimmel Date: Sun, 3 Apr 2016 00:14:08 +0200 Subject: [PATCH] Added TCP_TIMEOUT * Added TCP_TIMEOUT Default tcp timeout 3minutes. change to optional in newCLAMDTcpConn function. * added time import * Revert "added time import" This reverts commit 11ba4f047f100cfc20261ca5376f91ffa5ec5436. * Revert "Revert "added time import"" This reverts commit 984f179a6338b2ee3e44e2ba98d99af4c6886b53. --- conn.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index df83253..32da3a8 100644 --- a/conn.go +++ b/conn.go @@ -32,9 +32,11 @@ import ( "net" "strings" "sync" + "time" ) const CHUNK_SIZE = 1024 +const TCP_TIMEOUT = time.Second * 2 type CLAMDConn struct { net.Conn @@ -111,8 +113,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 }