Merge pull request #120 from LinboLen/fix_limit_problem

fix: adjust rate limiting to use actual bytes transferred
This commit is contained in:
LinboLen
2025-12-03 04:23:31 +08:00
committed by GitHub
parent 98777eb1b5
commit 33b7faba53

View File

@@ -19,13 +19,19 @@ type Conn struct {
} }
func (c *Conn) Read(b []byte) (n int, err error) { func (c *Conn) Read(b []byte) (n int, err error) {
c.limiter.Wait(int64(len(b))) n, err = c.Conn.Read(b)
return c.Conn.Read(b) if n > 0 {
c.limiter.Wait(int64(n))
}
return n, err
} }
func (c *Conn) Write(b []byte) (n int, err error) { func (c *Conn) Write(b []byte) (n int, err error) {
c.limiter.Wait(int64(len(b))) n, err = c.Conn.Write(b)
return c.Conn.Write(b) if n > 0 {
c.limiter.Wait(int64(n))
}
return n, err
} }
/* /*