Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
44b76d10
Commit
44b76d10
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Remove unnecessary loop around io.CopyBuffer
parent
940de449
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
node/proxy.go
+11
-20
11 additions, 20 deletions
node/proxy.go
with
11 additions
and
20 deletions
node/proxy.go
+
11
−
20
View file @
44b76d10
...
...
@@ -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
=
5
12
bufSize
=
4096
bufPoolSize
=
12
8
)
var
bufPool
chan
[]
byte
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment