It's not used anywhere.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-12-16 13:51:56 -05:00
Родитель 52fd30079a
Коммит 4d8ce0ef4a
2 изменённых файлов: 0 добавлений и 61 удалений

Просмотреть файл

@ -1,28 +0,0 @@
// Package timeoutconn provides overridden net.Conn that supports deadline (timeout).
package timeoutconn
import (
"net"
"time"
)
// New creates a net.Conn with a timeout for every Read operation.
func New(netConn net.Conn, timeout time.Duration) net.Conn {
return &conn{netConn, timeout}
}
// A net.Conn that sets a deadline for every Read operation.
// FIXME was documented the deadline was on Write operation too but not implement
type conn struct {
net.Conn
timeout time.Duration
}
func (c *conn) Read(b []byte) (int, error) {
if c.timeout > 0 {
if err := c.Conn.SetReadDeadline(time.Now().Add(c.timeout)); err != nil {
return 0, err
}
}
return c.Conn.Read(b)
}

Просмотреть файл

@ -1,33 +0,0 @@
package timeoutconn
import (
"bufio"
"fmt"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"
)
func TestRead(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello")
}))
defer ts.Close()
conn, err := net.Dial("tcp", ts.URL[7:])
if err != nil {
t.Fatalf("failed to create connection to %q: %v", ts.URL, err)
}
tconn := New(conn, 1*time.Second)
if _, err = bufio.NewReader(tconn).ReadString('\n'); err == nil {
t.Fatalf("expected timeout error, got none")
}
if _, err := fmt.Fprintf(tconn, "GET / HTTP/1.0\r\n\r\n"); err != nil {
t.Errorf("unexpected error: %v", err)
}
if _, err = bufio.NewReader(tconn).ReadString('\n'); err != nil {
t.Errorf("unexpected error: %v", err)
}
}