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