Changed net.Dial to net.DialTimeout to allow adding a reasonable timeout. Also fixed a small typo

This commit is contained in:
Peter
2015-05-19 23:53:01 +01:00
parent 335a89337f
commit 31a0ee37ab

View File

@@ -155,7 +155,7 @@ func (s *Client) Process(msgpars ...string) (reply *SpamDOut, err error) {
return s.simpleCall(PROCESS, msgpars) return s.simpleCall(PROCESS, msgpars)
} }
//Same as PROCESS, but return only modified headers, not body (new in protocol 1.4) //Same as PROCESS, but return only modified headers, not body (new in protocol 1.4)
func (s *Client) Headers(msgpars ...string) (reply *SpamDOut, err error) { func (s *Client) Headers(msgpars ...string) (reply *SpamDOut, err error) {
return s.simpleCall(HEADERS, msgpars) return s.simpleCall(HEADERS, msgpars)
} }
@@ -263,8 +263,8 @@ func (s *Client) call(cmd string, msgpars []string, onData FnCallback, extraHead
cmd = REPORT cmd = REPORT
} }
// Create a new connection // Create a new connection, with a reasonable timeout
stream, err := net.Dial("tcp", s.Host) stream, err := net.DialTimeout("tcp", s.Host, time.Duration(DEFAULT_TIMEOUT)*time.Second)
if err != nil { if err != nil {
err = errors.New("Connection dial error to spamd: " + err.Error()) err = errors.New("Connection dial error to spamd: " + err.Error())
@@ -317,7 +317,7 @@ func processResponse(cmd string, data *bufio.Reader) (returnObj *SpamDOut, err e
var result = r.FindStringSubmatch(lineStr) var result = r.FindStringSubmatch(lineStr)
if len(result) < 4 { if len(result) < 4 {
if cmd != "SKIP" { if cmd != "SKIP" {
err = errors.New("spamd unreconized reply:" + lineStr) err = errors.New("spamd unrecognized reply:" + lineStr)
} else { } else {
returnObj.Code = EX_OK returnObj.Code = EX_OK
returnObj.Message = "SKIPPED" returnObj.Message = "SKIPPED"