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:
parent
7622e636e4
commit
d8ef7cda20
1 changed files with 52 additions and 48 deletions
|
@ -1982,18 +1982,17 @@ func (c *Client) sendData(i int) {
|
||||||
curi := float64(0)
|
curi := float64(0)
|
||||||
for {
|
for {
|
||||||
// Read file
|
// 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)
|
data := make([]byte, models.TCP_BUFFER_SIZE/2)
|
||||||
// log.Debugf("%d trying to read", i)
|
n, errRead = c.fread.ReadAt(data, readingPos)
|
||||||
n, errRead := c.fread.ReadAt(data, readingPos)
|
|
||||||
// log.Debugf("%d read %d bytes", i, n)
|
|
||||||
readingPos += int64(n)
|
|
||||||
if c.limiter != nil {
|
if c.limiter != nil {
|
||||||
r := c.limiter.ReserveN(time.Now(), n)
|
r := c.limiter.ReserveN(time.Now(), n)
|
||||||
log.Debugf("Limiting Upload for %d", r.Delay())
|
log.Debugf("Limiting Upload for %d", r.Delay())
|
||||||
time.Sleep(r.Delay())
|
time.Sleep(r.Delay())
|
||||||
}
|
}
|
||||||
|
if n > 0 {
|
||||||
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
|
||||||
// check to see if this is a chunk that the recipient wants
|
// check to see if this is a chunk that the recipient wants
|
||||||
usableChunk := true
|
usableChunk := true
|
||||||
c.mutex.Lock()
|
c.mutex.Lock()
|
||||||
|
@ -2037,7 +2036,12 @@ func (c *Client) sendData(i int) {
|
||||||
// time.Sleep(100 * time.Millisecond)
|
// time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == 0 {
|
||||||
|
n = models.TCP_BUFFER_SIZE / 2
|
||||||
|
}
|
||||||
|
readingPos += int64(n)
|
||||||
curi++
|
curi++
|
||||||
pos += uint64(n)
|
pos += uint64(n)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue