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