Barf gross hack so the waitgroup doesn't wait forever FIXME

This commit is contained in:
Neale Pickett 2018-07-23 21:50:40 +00:00
parent 899e425e76
commit 0434070a35
1 changed files with 12 additions and 2 deletions

View File

@ -6,11 +6,13 @@ import (
"log" "log"
"strings" "strings"
"sync" "sync"
"time"
"github.com/google/gopacket" "github.com/google/gopacket"
"github.com/google/gopacket/tcpassembly" "github.com/google/gopacket/tcpassembly"
"github.com/dirtbags/netshovel" "github.com/dirtbags/netshovel"
) )
var threads int
var wg sync.WaitGroup var wg sync.WaitGroup
type SimpleStreamFactory struct { type SimpleStreamFactory struct {
@ -34,6 +36,7 @@ func (f *SimpleStreamFactory) New(net, transport gopacket.Flow) tcpassembly.Stre
stream := &SimpleStream{ stream := &SimpleStream{
Stream: netshovel.NewStream(net, transport), Stream: netshovel.NewStream(net, transport),
} }
threads += 1
wg.Add(1) wg.Add(1)
go stream.Decode(wg) go stream.Decode(wg)
@ -52,7 +55,6 @@ func (stream SimpleStream) Display(pkt SimplePacket) {
} }
func (stream SimpleStream) Decode(wg sync.WaitGroup) { func (stream SimpleStream) Decode(wg sync.WaitGroup) {
defer wg.Done()
for { for {
pkt := NewSimplePacket() pkt := NewSimplePacket()
@ -69,9 +71,17 @@ func (stream SimpleStream) Decode(wg sync.WaitGroup) {
pkt.When = utterance.When pkt.When = utterance.When
stream.Display(pkt) stream.Display(pkt)
} }
threads -= 1
wg.Done()
} }
func main() { func main() {
threads = 0
netshovel.Shovel(&SimpleStreamFactory{}) netshovel.Shovel(&SimpleStreamFactory{})
wg.Wait()
// XXX: ZOMG WHY
for threads > 0 {
time.Sleep(100 * time.Millisecond)
}
//wg.Wait()
} }