do ReadCodeLine in Close() @ ReadCloser

This commit is contained in:
SunRunAway 2013-07-10 18:18:32 +08:00
parent 60f85a4eb0
commit 65a25a2848
2 changed files with 14 additions and 7 deletions

View File

@ -57,6 +57,13 @@ func TestConn(t *testing.T) {
r.Close()
}
r, err = c.Retr("tset")
if err != nil {
t.Error(err)
} else {
r.Close()
}
err = c.Delete("tset")
if err != nil {
t.Error(err)

14
ftp.go
View File

@ -405,16 +405,16 @@ func (c *ServerConn) Quit() error {
// Read implements the io.Reader interface on a FTP data connection.
func (r *response) Read(buf []byte) (int, error) {
n, err := r.conn.Read(buf)
if err == io.EOF {
_, _, err2 := r.c.conn.ReadCodeLine(StatusClosingDataConnection)
if err2 != nil {
err = err2
}
}
return n, err
}
// Close implements the io.Closer interface on a FTP data connection.
func (r *response) Close() error {
return r.conn.Close()
err := r.conn.Close()
_, _, err2 := r.c.conn.ReadCodeLine(StatusClosingDataConnection)
if err2 != nil {
err = err2
}
return err
}