fix windows tailer closing issues

This commit is contained in:
Ben Grewell
2021-03-10 14:48:33 -08:00
parent 0dc467f289
commit f9a882f5e4
5 changed files with 56 additions and 51 deletions

3
.idea/workspace.xml generated
View File

@@ -3,9 +3,10 @@
<component name="ChangeListManager">
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter_linux.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_linux.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/tests/client/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/tests/client/client.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/reporter_windows.go" beforeDir="false" afterPath="$PROJECT_DIR$/reporter_windows.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@@ -492,7 +492,6 @@ func (c *Client) Start() (err error) {
if err != nil {
return err
}
fmt.Println(cmd)
var exit chan int
c.outputStream, c.errorStream, exit, c.cancel, err = ExecuteAsyncWithCancel(cmd)
if err != nil {

View File

@@ -1,7 +1,6 @@
package iperf
import (
"fmt"
"github.com/BGrewell/tail"
)
@@ -22,7 +21,6 @@ func (r *Reporter) Stop() {
r.tailer.Stop()
r.tailer.Cleanup()
close(r.ReportingChannel)
fmt.Println("reporter stopped")
}
// runLogProcessor is OS specific because of differences in iperf on Windows and Linux

View File

@@ -45,13 +45,12 @@ Connecting to host 10.254.100.100, port 5201
iperf Done.
*/
//TODO: NEED TO UPDATE WINDOWS IMPLEMENTATION ALSO!!!!!
func (r *Reporter) runLogProcessor() {
var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true,
ReOpen: true,
Poll: true, // on linux we don't need to poll as the fsnotify works properly
Poll: false, // on linux we don't need to poll as the fsnotify works properly
MustExist: true,
})
if err != nil {
@@ -120,7 +119,7 @@ func (r *Reporter) runLogProcessor() {
r.ReportingChannel <- report
}
}
case <- time.After(1 * time.Second):
case <- time.After(100 * time.Millisecond):
if !r.running {
return
}

View File

@@ -7,10 +7,12 @@ import (
"log"
"strconv"
"strings"
"time"
)
func (r *Reporter) runLogProcessor() {
tailer, err := tail.TailFile(r.LogFile, tail.Config{
var err error
r.tailer, err = tail.TailFile(r.LogFile, tail.Config{
Follow: true,
ReOpen: true,
Poll: true,
@@ -19,8 +21,13 @@ func (r *Reporter) runLogProcessor() {
if err != nil {
log.Fatalf("failed to tail log file: %v", err)
}
for line := range tailer.Lines {
// TODO: For now this only cares about individual streams it ignores the sum lines
for {
select {
case line := <- r.tailer.Lines:
if line == nil {
continue
}
if len(line.Text) > 5 {
id := line.Text[1:4]
stream, err := strconv.Atoi(strings.TrimSpace(id))
@@ -65,9 +72,10 @@ func (r *Reporter) runLogProcessor() {
r.ReportingChannel <- report
}
}
case <- time.After(100 * time.Millisecond):
if !r.running {
return
}
}
}
}