From 690a85797e70c3816a1dec768bff0c454e1e23a9 Mon Sep 17 00:00:00 2001 From: Rik Nijessen Date: Wed, 25 Feb 2015 16:59:29 +0100 Subject: [PATCH] Move TimeoutConn to seperate pkg dir. Fixes #10965 Signed-off-by: Rik Nijessen --- utils/timeoutconn.go => pkg/timeout/timeout.go | 10 +++++----- .../timeoutconn_test.go => pkg/timeout/timeout_test.go | 6 +++--- registry/registry.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) rename utils/timeoutconn.go => pkg/timeout/timeout.go (58%) rename utils/timeoutconn_test.go => pkg/timeout/timeout_test.go (87%) diff --git a/utils/timeoutconn.go b/pkg/timeout/timeout.go similarity index 58% rename from utils/timeoutconn.go rename to pkg/timeout/timeout.go index a3231c7ee3..be85ebdac8 100644 --- a/utils/timeoutconn.go +++ b/pkg/timeout/timeout.go @@ -1,21 +1,21 @@ -package utils +package timeout import ( "net" "time" ) -func NewTimeoutConn(conn net.Conn, timeout time.Duration) net.Conn { - return &TimeoutConn{conn, timeout} +func New(netConn net.Conn, timeout time.Duration) net.Conn { + return &conn{netConn, timeout} } // A net.Conn that sets a deadline for every Read or Write operation -type TimeoutConn struct { +type conn struct { net.Conn timeout time.Duration } -func (c *TimeoutConn) Read(b []byte) (int, error) { +func (c *conn) Read(b []byte) (int, error) { if c.timeout > 0 { err := c.Conn.SetReadDeadline(time.Now().Add(c.timeout)) if err != nil { diff --git a/utils/timeoutconn_test.go b/pkg/timeout/timeout_test.go similarity index 87% rename from utils/timeoutconn_test.go rename to pkg/timeout/timeout_test.go index d07b96cc06..f2bebae558 100644 --- a/utils/timeoutconn_test.go +++ b/pkg/timeout/timeout_test.go @@ -1,4 +1,4 @@ -package utils +package timeout import ( "bufio" @@ -10,7 +10,7 @@ import ( "time" ) -func TestTimeoutConnRead(t *testing.T) { +func TestRead(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "hello") })) @@ -19,7 +19,7 @@ func TestTimeoutConnRead(t *testing.T) { if err != nil { t.Fatalf("failed to create connection to %q: %v", ts.URL, err) } - tconn := NewTimeoutConn(conn, 1*time.Second) + tconn := New(conn, 1*time.Second) if _, err = bufio.NewReader(tconn).ReadString('\n'); err == nil { t.Fatalf("expected timeout error, got none") diff --git a/registry/registry.go b/registry/registry.go index 77a78a8203..ed57ed1a4b 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -14,7 +14,7 @@ import ( "time" log "github.com/Sirupsen/logrus" - "github.com/docker/docker/utils" + "github.com/docker/docker/pkg/timeout" ) var ( @@ -71,7 +71,7 @@ func newClient(jar http.CookieJar, roots *x509.CertPool, certs []tls.Certificate if err != nil { return nil, err } - conn = utils.NewTimeoutConn(conn, 1*time.Minute) + conn = timeout.New(conn, 1*time.Minute) return conn, nil } }