Figured out waitgroup problem, thank heaven

This commit is contained in:
Neale Pickett 2018-07-23 21:54:08 +00:00
parent 0434070a35
commit 88f14b78d1
1 changed files with 3 additions and 13 deletions

View File

@ -6,13 +6,11 @@ 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 {
@ -36,9 +34,8 @@ 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)
return stream return stream
} }
@ -54,7 +51,7 @@ func (stream SimpleStream) Display(pkt SimplePacket) {
fmt.Println(out.String()) fmt.Println(out.String())
} }
func (stream SimpleStream) Decode(wg sync.WaitGroup) { func (stream SimpleStream) Decode(wg *sync.WaitGroup) {
for { for {
pkt := NewSimplePacket() pkt := NewSimplePacket()
@ -71,17 +68,10 @@ 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() 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()
} }