"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
Fix timeouts not working when set to 0 and firing too often - #766
Nick Craig-Woode94850f32286
diff --git a/fs/http.go b/fs/http.goindex d59e218ff..f49fefd65 100644--- a/fs/http.go+++ b/fs/http.go@@ -28,7 +28,6 @@ type timeoutConn struct {readTimer *time.TimerwriteTimer *time.Timertimeout time.Duration- _cancel func()off time.Time}@@ -40,34 +39,39 @@ func newTimeoutConn(conn net.Conn, timeout time.Duration) *timeoutConn {}}-// Read bytes doing timeouts-func (c *timeoutConn) Read(b []byte) (n int, err error) {- err = c.Conn.SetReadDeadline(time.Now().Add(c.timeout))- if err != nil {- return n, err+// Nudge the deadline for an idle timeout on by c.timeout if non-zero+func (c *timeoutConn) nudgeDeadline() (err error) {+ if c.timeout == 0 {+ return nil}- n, err = c.Conn.Read(b)- cerr := c.Conn.SetReadDeadline(c.off)- if cerr != nil {- err = cerr- }- return n, err+ when := time.Now().Add(c.timeout)+ return c.Conn.SetDeadline(when)}-// Write bytes doing timeouts-func (c *timeoutConn) Write(b []byte) (n int, err error) {- err = c.Conn.SetWriteDeadline(time.Now().Add(c.timeout))+// readOrWrite bytes doing idle timeouts+func (c *timeoutConn) readOrWrite(f func([]byte) (int, error), b []byte) (n int, err error) {+ err = c.nudgeDeadline()if err != nil {return n, err}- n, err = c.Conn.Write(b)- cerr := c.Conn.SetWriteDeadline(c.off)- if cerr != nil {+ n, err = f(b)+ cerr := c.nudgeDeadline()+ if err == nil && cerr != nil {err = cerr}return n, err}+// Read bytes doing idle timeouts+func (c *timeoutConn) Read(b []byte) (n int, err error) {+ return c.readOrWrite(c.Conn.Read, b)+}++// Write bytes doing idle timeouts+func (c *timeoutConn) Write(b []byte) (n int, err error) {+ return c.readOrWrite(c.Conn.Write, b)+}+// setDefaults for a from b//// Copy the public members from b to a. We can't just use a struct