From 0434070a3548e648fc78723d2b1e38b81543e554 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 23 Jul 2018 21:50:40 +0000 Subject: [PATCH] Barf gross hack so the waitgroup doesn't wait forever FIXME --- examples/simple/simple.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/simple/simple.go b/examples/simple/simple.go index 65782a8..ce26cce 100644 --- a/examples/simple/simple.go +++ b/examples/simple/simple.go @@ -6,11 +6,13 @@ import ( "log" "strings" "sync" + "time" "github.com/google/gopacket" "github.com/google/gopacket/tcpassembly" "github.com/dirtbags/netshovel" ) +var threads int var wg sync.WaitGroup type SimpleStreamFactory struct { @@ -34,6 +36,7 @@ func (f *SimpleStreamFactory) New(net, transport gopacket.Flow) tcpassembly.Stre stream := &SimpleStream{ Stream: netshovel.NewStream(net, transport), } + threads += 1 wg.Add(1) go stream.Decode(wg) @@ -52,7 +55,6 @@ func (stream SimpleStream) Display(pkt SimplePacket) { } func (stream SimpleStream) Decode(wg sync.WaitGroup) { - defer wg.Done() for { pkt := NewSimplePacket() @@ -69,9 +71,17 @@ func (stream SimpleStream) Decode(wg sync.WaitGroup) { pkt.When = utterance.When stream.Display(pkt) } + threads -= 1 + wg.Done() } func main() { + threads = 0 netshovel.Shovel(&SimpleStreamFactory{}) - wg.Wait() + + // XXX: ZOMG WHY + for threads > 0 { + time.Sleep(100 * time.Millisecond) + } + //wg.Wait() }