timer.after => timer

dev
mzack 2021-10-19 19:39:33 +02:00
parent 0ba3b19f1f
commit ae99a88f52
1 changed files with 10 additions and 2 deletions

View File

@ -198,17 +198,25 @@ func (request *Request) executeRequestWithPayloads(actualAddress, address, input
)
if request.ReadAll {
readInterval := time.After(time.Second * 1)
readInterval := time.NewTimer(time.Second * 1)
// stop the timer and drain the channel
closeTimer := func(t *time.Timer) {
if !t.Stop() {
<-t.C
}
}
read_socket:
for {
select {
case <-readInterval:
case <-readInterval.C:
closeTimer(readInterval)
break read_socket
default:
buf := make([]byte, bufferSize)
nBuf, err := conn.Read(buf)
if err != nil && !os.IsTimeout(err) {
request.options.Output.Request(request.options.TemplateID, address, "network", err)
closeTimer(readInterval)
return errors.Wrap(err, "could not read from server")
}
responseBuilder.Write(buf[:nBuf])