Skip to content

Commit

Permalink
Merge pull request #226 from rod-hynes/master
Browse files Browse the repository at this point in the history
Revert da7abf4
  • Loading branch information
rod-hynes committed Aug 8, 2016
2 parents fef1226 + 7189e73 commit 1f426d5
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions psiphon/common/throttled.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ type ThrottledConn struct {
net.Conn
}

const chunkSize = 4096

// NewThrottledConn initializes a new ThrottledConn.
func NewThrottledConn(conn net.Conn, limits RateLimits) *ThrottledConn {

Expand Down Expand Up @@ -119,14 +117,7 @@ func (conn *ThrottledConn) Read(buffer []byte) (int, error) {
}
}

// When throttling, read small chunks to avoid
// excessive latency due to long waits in limitedReader.Read.

if len(buffer) <= chunkSize {
return conn.limitedReader.Read(buffer)
}

return conn.limitedReader.Read(buffer[0:chunkSize])
return conn.limitedReader.Read(buffer)
}

func (conn *ThrottledConn) Write(buffer []byte) (int, error) {
Expand All @@ -140,24 +131,5 @@ func (conn *ThrottledConn) Write(buffer []byte) (int, error) {
}
}

// When throttling, write buffer in small chunks to avoid
// excessive latency due to long waits in limitedWriter.Write.

bytesWritten := 0

for start := 0; start < len(buffer); start += chunkSize {
end := start + chunkSize
if end > len(buffer) {
end = len(buffer)
}

n, err := conn.limitedWriter.Write(buffer[start:end])
bytesWritten += n
if err != nil {
// Note: no ContextError as caller may check for io.EOF, etc.
return bytesWritten, err
}
}

return bytesWritten, nil
return conn.limitedWriter.Write(buffer)
}

0 comments on commit 1f426d5

Please sign in to comment.