Move TimeoutConn to seperate pkg dir.
Fixes #10965 Signed-off-by: Rik Nijessen <riknijessen@gmail.com>
This commit is contained in:
parent
309eec2378
commit
690a85797e
3 changed files with 10 additions and 10 deletions
|
@ -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 {
|
|
@ -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")
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue