From 53ff4378771d3454b85d01842b38a8ecdbb58c2e Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 5 Sep 2014 10:01:50 +0800 Subject: [PATCH] update ReadBulkTo --- server/util.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/util.go b/server/util.go index 49c20ba..c015b60 100644 --- a/server/util.go +++ b/server/util.go @@ -29,7 +29,9 @@ func ReadLine(rb *bufio.Reader) ([]byte, error) { func ReadBulkTo(rb *bufio.Reader, w io.Writer) error { l, err := ReadLine(rb) - if len(l) == 0 { + if err != nil { + return err + } else if len(l) == 0 { return errBulkFormat } else if l[0] == '$' { var n int @@ -39,8 +41,11 @@ func ReadBulkTo(rb *bufio.Reader, w io.Writer) error { } else if n == -1 { return nil } else { - if _, err = io.CopyN(w, rb, int64(n)); err != nil { + var nn int64 + if nn, err = io.CopyN(w, rb, int64(n)); err != nil { return err + } else if nn != int64(n) { + return io.ErrShortWrite } if l, err = ReadLine(rb); err != nil {