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 11ba4f047f.

* Revert "Revert "added time import""

This reverts commit 984f179a63.
This commit is contained in:
Dolf Schimmel
2016-04-03 00:14:08 +02:00
parent 1bb7549e07
commit f70f574e61

View File

@@ -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
}