mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
fshttp: fix bandwidth limiting after bad merge
Reapply missing bwlimiting which was inserted in0a932dc1f2
Add --bwlimit for upload and download #1873 But accidentally removed when mergingedfe183ba2
fshttp: add DSCP support with --dscp for QoS with differentiated services
This commit is contained in:
parent
37e630178e
commit
e779cacc82
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/accounting"
|
||||
"golang.org/x/net/ipv4"
|
||||
"golang.org/x/net/ipv6"
|
||||
)
|
||||
@ -91,24 +92,29 @@ func (c *timeoutConn) nudgeDeadline() (err error) {
|
||||
return c.Conn.SetDeadline(when)
|
||||
}
|
||||
|
||||
// readOrWrite bytes doing idle timeouts
|
||||
func (c *timeoutConn) readOrWrite(f func([]byte) (int, error), b []byte) (n int, err error) {
|
||||
n, err = f(b)
|
||||
// Read bytes doing idle timeouts
|
||||
func (c *timeoutConn) Read(b []byte) (n int, err error) {
|
||||
// Ideally we would LimitBandwidth(len(b)) here and replace tokens we didn't use
|
||||
n, err = c.Conn.Read(b)
|
||||
accounting.TokenBucket.LimitBandwidth(accounting.TokenBucketSlotTransportRx, n)
|
||||
// Don't nudge if no bytes or an error
|
||||
if n == 0 || err != nil {
|
||||
return
|
||||
}
|
||||
// Nudge the deadline on successful Read or Write
|
||||
err = c.nudgeDeadline()
|
||||
return
|
||||
}
|
||||
|
||||
// Read bytes doing idle timeouts
|
||||
func (c *timeoutConn) Read(b []byte) (n int, err error) {
|
||||
return c.readOrWrite(c.Conn.Read, b)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Write bytes doing idle timeouts
|
||||
func (c *timeoutConn) Write(b []byte) (n int, err error) {
|
||||
return c.readOrWrite(c.Conn.Write, b)
|
||||
accounting.TokenBucket.LimitBandwidth(accounting.TokenBucketSlotTransportTx, len(b))
|
||||
n, err = c.Conn.Write(b)
|
||||
// Don't nudge if no bytes or an error
|
||||
if n == 0 || err != nil {
|
||||
return
|
||||
}
|
||||
// Nudge the deadline on successful Read or Write
|
||||
err = c.nudgeDeadline()
|
||||
return n, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user