MCPcopy Index your code
hub / github.com/moby/moby / clientLoop

Method clientLoop

cmd/docker-proxy/tcp_proxy_linux.go:27–60  ·  view source on GitHub ↗
(client *net.TCPConn, quit chan bool)

Source from the content-addressed store, hash-verified

25}
26
27func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
28 backend, err := net.DialTCP("tcp", nil, proxy.backendAddr)
29 if err != nil {
30 log.Printf("Can't forward traffic to backend tcp/%v: %s\n", proxy.backendAddr, err)
31 client.Close()
32 return
33 }
34
35 var wg sync.WaitGroup
36 broker := func(to, from *net.TCPConn) {
37 io.Copy(to, from)
38 from.CloseRead()
39 to.CloseWrite()
40 wg.Done()
41 }
42
43 wg.Add(2)
44 go broker(client, backend)
45 go broker(backend, client)
46
47 finish := make(chan struct{})
48 go func() {
49 wg.Wait()
50 close(finish)
51 }()
52
53 select {
54 case <-quit:
55 case <-finish:
56 }
57 client.Close()
58 backend.Close()
59 <-finish
60}
61
62// Run starts forwarding the traffic using TCP.
63func (proxy *TCPProxy) Run() {

Callers 1

RunMethod · 0.95

Calls 5

CloseMethod · 0.65
CloseWriteMethod · 0.65
AddMethod · 0.65
WaitMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected