github.com/rentongzhang/docker@v1.8.2-rc1/pkg/sockets/tcp_socket.go (about) 1 package sockets 2 3 import ( 4 "crypto/tls" 5 "net" 6 "net/http" 7 "time" 8 9 "github.com/docker/docker/pkg/listenbuffer" 10 ) 11 12 func NewTcpSocket(addr string, tlsConfig *tls.Config, activate <-chan struct{}) (net.Listener, error) { 13 l, err := listenbuffer.NewListenBuffer("tcp", addr, activate) 14 if err != nil { 15 return nil, err 16 } 17 if tlsConfig != nil { 18 tlsConfig.NextProtos = []string{"http/1.1"} 19 l = tls.NewListener(l, tlsConfig) 20 } 21 return l, nil 22 } 23 24 func ConfigureTCPTransport(tr *http.Transport, proto, addr string) { 25 // Why 32? See https://github.com/docker/docker/pull/8035. 26 timeout := 32 * time.Second 27 if proto == "unix" { 28 // No need for compression in local communications. 29 tr.DisableCompression = true 30 tr.Dial = func(_, _ string) (net.Conn, error) { 31 return net.DialTimeout(proto, addr, timeout) 32 } 33 } else { 34 tr.Proxy = http.ProxyFromEnvironment 35 tr.Dial = (&net.Dialer{Timeout: timeout}).Dial 36 } 37 }