Implement reception of Close message

This commit is contained in:
Jakob Borg
2014-07-26 21:27:55 +02:00
parent 5bf7d372f6
commit b7176d2204
4 changed files with 107 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ const (
messageTypePing = 4
messageTypePong = 5
messageTypeIndexUpdate = 6
messageTypeClose = 7
)
const (
@@ -306,6 +307,11 @@ func (c *rawConnection) readerLoop() (err error) {
}
c.state = stateCCRcvd
case messageTypeClose:
if err := c.handleClose(); err != nil {
return err
}
default:
return fmt.Errorf("protocol error: %s: unknown message type %#x", c.id, hdr.msgType)
}
@@ -389,6 +395,15 @@ func (c *rawConnection) handleClusterConfig() error {
return nil
}
func (c *rawConnection) handleClose() error {
var cm CloseMessage
cm.decodeXDR(c.xr)
if err := c.xr.Error(); err != nil {
return err
}
return errors.New(cm.Reason)
}
type encodable interface {
encodeXDR(*xdr.Writer) (int, error)
}