Change dns snooper timeout to avoid spinning in pcap

The previous code seems to be relying on a 64-bit to 32-bit conversion
working in a certain way; when gopacket was changed to cast the value
explicitly it starts returning immeditely from pcap.
This commit is contained in:
Bryan Boreham
2019-09-20 14:31:07 +00:00
parent 07d3dfd45c
commit 9208e08bf3

View File

@@ -8,7 +8,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"math"
"sync"
"time"
@@ -60,9 +59,10 @@ func newPcapHandle() (*pcap.Handle, error) {
return nil, err
}
defer inactive.CleanUp()
// pcap timeout blackmagic copied from Weave Net to reduce CPU consumption
// Set a long timeout because "pcap.BlockForever" actually spins on a 10ms timeout
// see https://github.com/weaveworks/weave/commit/025315363d5ea8b8265f1b3ea800f24df2be51a4
if err = inactive.SetTimeout(time.Duration(math.MaxInt64)); err != nil {
// (note the value in microseconds has to fit in a 32-bit signed int)
if err = inactive.SetTimeout(time.Minute * 30); err != nil {
return nil, err
}
if err = inactive.SetImmediateMode(true); err != nil {