manage normal close in response to close frame

This commit is contained in:
xdrm-brackets 2018-05-08 11:31:37 +02:00
parent ca3b83abee
commit fff5d068d1
2 changed files with 6 additions and 3 deletions

View File

@ -157,7 +157,9 @@ func clientReader(c *client){
msgErr := msg.check(frag != nil)
// fmt.Printf("> %.3f us\n", float64(time.Now().UnixNano()-s0)/1e3)
if msgErr == ErrInvalidPayload {
if msgErr == CloseFrame {
break
} else if msgErr == ErrInvalidPayload {
closeStatus = INVALID_PAYLOAD
break
} else if msgErr != nil {
@ -300,7 +302,7 @@ func (c *client) close(status MessageError, clientACK bool){
/* (4) Send message */
msg.Send(c.io.sock)
// if err != nil {
// fmt.Printf("[close] send error (%s0\n", err)
// fmt.Printf("[close] send error (%s0\n", err)
// }
}

View File

@ -14,6 +14,7 @@ var ErrInvalidSize = fmt.Errorf("Received invalid payload size")
var ErrInvalidPayload = fmt.Errorf("Received invalid utf8 payload")
var ErrInvalidCloseStatus = fmt.Errorf("Received invalid close status")
var ErrInvalidOpCode = fmt.Errorf("Received invalid OpCode")
var CloseFrame = fmt.Errorf("Received close Frame")
// Maximum Header Size = Final/OpCode + isMask/Length + Length + Mask
@ -291,7 +292,7 @@ func (m *Message) check(fragment bool) error{
return ErrInvalidCloseStatus
}
}
return nil
return CloseFrame
case PING:
return nil