Reuse server buffer in copyServer2Client.

This commit is contained in:
Chen Yufei
2013-02-22 19:35:10 +08:00
parent fb74efb311
commit bcbfec6a61
2 changed files with 13 additions and 12 deletions

View File

@@ -42,7 +42,11 @@ func freeBuf(b []byte) {
return
}
// Close client connection if no new request received in some time.
// Close client connection if no new request received in some time. Keep it
// small to avoid keeping too many client connections (which associates with
// server connections) and lead to too much open file error. On OS X, the
// default soft limit of open file descriptor is 256, which is really
// conservative.
const clientConnTimeout = 10 * time.Second
const keepAliveHeader = "Keep-Alive: timeout=10\r\n"
@@ -719,13 +723,8 @@ func (sv *serverConn) mayBeClosed() bool {
}
func copyServer2Client(sv *serverConn, c *clientConn, r *Request) (err error) {
// For connect, the data read each time is usually less than 4096. Little
// benefit to increase this to 8192.
buf := getBuf()
defer func() {
freeBuf(buf)
}()
sv.bufRd = nil
sv.bufRd = nil // Use buffer from server connection
buf := sv.buf
var n int
/*

View File

@@ -57,12 +57,14 @@ test_get() {
}
test_get $PROXY_ADDR/pac "apple.com" "noproxy" # test for pac
test_get google.com "</html>" # 301 redirect
test_get www.google.com "</html>" # 302 redirect , chunked encoding
test_get google.com "<html" # 301 redirect
test_get www.google.com "<html" # 302 redirect , chunked encoding
test_get www.reddit.com "<html" # chunked encoding
test_get https://www.twitter.com "</html>" # builtin blocked site, HTTP CONNECT
test_get openvpn.net "</html>" # blocked site, all kinds of block method
test_get http://plan9.bell-labs.com/magic/man2html/1/2l "<head>" "" "404" # single LF in response header
test_get plan9.bell-labs.com/magic/man2html/1/2l "<head>" "" "404" # single LF in response header
test_get https://google.com "<html" # test for HTTP connect
test_get https://www.google.com "<html"
test_get https://www.twitter.com "</html>"
# Chinese sites may timeout on travis.
if [[ -z $TRAVIS ]]; then