mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
move mutex to avoid race condition #407
This commit is contained in:
parent
7993e73ac2
commit
86aeed93db
1 changed files with 3 additions and 1 deletions
|
@ -1454,13 +1454,14 @@ func (c *Client) receiveData(i int) {
|
||||||
|
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
_, err = c.CurrentFile.WriteAt(data[8:], positionInt64)
|
_, err = c.CurrentFile.WriteAt(data[8:], positionInt64)
|
||||||
c.mutex.Unlock()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
c.bar.Add(len(data[8:]))
|
c.bar.Add(len(data[8:]))
|
||||||
c.TotalSent += int64(len(data[8:]))
|
c.TotalSent += int64(len(data[8:]))
|
||||||
c.TotalChunksTransfered++
|
c.TotalChunksTransfered++
|
||||||
|
// log.Debug(len(c.CurrentFileChunks), c.TotalChunksTransfered, c.TotalSent, c.FilesToTransfer[c.FilesToTransferCurrentNum].Size)
|
||||||
|
|
||||||
if !c.CurrentFileIsClosed && (c.TotalChunksTransfered == len(c.CurrentFileChunks) || c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size) {
|
if !c.CurrentFileIsClosed && (c.TotalChunksTransfered == len(c.CurrentFileChunks) || c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size) {
|
||||||
c.CurrentFileIsClosed = true
|
c.CurrentFileIsClosed = true
|
||||||
log.Debug("finished receiving!")
|
log.Debug("finished receiving!")
|
||||||
|
@ -1483,6 +1484,7 @@ func (c *Client) receiveData(i int) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c.mutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue