add total byte counts to track accurate flushing of buffers

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-09 23:48:53 +00:00
parent 026c59bc5c
commit f1d7a816be
1 changed files with 29 additions and 12 deletions

View File

@ -72,12 +72,17 @@ func Run(cmdline string) int {
newerrreader := bufio.NewReader(pstderr) newerrreader := bufio.NewReader(pstderr)
nbrerr := nbreader.NewNBReader(newerrreader, 1024) nbrerr := nbreader.NewNBReader(newerrreader, 1024)
totalCount := 0
for { for {
time.Sleep(2 * time.Millisecond) // only check the buffer 500 times a second time.Sleep(2 * time.Millisecond) // only check the buffer 500 times a second
// log.Println("sleep done") // log.Println("sleep done")
// tight loop that reads 1K at a time until buffer is empty
for {
oneByte := make([]byte, 1024) oneByte := make([]byte, 1024)
count, err := nbr.Read(oneByte) count, err := nbr.Read(oneByte)
totalCount += count
if (err != nil) { if (err != nil) {
// log.Println("Read() count = ", count, "err = ", err) // log.Println("Read() count = ", count, "err = ", err)
@ -88,9 +93,21 @@ func Run(cmdline string) int {
} }
f.Write([]byte(string(oneByte))) f.Write([]byte(string(oneByte)))
f.Flush() f.Flush()
if (count == 0) {
break
}
}
oneByte = make([]byte, 1024) if (totalCount != 0) {
count, err = nbrerr.Read(oneByte) log.Println("totalCount = ", totalCount)
}
//
// HANDLE STDERR
// HANDLE STDERR
//
oneByte := make([]byte, 1024)
count, err := nbrerr.Read(oneByte)
if (err != nil) { if (err != nil) {
oneByte = make([]byte, 1024) oneByte = make([]byte, 1024)
@ -99,8 +116,8 @@ func Run(cmdline string) int {
f.Flush() f.Flush()
log.Println("Read() count = ", count, "err = ", err) log.Println("Read() count = ", count, "err = ", err)
spew.Dump(process.Process) // spew.Dump(process.Process)
spew.Dump(process.ProcessState) // spew.Dump(process.ProcessState)
err := process.Wait() err := process.Wait()
if err != nil { if err != nil {
spew.Dump(err.(*exec.ExitError)) spew.Dump(err.(*exec.ExitError))