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 commit11ba4f047f. * Revert "Revert "added time import"" This reverts commit984f179a63.
This commit is contained in:
9
conn.go
9
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user