mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #22637 from LK4D4/simplify_tcp_proxy
pkg/proxy: remove unused 'transfered' variable
This commit is contained in:
commit
730b974c64
1 changed files with 15 additions and 18 deletions
|
@ -3,6 +3,7 @@ package proxy
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
|
@ -39,10 +40,9 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
event := make(chan int64)
|
var wg sync.WaitGroup
|
||||||
var broker = func(to, from *net.TCPConn) {
|
var broker = func(to, from *net.TCPConn) {
|
||||||
written, err := io.Copy(to, from)
|
if _, err := io.Copy(to, from); err != nil {
|
||||||
if err != nil {
|
|
||||||
// If the socket we are writing to is shutdown with
|
// If the socket we are writing to is shutdown with
|
||||||
// SHUT_WR, forward it to the other end of the pipe:
|
// SHUT_WR, forward it to the other end of the pipe:
|
||||||
if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
|
if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
|
||||||
|
@ -50,29 +50,26 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
to.CloseRead()
|
to.CloseRead()
|
||||||
event <- written
|
wg.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Add(2)
|
||||||
go broker(client, backend)
|
go broker(client, backend)
|
||||||
go broker(backend, client)
|
go broker(backend, client)
|
||||||
|
|
||||||
var transferred int64
|
finish := make(chan struct{})
|
||||||
for i := 0; i < 2; i++ {
|
go func() {
|
||||||
select {
|
wg.Wait()
|
||||||
case written := <-event:
|
close(finish)
|
||||||
transferred += written
|
}()
|
||||||
case <-quit:
|
|
||||||
// Interrupt the two brokers and "join" them.
|
select {
|
||||||
client.Close()
|
case <-quit:
|
||||||
backend.Close()
|
case <-finish:
|
||||||
for ; i < 2; i++ {
|
|
||||||
transferred += <-event
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
client.Close()
|
client.Close()
|
||||||
backend.Close()
|
backend.Close()
|
||||||
|
<-finish
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts forwarding the traffic using TCP.
|
// Run starts forwarding the traffic using TCP.
|
||||||
|
|
Loading…
Reference in a new issue