From fff5d068d1ead78cb82a1641f3924024a8e25916 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 8 May 2018 11:31:37 +0200 Subject: [PATCH] manage normal close in response to close frame --- ws/client.go | 6 ++++-- ws/message.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ws/client.go b/ws/client.go index b09dc2c..ff24278 100644 --- a/ws/client.go +++ b/ws/client.go @@ -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) // } } diff --git a/ws/message.go b/ws/message.go index 6cb54f9..26f5404 100644 --- a/ws/message.go +++ b/ws/message.go @@ -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