mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Merge pull request #702 from schollz:schollz/issue599
chore: improve efficiency and remove extraneous reads
This commit is contained in:
commit
f6633cbac9
1 changed files with 52 additions and 48 deletions
|
@ -1982,18 +1982,17 @@ func (c *Client) sendData(i int) {
|
|||
curi := float64(0)
|
||||
for {
|
||||
// Read file
|
||||
var n int
|
||||
var errRead error
|
||||
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
||||
data := make([]byte, models.TCP_BUFFER_SIZE/2)
|
||||
// log.Debugf("%d trying to read", i)
|
||||
n, errRead := c.fread.ReadAt(data, readingPos)
|
||||
// log.Debugf("%d read %d bytes", i, n)
|
||||
readingPos += int64(n)
|
||||
n, errRead = c.fread.ReadAt(data, readingPos)
|
||||
if c.limiter != nil {
|
||||
r := c.limiter.ReserveN(time.Now(), n)
|
||||
log.Debugf("Limiting Upload for %d", r.Delay())
|
||||
time.Sleep(r.Delay())
|
||||
}
|
||||
|
||||
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
||||
if n > 0 {
|
||||
// check to see if this is a chunk that the recipient wants
|
||||
usableChunk := true
|
||||
c.mutex.Lock()
|
||||
|
@ -2037,7 +2036,12 @@ func (c *Client) sendData(i int) {
|
|||
// time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
n = models.TCP_BUFFER_SIZE / 2
|
||||
}
|
||||
readingPos += int64(n)
|
||||
curi++
|
||||
pos += uint64(n)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue