2015-05-20 23:48:39 +00:00
|
|
|
package sockets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"net"
|
2015-05-27 22:21:18 +00:00
|
|
|
"net/http"
|
|
|
|
"time"
|
2015-05-20 23:48:39 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/listenbuffer"
|
|
|
|
)
|
|
|
|
|
2015-05-07 16:49:07 +00:00
|
|
|
func NewTcpSocket(addr string, tlsConfig *tls.Config, activate <-chan struct{}) (net.Listener, error) {
|
2015-05-20 23:48:39 +00:00
|
|
|
l, err := listenbuffer.NewListenBuffer("tcp", addr, activate)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-05-07 16:49:07 +00:00
|
|
|
if tlsConfig != nil {
|
|
|
|
tlsConfig.NextProtos = []string{"http/1.1"}
|
|
|
|
l = tls.NewListener(l, tlsConfig)
|
2015-05-20 23:48:39 +00:00
|
|
|
}
|
|
|
|
return l, nil
|
|
|
|
}
|
2015-05-27 22:21:18 +00:00
|
|
|
|
|
|
|
func ConfigureTCPTransport(tr *http.Transport, proto, addr string) {
|
|
|
|
// Why 32? See https://github.com/docker/docker/pull/8035.
|
|
|
|
timeout := 32 * time.Second
|
|
|
|
if proto == "unix" {
|
|
|
|
// No need for compression in local communications.
|
|
|
|
tr.DisableCompression = true
|
|
|
|
tr.Dial = func(_, _ string) (net.Conn, error) {
|
|
|
|
return net.DialTimeout(proto, addr, timeout)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tr.Proxy = http.ProxyFromEnvironment
|
|
|
|
tr.Dial = (&net.Dialer{Timeout: timeout}).Dial
|
|
|
|
}
|
|
|
|
}
|