mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Bug fix: remove race condition for startTime
This commit is contained in:
parent
d105c253c1
commit
152c27a5e9
1 changed files with 12 additions and 4 deletions
16
connect.go
16
connect.go
|
@ -212,7 +212,6 @@ func (c *Connection) runClient() error {
|
||||||
"sender?": c.IsSender,
|
"sender?": c.IsSender,
|
||||||
})
|
})
|
||||||
|
|
||||||
startTime := time.Now()
|
|
||||||
c.HashedCode = Hash(c.Code)
|
c.HashedCode = Hash(c.Code)
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@ -227,10 +226,14 @@ func (c *Connection) runClient() error {
|
||||||
gotResponse bool
|
gotResponse bool
|
||||||
gotConnectionInUse bool
|
gotConnectionInUse bool
|
||||||
notPresent bool
|
notPresent bool
|
||||||
|
startTime time.Time
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
responses := new(responsesStruct)
|
responses := new(responsesStruct)
|
||||||
|
responses.Lock()
|
||||||
|
responses.startTime = time.Now()
|
||||||
|
responses.Unlock()
|
||||||
for id := 0; id < c.NumberOfConnections; id++ {
|
for id := 0; id < c.NumberOfConnections; id++ {
|
||||||
go func(id int) {
|
go func(id int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -292,7 +295,9 @@ func (c *Connection) runClient() error {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
// Write data from file
|
// Write data from file
|
||||||
logger.Debug("send file")
|
logger.Debug("send file")
|
||||||
startTime = time.Now()
|
responses.Lock()
|
||||||
|
responses.startTime = time.Now()
|
||||||
|
responses.Unlock()
|
||||||
c.bar.Reset()
|
c.bar.Reset()
|
||||||
if err := c.sendFile(id, connection); err != nil {
|
if err := c.sendFile(id, connection); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -387,7 +392,9 @@ func (c *Connection) runClient() error {
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
fmt.Printf("\n\nReceiving (<-%s)..\n", sendersAddress)
|
fmt.Printf("\n\nReceiving (<-%s)..\n", sendersAddress)
|
||||||
}
|
}
|
||||||
startTime = time.Now()
|
responses.Lock()
|
||||||
|
responses.startTime = time.Now()
|
||||||
|
responses.Unlock()
|
||||||
c.bar.SetMax(c.File.Size)
|
c.bar.SetMax(c.File.Size)
|
||||||
c.bar.Reset()
|
c.bar.Reset()
|
||||||
if err := c.receiveFile(id, connection); err != nil {
|
if err := c.receiveFile(id, connection); err != nil {
|
||||||
|
@ -406,6 +413,8 @@ func (c *Connection) runClient() error {
|
||||||
return nil // connection was in use, just quit cleanly
|
return nil // connection was in use, just quit cleanly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeSinceStart := time.Since(responses.startTime) / time.Second
|
||||||
|
|
||||||
if c.IsSender {
|
if c.IsSender {
|
||||||
if responses.gotTimeout {
|
if responses.gotTimeout {
|
||||||
fmt.Println("Timeout waiting for receiver")
|
fmt.Println("Timeout waiting for receiver")
|
||||||
|
@ -471,7 +480,6 @@ func (c *Connection) runClient() error {
|
||||||
fmt.Printf("\nReceived file written to %s", path.Join(c.Path, c.File.Name))
|
fmt.Printf("\nReceived file written to %s", path.Join(c.Path, c.File.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
timeSinceStart := time.Since(startTime) / time.Second
|
|
||||||
fmt.Printf(" (%s/s)\n", humanize.Bytes(uint64(float64(c.File.Size)/float64(timeSinceStart))))
|
fmt.Printf(" (%s/s)\n", humanize.Bytes(uint64(float64(c.File.Size)/float64(timeSinceStart))))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue