]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Treat ECONNRESET and i/o timeout from peers as EOF
authorMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 17:45:38 +0000 (03:45 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 13 Sep 2014 17:45:38 +0000 (03:45 +1000)
client.go

index 50f2136bd26e0df217299d357710771dd534d212..72782463ee948d57367e60f519f62dbd9743d1cb 100644 (file)
--- a/client.go
+++ b/client.go
@@ -492,6 +492,16 @@ func (pc peerConn) Read(b []byte) (n int, err error) {
                return
        }
        n, err = pc.Conn.Read(b)
+       if err != nil {
+               if opError, ok := err.(*net.OpError); ok && opError.Op == "read" && opError.Err == syscall.ECONNRESET {
+                       err = io.EOF
+               } else if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
+                       if n != 0 {
+                               panic(n)
+                       }
+                       err = io.EOF
+               }
+       }
        return
 }