From bcbfec6a611f9edc1646dbff1004abe593fe37ea Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Fri, 22 Feb 2013 19:35:10 +0800 Subject: [PATCH] Reuse server buffer in copyServer2Client. --- proxy.go | 15 +++++++-------- script/test.sh | 10 ++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/proxy.go b/proxy.go index 25d3e26..9b232bb 100644 --- a/proxy.go +++ b/proxy.go @@ -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 /* diff --git a/script/test.sh b/script/test.sh index ef76d70..fcb061a 100755 --- a/script/test.sh +++ b/script/test.sh @@ -57,12 +57,14 @@ test_get() { } test_get $PROXY_ADDR/pac "apple.com" "noproxy" # test for pac -test_get google.com "" # 301 redirect -test_get www.google.com "" # 302 redirect , chunked encoding +test_get google.com "" # builtin blocked site, HTTP CONNECT test_get openvpn.net "" # blocked site, all kinds of block method -test_get http://plan9.bell-labs.com/magic/man2html/1/2l "" "" "404" # single LF in response header +test_get plan9.bell-labs.com/magic/man2html/1/2l "" "" "404" # single LF in response header +test_get https://google.com "" # Chinese sites may timeout on travis. if [[ -z $TRAVIS ]]; then