From 7ee9b3c7ee9d21f860f216c10828363fb936fd05 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 24 Apr 2014 21:26:04 -0600 Subject: [PATCH] Remove unnecessary defer --- connection.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/connection.go b/connection.go index 36699844..dab93f66 100644 --- a/connection.go +++ b/connection.go @@ -832,21 +832,19 @@ func (c *Connection) rxMsgHeader() (t byte, bodySize int32, err error) { return } -func (c *Connection) rxMsgBody(bodySize int32) (buf *bytes.Buffer, err error) { +func (c *Connection) rxMsgBody(bodySize int32) (*bytes.Buffer, error) { if !c.alive { - err = errors.New("Connection is dead") - return + return nil, errors.New("Connection is dead") } - defer func() { - if err != nil { - c.die(err) - } - }() + buf := c.getBuf() + _, err := io.CopyN(buf, c.conn, int64(bodySize)) + if err != nil { + c.die(err) + return nil, err + } - buf = c.getBuf() - _, err = io.CopyN(buf, c.conn, int64(bodySize)) - return + return buf, nil } func (c *Connection) rxAuthenticationX(r *MessageReader) (err error) {