Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ethr.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func main() {
}
bufLen := unitToNumber(*bufLenStr)
if bufLen == 0 {
printUsageError(fmt.Sprintf("Invalid length specified: %s" + *bufLenStr))
printUsageError(fmt.Sprintf("Invalid length specified: %s", *bufLenStr))
}

// Check specific bwRate if any.
Expand Down
23 changes: 18 additions & 5 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"log"
"os"
"sync"
"time"
)

Expand Down Expand Up @@ -60,6 +61,8 @@ type logTestResults struct {

var loggingActive = false
var logChan = make(chan string, 64)
var logDone = make(chan struct{})
var logFiniOnce sync.Once

func logInit(fileName string) {
if fileName == "" {
Expand All @@ -77,15 +80,25 @@ func logInit(fileName string) {
}

func logFini() {
loggingActive = false
// Signal runLogger to stop. Without this the goroutine blocks forever on
// the logChan receive and the log file is never closed. The once guard
// keeps logFini safe to call more than once.
logFiniOnce.Do(func() {
loggingActive = false
close(logDone)
})
}

func runLogger(logFile *os.File) {
for loggingActive {
s := <-logChan
log.Println(s)
for {
select {
case <-logDone:
_ = logFile.Close()
return
case s := <-logChan:
log.Println(s)
}
}
logFile.Close()
}

func logMsg(prefix, msg string) {
Expand Down