Added TCP_TIMEOUT

Default tcp timeout 3minutes. change to optional in newCLAMDTcpConn
function.
This commit is contained in:
c1982
2015-04-10 22:01:56 +03:00
parent 1bb7549e07
commit 19466ba249

View File

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