sdr: replace Scan due to a report that it was still blocking, split stderr and stdout

pull/326/head
Joseph Poirier 2016-03-14 02:23:03 -05:00
rodzic 336d17d615
commit 529b453ba2
1 zmienionych plików z 17 dodań i 16 usunięć

Wyświetl plik

@ -10,7 +10,6 @@
package main
import (
"bufio"
"log"
"os/exec"
"regexp"
@ -71,9 +70,6 @@ func (e *ES) read() {
log.Println("Executed /usr/bin/dump1090 successfully...")
scanStdout := bufio.NewScanner(stdout)
scanStderr := bufio.NewScanner(stderr)
done := make(chan bool)
go func() {
@ -94,27 +90,32 @@ func (e *ES) read() {
}
}()
stdoutBuf := make([]byte, 1024)
stderrBuf := make([]byte, 1024)
go func() {
for {
select {
case <-done:
return
default:
if scanStdout.Scan() {
replayLog(scanStdout.Text(), MSGCLASS_DUMP1090)
}
if err := scanStdout.Err(); err != nil {
log.Printf("scanStdout error: %s\n", err)
n, err := stdout.Read(stdoutBuf)
if err == nil && n > 0 {
replayLog(string(stdoutBuf[:n]), MSGCLASS_DUMP1090)
}
}
}
}()
if scanStderr.Scan() {
replayLog(scanStderr.Text(), MSGCLASS_DUMP1090)
go func() {
for {
select {
case <-done:
return
default:
n, err := stderr.Read(stderrBuf)
if err == nil && n > 0 {
replayLog(string(stderrBuf[:n]), MSGCLASS_DUMP1090)
}
if err := scanStderr.Err(); err != nil {
log.Printf("scanStderr error: %s\n", err)
}
time.Sleep(1 * time.Second)
}
}
}()