Skip to content
Snippets Groups Projects
Commit 44b76d10 authored by ale's avatar ale
Browse files

Remove unnecessary loop around io.CopyBuffer

parent 940de449
Branches
No related tags found
No related merge requests found
......@@ -57,13 +57,13 @@ type wrappedWriter interface {
// instrumentation.
func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL, streamName string) {
log.Printf("proxy: in=%s out=%s stream=%s", req.URL.String(), target.String(), streamName)
outreq := new(http.Request)
*outreq = *req // includes shallow copies of maps, but okay
// Make a HTTP/1.0 connection to the backend.
outreq.URL.Scheme = target.Scheme
outreq.URL.Host = target.Host
//outreq.URL.Path = singleJoiningSlash(target.Path, req.URL.Path)
outreq.URL.Path = target.Path
outreq.Proto = "HTTP/1.0"
outreq.ProtoMajor = 1
......@@ -150,7 +150,7 @@ func doIcecastProxy(rw http.ResponseWriter, req *http.Request, target *url.URL,
// Copy data between two network connections. On recent Go versions
// (>1.11), this is quite fast as io.CopyBuffer uses the splice()
// system call internally (in exchange we lose the ability to figure
// out which connection is the source of the error).
// out which end of the connection is the source of the error).
func copyStream(tag string, out, in *net.TCPConn, promCounter prometheus.Counter, cntr *uint64) {
buf := getBuf()
defer releaseBuf(buf)
......@@ -164,22 +164,13 @@ func copyStream(tag string, out, in *net.TCPConn, promCounter prometheus.Counter
defer in.Close() //nolint
defer out.Close() //nolint
for {
n, err := io.CopyBuffer(out, in, buf)
promCounter.Add(float64(n))
if cntr != nil {
atomic.AddUint64(cntr, uint64(n))
}
if err != nil {
if !isCloseError(err) {
log.Printf("http: proxy error (%s): %v", tag, err)
}
return
}
if n == 0 {
log.Printf("http: proxy got 0 bytes from splice()")
return
}
n, err := io.CopyBuffer(out, in, buf)
promCounter.Add(float64(n))
if cntr != nil {
atomic.AddUint64(cntr, uint64(n))
}
if err != nil && !isCloseError(err) {
log.Printf("http: proxy error (%s): %v", tag, err)
}
}
......@@ -216,8 +207,8 @@ func handleProxy(conn *net.TCPConn, upstream *net.TCPConn, streamName string) {
// Implementation of a simple buffer cache, to minimize large
// allocations at runtime.
const (
bufSize = 8192
bufPoolSize = 512
bufSize = 4096
bufPoolSize = 128
)
var bufPool chan []byte
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment