add return of iperf pid
This commit is contained in:
20
.idea/workspace.xml
generated
20
.idea/workspace.xml
generated
@@ -5,9 +5,11 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
|
<list default="true" id="fc2840de-29dc-4fca-8e0e-a283562f60ca" name="Default Changelist" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/reporter_darwin.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/client.go" beforeDir="false" afterPath="$PROJECT_DIR$/client.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/cmd/main.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/execute.go" beforeDir="false" afterPath="$PROJECT_DIR$/execute.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/server.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -56,59 +58,59 @@
|
|||||||
<recent name="C:\Users\BGrewell\repos\go-iperf\embedded" />
|
<recent name="C:\Users\BGrewell\repos\go-iperf\embedded" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="RunManager" selected="Go Build.go build github.com/BGrewell/go-iperf/tests/controller">
|
<component name="RunManager" selected="Go Build.go build github.com/BGrewell/go-iperf/cmd">
|
||||||
<configuration name="go build github.com/BGrewell/go-iperf/cmd" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
<configuration name="go build github.com/BGrewell/go-iperf/cmd" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||||
<module name="go-iperf" />
|
<module name="go-iperf" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/cmd/main.go" />
|
||||||
<package value="github.com/BGrewell/go-iperf/cmd" />
|
<package value="github.com/BGrewell/go-iperf/cmd" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/cmd/main.go" />
|
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="go build github.com/BGrewell/go-iperf/tests/client" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
<configuration name="go build github.com/BGrewell/go-iperf/tests/client" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||||
<module name="go-iperf" />
|
<module name="go-iperf" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/tests/client/client.go" />
|
||||||
<package value="github.com/BGrewell/go-iperf/tests/client" />
|
<package value="github.com/BGrewell/go-iperf/tests/client" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/tests/client/client.go" />
|
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="go build github.com/BGrewell/go-iperf/tests/controller" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
<configuration name="go build github.com/BGrewell/go-iperf/tests/controller" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||||
<module name="go-iperf" />
|
<module name="go-iperf" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/tests/controller/main.go" />
|
||||||
<package value="github.com/BGrewell/go-iperf/tests/controller" />
|
<package value="github.com/BGrewell/go-iperf/tests/controller" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/tests/controller/main.go" />
|
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="go build github.com/BGrewell/go-iperf/tests/extract" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
<configuration name="go build github.com/BGrewell/go-iperf/tests/extract" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||||
<module name="go-iperf" />
|
<module name="go-iperf" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/tests/extract/main.go" />
|
||||||
<package value="github.com/BGrewell/go-iperf/tests/extract" />
|
<package value="github.com/BGrewell/go-iperf/tests/extract" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/tests/extract/main.go" />
|
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration name="go build github.com/BGrewell/go-iperf/tests/server" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
<configuration name="go build github.com/BGrewell/go-iperf/tests/server" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
|
||||||
<module name="go-iperf" />
|
<module name="go-iperf" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="PACKAGE" />
|
<kind value="PACKAGE" />
|
||||||
|
<filePath value="$PROJECT_DIR$/tests/server/server.go" />
|
||||||
<package value="github.com/BGrewell/go-iperf/tests/server" />
|
<package value="github.com/BGrewell/go-iperf/tests/server" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/tests/server/server.go" />
|
|
||||||
<method v="2" />
|
<method v="2" />
|
||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/cmd" />
|
||||||
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/controller" />
|
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/controller" />
|
||||||
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/extract" />
|
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/extract" />
|
||||||
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/client" />
|
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/client" />
|
||||||
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/server" />
|
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/tests/server" />
|
||||||
<item itemvalue="Go Build.go build github.com/BGrewell/go-iperf/cmd" />
|
|
||||||
</list>
|
</list>
|
||||||
</recent_temporary>
|
</recent_temporary>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
17
client.go
17
client.go
@@ -489,15 +489,24 @@ func (c *Client) SetModeLive() <-chan *StreamIntervalReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Start() (err error) {
|
func (c *Client) Start() (err error) {
|
||||||
|
_, err = c.start()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) StartEx() (pid int, err error) {
|
||||||
|
return c.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) start() (pid int, err error) {
|
||||||
read := make(chan interface{})
|
read := make(chan interface{})
|
||||||
cmd, err := c.commandString()
|
cmd, err := c.commandString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return -1, err
|
||||||
}
|
}
|
||||||
var exit chan int
|
var exit chan int
|
||||||
c.outputStream, c.errorStream, exit, c.cancel, err = ExecuteAsyncWithCancelReadIndicator(cmd, read)
|
c.outputStream, c.errorStream, exit, c.cancel, pid, err = ExecuteAsyncWithCancelReadIndicator(cmd, read)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return -1, err
|
||||||
}
|
}
|
||||||
c.Running = true
|
c.Running = true
|
||||||
|
|
||||||
@@ -548,7 +557,7 @@ func (c *Client) Start() (err error) {
|
|||||||
reporter.Stop()
|
reporter.Stop()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return pid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Stop() {
|
func (c *Client) Stop() {
|
||||||
|
|||||||
70
cmd/main.go
70
cmd/main.go
@@ -2,45 +2,47 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
//"fmt"
|
//"fmt"
|
||||||
//"github.com/BGrewell/go-conversions"
|
"github.com/BGrewell/go-conversions"
|
||||||
//"github.com/BGrewell/go-iperf"
|
//"github.com/BGrewell/go-iperf"
|
||||||
//"time"
|
//"time"
|
||||||
|
"fmt"
|
||||||
|
"github.com/BGrewell/go-iperf"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
//s := iperf.NewServer()
|
s := iperf.NewServer()
|
||||||
//c := iperf.NewClient("127.0.0.1")
|
c := iperf.NewClient("127.0.0.1")
|
||||||
//includeServer := true
|
c.SetIncludeServer(true)
|
||||||
//c.IncludeServer = &includeServer
|
fmt.Println(s.Id)
|
||||||
//fmt.Println(s.Id)
|
fmt.Println(c.Id)
|
||||||
//fmt.Println(c.Id)
|
|
||||||
//
|
err := s.Start()
|
||||||
//err := s.Start()
|
if err != nil {
|
||||||
//if err != nil {
|
fmt.Println(err)
|
||||||
// fmt.Println(err)
|
}
|
||||||
//}
|
|
||||||
//
|
err = c.Start()
|
||||||
//err = c.Start()
|
if err != nil {
|
||||||
//if err != nil {
|
fmt.Println(err)
|
||||||
// fmt.Println(err)
|
}
|
||||||
//}
|
|
||||||
//
|
for c.Running {
|
||||||
//for c.Running {
|
time.Sleep(1 * time.Second)
|
||||||
// time.Sleep(1 * time.Second)
|
}
|
||||||
//}
|
|
||||||
//
|
fmt.Println("stopping server")
|
||||||
//fmt.Println("stopping server")
|
s.Stop()
|
||||||
//s.Stop()
|
|
||||||
//
|
fmt.Printf("Client exit code: %d\n", *c.ExitCode())
|
||||||
//fmt.Printf("Client exit code: %d\n", *c.ExitCode)
|
fmt.Printf("Server exit code: %d\n", *s.ExitCode)
|
||||||
//fmt.Printf("Server exit code: %d\n", *s.ExitCode)
|
iperf.Cleanup()
|
||||||
//iperf.Cleanup()
|
if c.Report().Error != "" {
|
||||||
//if c.Report.Error != "" {
|
fmt.Println(c.Report().Error)
|
||||||
// fmt.Println(c.Report.Error)
|
} else {
|
||||||
//} else {
|
fmt.Printf("Recv Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumReceived.BitsPerSecond)))
|
||||||
// fmt.Printf("Recv Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumReceived.BitsPerSecond)))
|
fmt.Printf("Send Rate: %s\n", conversions.IntBitRateToString(int64(c.Report().End.SumSent.BitsPerSecond)))
|
||||||
// fmt.Printf("Send Rate: %s\n", conversions.IntBitRateToString(int64(c.Report.End.SumSent.BitsPerSecond)))
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
18
execute.go
18
execute.go
@@ -42,34 +42,38 @@ func ExecuteAsync(cmd string) (outPipe io.ReadCloser, errPipe io.ReadCloser, exi
|
|||||||
return outPipe, errPipe, exitCode, nil
|
return outPipe, errPipe, exitCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecuteAsyncWithCancel(cmd string) (stdOut io.ReadCloser, stdErr io.ReadCloser, exitCode chan int, cancelToken context.CancelFunc, err error) {
|
func ExecuteAsyncWithCancel(cmd string) (stdOut io.ReadCloser, stdErr io.ReadCloser, exitCode chan int, cancelToken context.CancelFunc, pid int, err error) {
|
||||||
return ExecuteAsyncWithCancelReadIndicator(cmd, nil)
|
return ExecuteAsyncWithCancelReadIndicator(cmd, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExecuteAsyncWithCancelReadIndicator(cmd string, readIndicator chan interface{}) (stdOut io.ReadCloser, stdErr io.ReadCloser, exitCode chan int, cancelToken context.CancelFunc, err error) {
|
func ExecuteAsyncWithCancelReadIndicator(cmd string, readIndicator chan interface{}) (stdOut io.ReadCloser, stdErr io.ReadCloser, exitCode chan int, cancelToken context.CancelFunc, pid int, err error) {
|
||||||
|
return executeAsyncWithCancel(cmd, readIndicator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeAsyncWithCancel(cmd string, readIndicator chan interface{}) (stdOut io.ReadCloser, stdErr io.ReadCloser, exitCode chan int, cancelToken context.CancelFunc, pid int, err error) {
|
||||||
exitCode = make(chan int)
|
exitCode = make(chan int)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
cmdParts := strings.Fields(cmd)
|
cmdParts := strings.Fields(cmd)
|
||||||
binary, err := exec.LookPath(cmdParts[0])
|
binary, err := exec.LookPath(cmdParts[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, -1, err
|
||||||
}
|
}
|
||||||
exe := exec.CommandContext(ctx, binary, cmdParts[1:]...)
|
exe := exec.CommandContext(ctx, binary, cmdParts[1:]...)
|
||||||
stdOut, err = exe.StdoutPipe()
|
stdOut, err = exe.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, -1, err
|
||||||
}
|
}
|
||||||
stdErr, err = exe.StderrPipe()
|
stdErr, err = exe.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, -1, err
|
||||||
}
|
}
|
||||||
err = exe.Start()
|
err = exe.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
return nil, nil, nil, nil, err
|
return nil, nil, nil, nil, -1, err
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// Note: Wait() will close the Stdout/Stderr and in some cases can do it before we read. In order to prevent
|
// Note: Wait() will close the Stdout/Stderr and in some cases can do it before we read. In order to prevent
|
||||||
@@ -87,5 +91,5 @@ func ExecuteAsyncWithCancelReadIndicator(cmd string, readIndicator chan interfac
|
|||||||
exitCode <- 0
|
exitCode <- 0
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return stdOut, stdErr, exitCode, cancel, nil
|
return stdOut, stdErr, exitCode, cancel, exe.Process.Pid, nil
|
||||||
}
|
}
|
||||||
17
server.go
17
server.go
@@ -151,14 +151,23 @@ func (s *Server) SetLogFile(filename string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() (err error) {
|
func (s *Server) Start() (err error) {
|
||||||
|
_, err = s.start()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) StartEx() (pid int, err error) {
|
||||||
|
return s.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) start() (pid int, err error) {
|
||||||
cmd, err := s.commandString()
|
cmd, err := s.commandString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return -1, err
|
||||||
}
|
}
|
||||||
var exit chan int
|
var exit chan int
|
||||||
s.outputStream, s.errorStream, exit, s.cancel, err = ExecuteAsyncWithCancel(cmd)
|
s.outputStream, s.errorStream, exit, s.cancel, pid, err = ExecuteAsyncWithCancel(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return -1, err
|
||||||
}
|
}
|
||||||
s.Running = true
|
s.Running = true
|
||||||
|
|
||||||
@@ -176,7 +185,7 @@ func (s *Server) Start() (err error) {
|
|||||||
s.ExitCode = &exitCode
|
s.ExitCode = &exitCode
|
||||||
s.Running = false
|
s.Running = false
|
||||||
}()
|
}()
|
||||||
return nil
|
return pid,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user