This commit is contained in:
Matt Joiner 2015-02-21 14:58:28 +11:00
parent c3457b2f54
commit e067bff5b3
1 changed files with 3 additions and 0 deletions

View File

@ -830,6 +830,8 @@ func handshake(sock io.ReadWriteCloser, ih *InfoHash, peerID [20]byte) (res hand
return return
} }
// Wraps a raw connection and provides the interface we want for using the
// connection in the message loop.
type peerConn struct { type peerConn struct {
net.Conn net.Conn
} }
@ -841,6 +843,7 @@ func (pc peerConn) Read(b []byte) (n int, err error) {
err = fmt.Errorf("error setting read deadline: %s", err) err = fmt.Errorf("error setting read deadline: %s", err)
} }
n, err = pc.Conn.Read(b) n, err = pc.Conn.Read(b)
// Convert common errors into io.EOF.
if err != nil { if err != nil {
if opError, ok := err.(*net.OpError); ok && opError.Op == "read" && opError.Err == syscall.ECONNRESET { if opError, ok := err.(*net.OpError); ok && opError.Op == "read" && opError.Err == syscall.ECONNRESET {
err = io.EOF err = io.EOF