0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

use single reader

This commit is contained in:
Zack Scholl 2019-09-07 07:14:16 -07:00
parent cce4a7ed92
commit 98799d057f

View file

@ -30,7 +30,6 @@ import (
"github.com/schollz/peerdiscovery" "github.com/schollz/peerdiscovery"
"github.com/schollz/progressbar/v2" "github.com/schollz/progressbar/v2"
"github.com/schollz/spinner" "github.com/schollz/spinner"
"golang.org/x/exp/mmap"
) )
func init() { func init() {
@ -92,7 +91,7 @@ type Client struct {
firstSend bool firstSend bool
mutex *sync.Mutex mutex *sync.Mutex
fread *mmap.ReaderAt fread *os.File
numfinished int numfinished int
quit chan bool quit chan bool
} }
@ -851,7 +850,7 @@ func (c *Client) updateState() (err error) {
c.FilesToTransfer[c.FilesToTransferCurrentNum].Name, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
) )
c.fread, err = mmap.Open(pathToFile) c.fread, err = os.Open(pathToFile)
c.numfinished = 0 c.numfinished = 0
if err != nil { if err != nil {
return return
@ -958,16 +957,6 @@ func (c *Client) sendData(i int) {
c.fread.Close() c.fread.Close()
} }
}() }()
// pathToFile := path.Join(
// c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource,
// c.FilesToTransfer[c.FilesToTransferCurrentNum].Name,
// )
// log.Debugf("opening %s to read", pathToFile)
// f, err := mmap.Open(pathToFile)
// if err != nil {
// panic(err)
// }
// defer f.Close()
var readingPos int64 var readingPos int64
pos := uint64(0) pos := uint64(0)
@ -1006,9 +995,7 @@ func (c *Client) sendData(i int) {
panic(err) panic(err)
} }
log.Debug("sending data")
err = c.conn[i+1].Send(dataToSend) err = c.conn[i+1].Send(dataToSend)
log.Debug("sent")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -1030,7 +1017,5 @@ func (c *Client) sendData(i int) {
panic(errRead) panic(errRead)
} }
} }
// time.Sleep(10 * time.Second)
return return
} }