a bit less retarded exit handling

pull/8/head
Jean-Louis Huynen 2019-02-15 15:22:23 +01:00
parent ac822133d7
commit 46b52b6a5f
1 changed files with 12 additions and 7 deletions

View File

@ -287,7 +287,7 @@ func main() {
// We start a worker to send the processed TLS connection the outside world
var w sync.WaitGroup
w.Add(1)
go processCompletedSession(jobQ, &w)
go processCompletedSession(cancelC, jobQ, &w)
var eth layers.Ethernet
var ip4 layers.IPv4
@ -358,6 +358,7 @@ func main() {
fmt.Fprintf(os.Stderr, "\nCaught SIGINT: aborting\n")
cancelC <- "stop"
done = true
break
default:
// NOP: continue
}
@ -387,15 +388,19 @@ func queueSession(t d4tls.TLSSession) bool {
}
}
func processCompletedSession(jobQ <-chan d4tls.TLSSession, w *sync.WaitGroup) {
func processCompletedSession(cancelC <-chan string, jobQ <-chan d4tls.TLSSession, w *sync.WaitGroup) {
for {
tlss, more := <-jobQ
select {
case tlss, more := <-jobQ:
if more {
output(tlss)
} else {
w.Done()
return
}
case <-cancelC:
w.Done()
}
}
}