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

chore: improve efficiency and remove extraneous reads

This commit is contained in:
Zack 2024-05-20 10:39:22 -07:00
parent 7622e636e4
commit d8ef7cda20

View file

@ -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)